From cf0348953beed229a880f14a4f8400bbc2d878e8 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 11:18:52 +0800 Subject: [PATCH 1/6] chore: migrate to newer intents --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 5a657e6..274a0d3 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ const client = new Client({ GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildMessageReactions, - GatewayIntentBits.GuildBans, + GatewayIntentBits.GuildModeration, ], partials: [Partials.Channel], }); From ff664c5f04be9d81e9245b4a174f27050976c024 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 11:18:58 +0800 Subject: [PATCH 2/6] chore: remove unused constant --- src/constants.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index 3a88957..20c3586 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -24,6 +24,3 @@ export const COLORS = { yellow: 0xfde047, orange: 0xfb923c, } as { [key: string]: number }; - -/* CHANGEME */ -export const ALLOWED_ROLES = ['Alert', 'Events', 'Progress']; From a4d326bb2634d8567564081982bd807204de6fee Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 11:20:09 +0800 Subject: [PATCH 3/6] chore: remove stale button handler --- src/index.ts | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/index.ts b/src/index.ts index 274a0d3..2656746 100644 --- a/src/index.ts +++ b/src/index.ts @@ -98,22 +98,6 @@ client.once('ready', async () => { }); client.on('interactionCreate', async (interaction) => { - if (interaction.isButton() && interaction.customId === 'delete-message') { - const messageRef = interaction.message.reference?.messageId; - if (messageRef) { - const msg = await interaction.message.channel.messages.fetch(messageRef); - - if (interaction?.user === msg.author) { - await interaction.message.delete(); - } else { - await interaction.reply({ - content: 'You can only delete your own messages!', - ephemeral: true, - }); - } - } - } - if (interaction.isChatInputCommand()) { const { commandName } = interaction; From 8117ed29ec6f3a84d01f38200f9657d5b0574034 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 11:21:54 +0800 Subject: [PATCH 4/6] chore: move to PermissionFlagsBits --- src/index.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 2656746..88aec77 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,7 @@ import { Partials, OAuth2Scopes, InteractionType, + PermissionFlagsBits, } from 'discord.js'; import { reuploadCommands } from './_reupload'; @@ -45,21 +46,21 @@ client.once('ready', async () => { client.generateInvite({ scopes: [OAuth2Scopes.Bot], permissions: [ - 'AddReactions', - 'ViewChannel', - 'BanMembers', - 'KickMembers', - 'CreatePublicThreads', - 'CreatePrivateThreads', - 'EmbedLinks', - 'ManageChannels', - 'ManageRoles', - 'ModerateMembers', - 'MentionEveryone', - 'MuteMembers', - 'SendMessages', - 'SendMessagesInThreads', - 'ReadMessageHistory', + PermissionFlagsBits.AddReactions, + PermissionFlagsBits.ViewChannel, + PermissionFlagsBits.BanMembers, + PermissionFlagsBits.KickMembers, + PermissionFlagsBits.CreatePublicThreads, + PermissionFlagsBits.CreatePrivateThreads, + PermissionFlagsBits.EmbedLinks, + PermissionFlagsBits.ManageChannels, + PermissionFlagsBits.ManageRoles, + PermissionFlagsBits.ModerateMembers, + PermissionFlagsBits.MentionEveryone, + PermissionFlagsBits.MuteMembers, + PermissionFlagsBits.SendMessages, + PermissionFlagsBits.SendMessagesInThreads, + PermissionFlagsBits.ReadMessageHistory, ], }) ) From b11b564e2da1e33865691f5e5fae5cf00240dbf9 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 11:25:06 +0800 Subject: [PATCH 5/6] feat: add logging for say command (closes #166) --- .env.example | 4 +++- src/commands/say.ts | 37 +++++++++++++++++++++++++++++++++++++ src/index.ts | 7 ++----- 3 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 src/commands/say.ts diff --git a/.env.example b/.env.example index a010304..27aec5b 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1,4 @@ DISCORD_TOKEN= -DISCORD_APP= \ No newline at end of file +DISCORD_APP= + +SAY_LOGS_CHANNEL= diff --git a/src/commands/say.ts b/src/commands/say.ts new file mode 100644 index 0000000..96e0979 --- /dev/null +++ b/src/commands/say.ts @@ -0,0 +1,37 @@ +import { + CacheType, + ChatInputCommandInteraction, + EmbedBuilder, +} from 'discord.js'; + +export const sayCommand = async ( + interaction: ChatInputCommandInteraction +) => { + if (!interaction.guild || !interaction.channel) return; + + const content = interaction.options.getString('content', true); + await interaction.deferReply({ ephemeral: true }); + const message = await interaction.channel.send(content); + await interaction.editReply('I said what you said!'); + + if (typeof process.env.SAY_LOGS_CHANNEL === 'string') { + const logsChannel = await interaction.guild.channels.fetch( + process.env.SAY_LOGS_CHANNEL + ); + + if (!logsChannel?.isTextBased()) return; + + await logsChannel.send({ + embeds: [ + new EmbedBuilder() + .setTitle('Say command used') + .setDescription(content) + .setAuthor({ + name: interaction.user.tag, + iconURL: interaction.user.avatarURL() ?? undefined, + }) + .setURL(message.url), + ], + }); + } +}; diff --git a/src/index.ts b/src/index.ts index 88aec77..11001ba 100644 --- a/src/index.ts +++ b/src/index.ts @@ -19,6 +19,7 @@ import { modrinthCommand } from './commands/modrinth'; import { tagsCommand } from './commands/tags'; import { jokeCommand } from './commands/joke'; import { roryCommand } from './commands/rory'; +import { sayCommand } from './commands/say'; import random from 'just-random'; import { green, bold, yellow, cyan } from 'kleur/colors'; @@ -114,11 +115,7 @@ client.on('interactionCreate', async (interaction) => { } else if (commandName === 'modrinth') { await modrinthCommand(interaction); } else if (commandName === 'say') { - if (!interaction.channel) return; - - await interaction.deferReply({ ephemeral: true }); - await interaction.channel.send(interaction.options.getString('content')!); - await interaction.editReply('I said what you said!'); + await sayCommand(interaction); } else if (commandName === 'tag') { await tagsCommand(interaction); } else if (commandName === 'joke') { From e1f8443eba6b74853e51093b57aea07df7520f77 Mon Sep 17 00:00:00 2001 From: Ryan Cao <70191398+ryanccn@users.noreply.github.com> Date: Wed, 24 May 2023 17:17:15 +0800 Subject: [PATCH 6/6] fix: check for empty strings Co-authored-by: Sefa Eyeoglu Signed-off-by: Ryan Cao <70191398+ryanccn@users.noreply.github.com> --- src/commands/say.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/say.ts b/src/commands/say.ts index 96e0979..fd3af32 100644 --- a/src/commands/say.ts +++ b/src/commands/say.ts @@ -14,7 +14,7 @@ export const sayCommand = async ( const message = await interaction.channel.send(content); await interaction.editReply('I said what you said!'); - if (typeof process.env.SAY_LOGS_CHANNEL === 'string') { + if (process.env.SAY_LOGS_CHANNEL) { const logsChannel = await interaction.guild.channels.fetch( process.env.SAY_LOGS_CHANNEL );