-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds message context menu commands for verification and unverification
- Loading branch information
1 parent
bee1bc7
commit cf9534a
Showing
13 changed files
with
425 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import type { | ||
Guild, | ||
Message, | ||
MessageReaction, | ||
Role, | ||
MessageContextMenuCommandInteraction, | ||
GuildMember, | ||
} from "discord.js"; | ||
import type Command from "../commands.js"; | ||
import type {ApplicationCommand, ApplicationCommandData, ApplicationUserInteraction} from "../commands.js"; | ||
import type {Unverification as UnverificationCompilation} from "../compilations.js"; | ||
import type {Unverification as UnverificationDefinition} from "../definitions.js"; | ||
import type {Unverification as UnverificationDependency} from "../dependencies.js"; | ||
import type {Locale, Localized} from "../utils/string.js"; | ||
import { | ||
ApplicationCommandType, | ||
} from "discord.js"; | ||
import {unverification as unverificationCompilation} from "../compilations.js"; | ||
import {unverification as unverificationDefinition} from "../definitions.js"; | ||
import {composeAll, localize, resolve} from "../utils/string.js"; | ||
type HelpGroups = UnverificationDependency["help"]; | ||
const { | ||
commandName, | ||
commandDescription, | ||
}: UnverificationDefinition = unverificationDefinition; | ||
const { | ||
help: helpLocalizations, | ||
reply: replyLocalizations, | ||
noMemberReply: noMemberReplyLocalizations, | ||
noPermissionReply: noPermissionReplyLocalizations, | ||
}: UnverificationCompilation = unverificationCompilation; | ||
const { | ||
SHICKA_APPROVAL_VERIFICATION_ROLE, | ||
SHICKA_REFUSAL_UNVERIFICATION_ROLE, | ||
}: NodeJS.ProcessEnv = process.env; | ||
const commandUnverificationRole: string = SHICKA_REFUSAL_UNVERIFICATION_ROLE ?? ""; | ||
const commandVerificationRole: string = SHICKA_APPROVAL_VERIFICATION_ROLE ?? ""; | ||
const unverificationCommand: Command = { | ||
register(): ApplicationCommandData { | ||
return { | ||
type: ApplicationCommandType.Message, | ||
name: commandName, | ||
nameLocalizations: commandDescription, | ||
defaultMemberPermissions: [], | ||
dmPermission: false, | ||
}; | ||
}, | ||
async interact(interaction: ApplicationUserInteraction): Promise<void> { | ||
if (!interaction.isMessageContextMenuCommand()) { | ||
return; | ||
} | ||
const {guild, locale, targetMessage}: MessageContextMenuCommandInteraction<"cached"> = interaction; | ||
const resolvedLocale: Locale = resolve(locale); | ||
const {roles}: Guild = guild; | ||
const unverificationRole: Role | undefined = roles.cache.find((role: Role): boolean => { | ||
return role.name === commandUnverificationRole; | ||
}); | ||
if (unverificationRole == null) { | ||
return; | ||
} | ||
const verificationRole: Role | undefined = roles.cache.find((role: Role): boolean => { | ||
return role.name === commandVerificationRole; | ||
}); | ||
if (verificationRole == null) { | ||
return; | ||
} | ||
const member: GuildMember | undefined = await (async (): Promise<GuildMember | undefined> => { | ||
try { | ||
const {author, member}: Message<true> = targetMessage; | ||
if (member == null) { | ||
const memberId: string = author.id; | ||
const member: GuildMember | undefined = guild.members.cache.get(memberId); | ||
if (member == null) { | ||
return await guild.members.fetch(memberId); | ||
} | ||
return member; | ||
} | ||
return member; | ||
} catch {} | ||
})(); | ||
if (member == null) { | ||
await interaction.reply({ | ||
content: noMemberReplyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
try { | ||
await member.roles.remove(verificationRole); | ||
await member.roles.remove(unverificationRole); | ||
} catch { | ||
await interaction.reply({ | ||
content: noPermissionReplyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
await targetMessage.react("❎"); | ||
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => { | ||
return (reaction.emoji.name ?? "") === "✅"; | ||
}); | ||
if (reaction != null) { | ||
await reaction.users.remove(); | ||
} | ||
await interaction.reply({ | ||
content: replyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
}, | ||
describe(applicationCommand: ApplicationCommand): Localized<(groups: {}) => string> { | ||
return composeAll<HelpGroups, {}>(helpLocalizations, localize<HelpGroups>((locale: Locale): HelpGroups => { | ||
return { | ||
commandMention: (): string => { | ||
return commandDescription[locale]; | ||
}, | ||
}; | ||
})); | ||
}, | ||
}; | ||
export default unverificationCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import type { | ||
Guild, | ||
Message, | ||
MessageReaction, | ||
Role, | ||
MessageContextMenuCommandInteraction, | ||
GuildMember, | ||
} from "discord.js"; | ||
import type Command from "../commands.js"; | ||
import type {ApplicationCommand, ApplicationCommandData, ApplicationUserInteraction} from "../commands.js"; | ||
import type {Verification as VerificationCompilation} from "../compilations.js"; | ||
import type {Verification as VerificationDefinition} from "../definitions.js"; | ||
import type {Verification as VerificationDependency} from "../dependencies.js"; | ||
import type {Locale, Localized} from "../utils/string.js"; | ||
import { | ||
ApplicationCommandType, | ||
} from "discord.js"; | ||
import {verification as verificationCompilation} from "../compilations.js"; | ||
import {verification as verificationDefinition} from "../definitions.js"; | ||
import {composeAll, localize, resolve} from "../utils/string.js"; | ||
type HelpGroups = VerificationDependency["help"]; | ||
const { | ||
commandName, | ||
commandDescription, | ||
}: VerificationDefinition = verificationDefinition; | ||
const { | ||
help: helpLocalizations, | ||
reply: replyLocalizations, | ||
noMemberReply: noMemberReplyLocalizations, | ||
noPermissionReply: noPermissionReplyLocalizations, | ||
}: VerificationCompilation = verificationCompilation; | ||
const { | ||
SHICKA_APPROVAL_VERIFICATION_ROLE, | ||
SHICKA_REFUSAL_UNVERIFICATION_ROLE, | ||
}: NodeJS.ProcessEnv = process.env; | ||
const commandUnverificationRole: string = SHICKA_REFUSAL_UNVERIFICATION_ROLE ?? ""; | ||
const commandVerificationRole: string = SHICKA_APPROVAL_VERIFICATION_ROLE ?? ""; | ||
const verificationCommand: Command = { | ||
register(): ApplicationCommandData { | ||
return { | ||
type: ApplicationCommandType.Message, | ||
name: commandName, | ||
nameLocalizations: commandDescription, | ||
defaultMemberPermissions: [], | ||
dmPermission: false, | ||
}; | ||
}, | ||
async interact(interaction: ApplicationUserInteraction): Promise<void> { | ||
if (!interaction.isMessageContextMenuCommand()) { | ||
return; | ||
} | ||
const {guild, locale, targetMessage}: MessageContextMenuCommandInteraction<"cached"> = interaction; | ||
const resolvedLocale: Locale = resolve(locale); | ||
const {roles}: Guild = guild; | ||
const unverificationRole: Role | undefined = roles.cache.find((role: Role): boolean => { | ||
return role.name === commandUnverificationRole; | ||
}); | ||
if (unverificationRole == null) { | ||
return; | ||
} | ||
const verificationRole: Role | undefined = roles.cache.find((role: Role): boolean => { | ||
return role.name === commandVerificationRole; | ||
}); | ||
if (verificationRole == null) { | ||
return; | ||
} | ||
const member: GuildMember | undefined = await (async (): Promise<GuildMember | undefined> => { | ||
try { | ||
const {author, member}: Message<true> = targetMessage; | ||
if (member == null) { | ||
const memberId: string = author.id; | ||
const member: GuildMember | undefined = guild.members.cache.get(memberId); | ||
if (member == null) { | ||
return await guild.members.fetch(memberId); | ||
} | ||
return member; | ||
} | ||
return member; | ||
} catch {} | ||
})(); | ||
if (member == null) { | ||
await interaction.reply({ | ||
content: noMemberReplyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
try { | ||
await member.roles.add(verificationRole); | ||
await member.roles.remove(unverificationRole); | ||
} catch { | ||
await interaction.reply({ | ||
content: noPermissionReplyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
await targetMessage.react("✅"); | ||
const reaction: MessageReaction | undefined = targetMessage.reactions.cache.find((reaction: MessageReaction): boolean => { | ||
return (reaction.emoji.name ?? "") === "❎"; | ||
}); | ||
if (reaction != null) { | ||
await reaction.users.remove(); | ||
} | ||
await interaction.reply({ | ||
content: replyLocalizations[resolvedLocale]({}), | ||
ephemeral: true, | ||
}); | ||
}, | ||
describe(applicationCommand: ApplicationCommand): Localized<(groups: {}) => string> { | ||
return composeAll<HelpGroups, {}>(helpLocalizations, localize<HelpGroups>((locale: Locale): HelpGroups => { | ||
return { | ||
commandMention: (): string => { | ||
return commandDescription[locale]; | ||
}, | ||
}; | ||
})); | ||
}, | ||
}; | ||
export default verificationCommand; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type {Unverification} from "../dependencies.js"; | ||
import type {Localized} from "../utils/string.js"; | ||
import {unverification} from "../definitions.js"; | ||
import {compileAll} from "../utils/string.js"; | ||
type HelpLocalizations = Localized<(groups: Unverification["help"]) => string>; | ||
type ReplyLocalizations = Localized<(groups: Unverification["reply"]) => string>; | ||
type NoMemberReplyLocalizations = Localized<(groups: Unverification["noMemberReply"]) => string>; | ||
type NoPermissionReplyLocalizations = Localized<(groups: Unverification["noPermissionReply"]) => string>; | ||
type UnverificationCompilation = { | ||
help: HelpLocalizations, | ||
reply: ReplyLocalizations, | ||
noMemberReply: NoMemberReplyLocalizations, | ||
noPermissionReply: NoPermissionReplyLocalizations, | ||
}; | ||
const helpLocalizations: HelpLocalizations = compileAll<Unverification["help"]>(unverification["help"]); | ||
const replyLocalizations: ReplyLocalizations = compileAll<Unverification["reply"]>(unverification["reply"]); | ||
const noMemberReplyLocalizations: NoMemberReplyLocalizations = compileAll<Unverification["noMemberReply"]>(unverification["noMemberReply"]); | ||
const noPermissionReplyLocalizations: NoPermissionReplyLocalizations = compileAll<Unverification["noPermissionReply"]>(unverification["noPermissionReply"]); | ||
const unverificationCompilation: UnverificationCompilation = { | ||
help: helpLocalizations, | ||
reply: replyLocalizations, | ||
noMemberReply: noMemberReplyLocalizations, | ||
noPermissionReply: noPermissionReplyLocalizations, | ||
}; | ||
export default unverificationCompilation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import type {Verification} from "../dependencies.js"; | ||
import type {Localized} from "../utils/string.js"; | ||
import {verification} from "../definitions.js"; | ||
import {compileAll} from "../utils/string.js"; | ||
type HelpLocalizations = Localized<(groups: Verification["help"]) => string>; | ||
type ReplyLocalizations = Localized<(groups: Verification["reply"]) => string>; | ||
type NoMemberReplyLocalizations = Localized<(groups: Verification["noMemberReply"]) => string>; | ||
type NoPermissionReplyLocalizations = Localized<(groups: Verification["noPermissionReply"]) => string>; | ||
type VerificationCompilation = { | ||
help: HelpLocalizations, | ||
reply: ReplyLocalizations, | ||
noMemberReply: NoMemberReplyLocalizations, | ||
noPermissionReply: NoPermissionReplyLocalizations, | ||
}; | ||
const helpLocalizations: HelpLocalizations = compileAll<Verification["help"]>(verification["help"]); | ||
const replyLocalizations: ReplyLocalizations = compileAll<Verification["reply"]>(verification["reply"]); | ||
const noMemberReplyLocalizations: NoMemberReplyLocalizations = compileAll<Verification["noMemberReply"]>(verification["noMemberReply"]); | ||
const noPermissionReplyLocalizations: NoPermissionReplyLocalizations = compileAll<Verification["noPermissionReply"]>(verification["noPermissionReply"]); | ||
const verificationCompilation: VerificationCompilation = { | ||
help: helpLocalizations, | ||
reply: replyLocalizations, | ||
noMemberReply: noMemberReplyLocalizations, | ||
noPermissionReply: noPermissionReplyLocalizations, | ||
}; | ||
export default verificationCompilation; |
Oops, something went wrong.