2021-06-30 04:56:56 +02:00
|
|
|
import { MessageMentionOptions, MessageMentionTypes, Snowflake } from "discord.js";
|
2021-06-01 02:05:55 +02:00
|
|
|
|
|
|
|
export function erisAllowedMentionsToDjsMentionOptions(
|
2021-06-02 19:35:44 +02:00
|
|
|
allowedMentions: ErisAllowedMentionFormat | undefined,
|
2021-06-01 02:05:55 +02:00
|
|
|
): MessageMentionOptions | undefined {
|
|
|
|
if (allowedMentions === undefined) return undefined;
|
|
|
|
|
2021-06-02 19:35:44 +02:00
|
|
|
const parse: MessageMentionTypes[] = [];
|
2021-06-30 04:56:56 +02:00
|
|
|
let users: Snowflake[] | undefined;
|
|
|
|
let roles: Snowflake[] | undefined;
|
2021-06-01 02:05:55 +02:00
|
|
|
|
|
|
|
if (Array.isArray(allowedMentions.users)) {
|
2021-06-30 04:56:56 +02:00
|
|
|
users = allowedMentions.users as Snowflake[];
|
2021-06-01 02:05:55 +02:00
|
|
|
} else if (allowedMentions.users === true) {
|
|
|
|
parse.push("users");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(allowedMentions.roles)) {
|
2021-06-30 04:56:56 +02:00
|
|
|
roles = allowedMentions.roles as Snowflake[];
|
2021-06-01 02:05:55 +02:00
|
|
|
} else if (allowedMentions.roles === true) {
|
|
|
|
parse.push("roles");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowedMentions.everyone === true) {
|
|
|
|
parse.push("everyone");
|
|
|
|
}
|
|
|
|
|
|
|
|
const mentions: MessageMentionOptions = {
|
|
|
|
parse,
|
|
|
|
users,
|
|
|
|
roles,
|
|
|
|
repliedUser: allowedMentions.repliedUser,
|
|
|
|
};
|
|
|
|
|
|
|
|
return mentions;
|
|
|
|
}
|
|
|
|
|
2021-06-02 19:35:44 +02:00
|
|
|
export interface ErisAllowedMentionFormat {
|
2021-06-02 04:07:50 +02:00
|
|
|
everyone?: boolean | undefined;
|
|
|
|
users?: boolean | string[] | undefined;
|
|
|
|
roles?: boolean | string[] | undefined;
|
|
|
|
repliedUser?: boolean | undefined;
|
2021-06-01 02:05:55 +02:00
|
|
|
}
|