diff --git a/deps.ts b/deps.ts index e16166a..72e8443 100644 --- a/deps.ts +++ b/deps.ts @@ -1 +1,2 @@ export * from "https://deno.land/x/discordeno@11.2.0/mod.ts"; +export { ms } from "https://deno.land/x/ms@v0.1.0/ms.ts"; diff --git a/src/rest/commands/moderation/mute.ts b/src/rest/commands/moderation/mute.ts new file mode 100644 index 0000000..ecc895d --- /dev/null +++ b/src/rest/commands/moderation/mute.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const MuteCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +MuteCommand.options = { + name: "mute", + description: enTranslate("commands/moderation/mute:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(MuteCommand); diff --git a/src/rest/commands/moderation/slowmode.ts b/src/rest/commands/moderation/slowmode.ts new file mode 100644 index 0000000..62c048c --- /dev/null +++ b/src/rest/commands/moderation/slowmode.ts @@ -0,0 +1,102 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate, translate } from "../../common/util/i18next.ts"; +import { + DiscordApplicationCommandOptionTypes, + editChannel, + ms, + snowflakeToBigint, + validatePermissions, +} from "../../../../deps.ts"; + +const SlowmodeCommand: Command = async (interaction) => { + const guildId: bigint = snowflakeToBigint(interaction.guildId!); + + if ( + !validatePermissions(snowflakeToBigint(interaction.member!.permissions), [ + "MANAGE_CHANNELS", + ]) + ) { + return basicInteractionResponse( + interaction.id, + interaction.token, + translate( + guildId, + "permission:USER_MISSING_PERMISSION", + { permission: "Manage Channels" }, + ), + ); + } + + const raw = interaction.data?.options?.[0]; + + if (!raw) { + return basicInteractionResponse( + interaction.id, + interaction.token, + translate(guildId, "commands/moderation/slowmode:MISSING_ARGUMENT"), + ); + } + + if (raw.type === DiscordApplicationCommandOptionTypes.String && raw.value) { + // If using ms, convert to seconds by dividing by 1000 + const time = /[A-Za-z]?$/.test(raw.value) + ? (ms(raw.value) as number) / 1000 + : +raw.value; + + if (!isFinite(time) || time > 21600) { + return basicInteractionResponse( + interaction.id, + interaction.token, + translate( + guildId, + "commands/moderation/slowmode:ERROR", + ), + ); + } + + try { + await editChannel(snowflakeToBigint(interaction.channelId!), { + rateLimitPerUser: time, + }); + } catch { + return basicInteractionResponse( + interaction.id, + interaction.token, + translate( + guildId, + "permission:SELF_MISSING_PERMISSION", + { permission: "Manage Channels" }, + ), + ); + } + + return basicInteractionResponse( + interaction.id, + interaction.token, + translate( + guildId, + "commands/moderation/slowmode:SLOWMODE_UPDATED", + ), + ); + } +}; + +SlowmodeCommand.options = { + name: "slowmode", + description: enTranslate("commands/moderation/slowmode:COMMAND_DESCRIPTION"), + options: [ + { + required: false, + name: "time", + description: enTranslate( + "commands/moderation/slowmode:SUBCOMMAND_DESCRIPTION_TIME", + ), + type: DiscordApplicationCommandOptionTypes.String, + }, + ], +}; + +bot.commands.add(SlowmodeCommand); diff --git a/src/rest/commands/moderation/softban.ts b/src/rest/commands/moderation/softban.ts new file mode 100644 index 0000000..f71091d --- /dev/null +++ b/src/rest/commands/moderation/softban.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const SoftbanCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +SoftbanCommand.options = { + name: "softban", + description: enTranslate("commands/moderation/softban:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(SoftbanCommand); diff --git a/src/rest/commands/moderation/unban.ts b/src/rest/commands/moderation/unban.ts new file mode 100644 index 0000000..b389256 --- /dev/null +++ b/src/rest/commands/moderation/unban.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const UnbanCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +UnbanCommand.options = { + name: "unban", + description: enTranslate("commands/moderation/unban:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(UnbanCommand); diff --git a/src/rest/commands/moderation/unmute.ts b/src/rest/commands/moderation/unmute.ts new file mode 100644 index 0000000..1a05710 --- /dev/null +++ b/src/rest/commands/moderation/unmute.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const UnmuteCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +UnmuteCommand.options = { + name: "unmute", + description: enTranslate("commands/moderation/unmute:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(UnmuteCommand); diff --git a/src/rest/commands/moderation/voicekick.ts b/src/rest/commands/moderation/voicekick.ts new file mode 100644 index 0000000..f14ce9c --- /dev/null +++ b/src/rest/commands/moderation/voicekick.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const VoiceKickCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +VoiceKickCommand.options = { + name: "voicekick", + description: enTranslate("commands/moderation/voicekick:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(VoiceKickCommand); diff --git a/src/rest/commands/moderation/warn.ts b/src/rest/commands/moderation/warn.ts new file mode 100644 index 0000000..1db4612 --- /dev/null +++ b/src/rest/commands/moderation/warn.ts @@ -0,0 +1,20 @@ +import Command, { + basicInteractionResponse, +} from "../../common/command/Command.ts"; +import { bot } from "../../cache.ts"; +import { enTranslate } from "../../common/util/i18next.ts"; + +const WarnCommand: Command = (interaction) => { + return basicInteractionResponse( + interaction.id, + interaction.token, + "Command not implemented yet.", + ); +}; + +WarnCommand.options = { + name: "warn", + description: enTranslate("commands/moderation/warn:COMMAND_DESCRIPTION"), +}; + +bot.commands.add(WarnCommand);