Merge pull request #167 from ryanccn/minor-cleanup

minor cleanup and fixes
This commit is contained in:
Sefa Eyeoglu 2023-05-29 17:07:13 +02:00 committed by GitHub
commit 005b1c8c30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 41 deletions

View file

@ -1,2 +1,4 @@
DISCORD_TOKEN= DISCORD_TOKEN=
DISCORD_APP= DISCORD_APP=
SAY_LOGS_CHANNEL=

37
src/commands/say.ts Normal file
View file

@ -0,0 +1,37 @@
import {
CacheType,
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
export const sayCommand = async (
interaction: ChatInputCommandInteraction<CacheType>
) => {
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 (process.env.SAY_LOGS_CHANNEL) {
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),
],
});
}
};

View file

@ -24,6 +24,3 @@ export const COLORS = {
yellow: 0xfde047, yellow: 0xfde047,
orange: 0xfb923c, orange: 0xfb923c,
} as { [key: string]: number }; } as { [key: string]: number };
/* CHANGEME */
export const ALLOWED_ROLES = ['Alert', 'Events', 'Progress'];

View file

@ -4,6 +4,7 @@ import {
Partials, Partials,
OAuth2Scopes, OAuth2Scopes,
InteractionType, InteractionType,
PermissionFlagsBits,
} from 'discord.js'; } from 'discord.js';
import { reuploadCommands } from './_reupload'; import { reuploadCommands } from './_reupload';
@ -18,6 +19,7 @@ import { modrinthCommand } from './commands/modrinth';
import { tagsCommand } from './commands/tags'; import { tagsCommand } from './commands/tags';
import { jokeCommand } from './commands/joke'; import { jokeCommand } from './commands/joke';
import { roryCommand } from './commands/rory'; import { roryCommand } from './commands/rory';
import { sayCommand } from './commands/say';
import random from 'just-random'; import random from 'just-random';
import { green, bold, yellow, cyan } from 'kleur/colors'; import { green, bold, yellow, cyan } from 'kleur/colors';
@ -32,7 +34,7 @@ const client = new Client({
GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences, GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildBans, GatewayIntentBits.GuildModeration,
], ],
partials: [Partials.Channel], partials: [Partials.Channel],
}); });
@ -45,21 +47,21 @@ client.once('ready', async () => {
client.generateInvite({ client.generateInvite({
scopes: [OAuth2Scopes.Bot], scopes: [OAuth2Scopes.Bot],
permissions: [ permissions: [
'AddReactions', PermissionFlagsBits.AddReactions,
'ViewChannel', PermissionFlagsBits.ViewChannel,
'BanMembers', PermissionFlagsBits.BanMembers,
'KickMembers', PermissionFlagsBits.KickMembers,
'CreatePublicThreads', PermissionFlagsBits.CreatePublicThreads,
'CreatePrivateThreads', PermissionFlagsBits.CreatePrivateThreads,
'EmbedLinks', PermissionFlagsBits.EmbedLinks,
'ManageChannels', PermissionFlagsBits.ManageChannels,
'ManageRoles', PermissionFlagsBits.ManageRoles,
'ModerateMembers', PermissionFlagsBits.ModerateMembers,
'MentionEveryone', PermissionFlagsBits.MentionEveryone,
'MuteMembers', PermissionFlagsBits.MuteMembers,
'SendMessages', PermissionFlagsBits.SendMessages,
'SendMessagesInThreads', PermissionFlagsBits.SendMessagesInThreads,
'ReadMessageHistory', PermissionFlagsBits.ReadMessageHistory,
], ],
}) })
) )
@ -98,22 +100,6 @@ client.once('ready', async () => {
}); });
client.on('interactionCreate', async (interaction) => { 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()) { if (interaction.isChatInputCommand()) {
const { commandName } = interaction; const { commandName } = interaction;
@ -129,11 +115,7 @@ client.on('interactionCreate', async (interaction) => {
} else if (commandName === 'modrinth') { } else if (commandName === 'modrinth') {
await modrinthCommand(interaction); await modrinthCommand(interaction);
} else if (commandName === 'say') { } else if (commandName === 'say') {
if (!interaction.channel) return; await sayCommand(interaction);
await interaction.deferReply({ ephemeral: true });
await interaction.channel.send(interaction.options.getString('content')!);
await interaction.editReply('I said what you said!');
} else if (commandName === 'tag') { } else if (commandName === 'tag') {
await tagsCommand(interaction); await tagsCommand(interaction);
} else if (commandName === 'joke') { } else if (commandName === 'joke') {