diff --git a/apps/bot-discord/src/commands/ban.js b/apps/bot-discord/src/commands/ban.js index e69de29..81237da 100644 --- a/apps/bot-discord/src/commands/ban.js +++ b/apps/bot-discord/src/commands/ban.js @@ -0,0 +1,45 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { checkForPerms } from '../utils/checkModPerms.js'; +import reportToLogs from '../utils/reportToLogs.js'; + +export default { + data: new SlashCommandBuilder() + .setName('ban') + .setDescription('Ban a member.') + .setDMPermission(false) + .addStringOption(option => + option + .setName('user') + .setDescription('The member to ban') + .setRequired(true) + ) + .addIntegerOption(option => + option + .setName('dmd') + .setDescription('Amount of days to delete messages') + ) + .addStringOption(option => + option + .setName('reason') + .setDescription('Reason for the ban') + ), + async execute(_, config, interaction) { + if (!checkForPerms(config, interaction.member)) return interaction.reply({ + epheremal: true, + content: 'You don\'t have the required permissions.' + }); + + interaction.guild.members.ban(interaction.getString('user'), { + reason: interaction.getString('reason'), + deleteMessageSeconds: interaction.getInteger('dmd') ? + interaction.getInteger('dmd') * 86_400 : 0 + }); + + reportToLogs(config, interaction.client, 'banned', null, { + reason: interaction.getString('reason'), + actionTo: await client.users.fetch(interaction.getString('user')), + actionBy: interaction.member, + channel: interaction.channel + }); + } +}; diff --git a/apps/bot-discord/src/commands/feedbackDislike.js b/apps/bot-discord/src/commands/feedbackDislike.js index 469aa36..388fc58 100644 --- a/apps/bot-discord/src/commands/feedbackDislike.js +++ b/apps/bot-discord/src/commands/feedbackDislike.js @@ -1,4 +1,4 @@ -import { checkForPerms } from '../utils/checkPerms.js'; +import { checkForPerms } from '../utils/checkSupporterPerms.js'; import trainAISelectMenu from '../utils/trainAISelectMenu.js'; export default { diff --git a/apps/bot-discord/src/commands/feedbackLike.js b/apps/bot-discord/src/commands/feedbackLike.js index 5dd2aa2..960bd85 100644 --- a/apps/bot-discord/src/commands/feedbackLike.js +++ b/apps/bot-discord/src/commands/feedbackLike.js @@ -1,4 +1,4 @@ -import { checkForPerms } from '../utils/checkPerms.js'; +import { checkForPerms } from '../utils/checkSupporterPerms.js'; export default { data: { diff --git a/apps/bot-discord/src/commands/unban.js b/apps/bot-discord/src/commands/unban.js new file mode 100644 index 0000000..884a7be --- /dev/null +++ b/apps/bot-discord/src/commands/unban.js @@ -0,0 +1,42 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { checkForPerms } from '../utils/checkModPerms'; +import reportToLogs from '../utils/reportToLogs.js'; + +export default { + data: new SlashCommandBuilder() + .setName('ban') + .setDescription('Ban a member.') + .setDMPermission(false) + .addStringOption(option => + option + .setName('user') + .setDescription('The member to ban') + .setRequired(true) + ) + .addIntegerOption(option => + option + .setName('dmd') + .setDescription('Amount of days to delete messages') + ) + .addStringOption(option => + option + .setName('reason') + .setDescription('Reason for the ban') + ), + async execute(_, config, interaction) { + if (!checkForPerms(config, interaction.member)) return interaction.reply({ + epheremal: true, + content: 'You don\'t have the required permissions.' + }); + + interaction.guild.members.unban(interaction.getString('user'), + interaction.getString('reason')); + + reportToLogs(config, interaction.client, 'unbanned', null, { + reason: interaction.getString('reason'), + actionTo: await client.users.fetch(interaction.getString('user')), + actionBy: interaction.member, + channel: interaction.channel + }); + } +}; diff --git a/apps/bot-discord/src/utils/checkPerms.js b/apps/bot-discord/src/utils/checkModPerms.js similarity index 72% rename from apps/bot-discord/src/utils/checkPerms.js rename to apps/bot-discord/src/utils/checkModPerms.js index fd8463a..d219191 100644 --- a/apps/bot-discord/src/utils/checkPerms.js +++ b/apps/bot-discord/src/utils/checkModPerms.js @@ -1,5 +1,5 @@ export function checkForPerms(config, member) { - for (let role in config.discord.trainRoles) { + for (const role in config.discord.modRoles) { if (member.roles.cache.get(role)) { return true; } diff --git a/apps/bot-discord/src/utils/checkSupporterPerms.js b/apps/bot-discord/src/utils/checkSupporterPerms.js new file mode 100644 index 0000000..a5c8daf --- /dev/null +++ b/apps/bot-discord/src/utils/checkSupporterPerms.js @@ -0,0 +1,8 @@ +export function checkForPerms(config, member) { + for (const role in config.discord.trainRoles) { + if (member.roles.cache.get(role)) { + return true; + } + } + return false; +} \ No newline at end of file diff --git a/apps/bot-discord/src/utils/reportToLogs.js b/apps/bot-discord/src/utils/reportToLogs.js new file mode 100644 index 0000000..f258ebe --- /dev/null +++ b/apps/bot-discord/src/utils/reportToLogs.js @@ -0,0 +1,33 @@ +import { EmbedBuilder, messageLink } from 'discord.js'; + +export default async function reportToLogs(config, client, action, message, { reason, expire, actionTo, actionBy }, channel) { + const channel = await client.channels.fetch(config.logs.channelId); + const thread = await channel.threads.fetch(config.logs.threadId); + + const actionEmbed = new EmbedBuilder() + .setThumbnail(actionTo.user.avatarURL()); + + const fields = [ + { name: 'Action', value: `${actionTo.toString()} was ${action} by ${actionBy.toString()}` } + ]; + + if (action === 'banned' || action === 'muted') fields.push({ + name: 'Reason', + value: reason ? reason : 'No reason provided' + }); + + if (expire) fields.push({ name: 'Expires', value: ``}); + + if (!message) fields.push({ name: 'Reference', value: `[Jump to message](${messageLink( + message.channelId, + message.id, + message.guild.id)})` + }); + + actionEmbed.setFields(fields); + + if (channel) { + const msg = await channel.send({ embeds: [actionEmbed] }); + reportToLogs(config, client, action, msg, { reason, expire, actionTo, actionBy }); + } else thread.send({ embeds: [actionEmbed] }); +} \ No newline at end of file