diff --git a/apps/bot-discord/src/commands/exile.js b/apps/bot-discord/src/commands/exile.js new file mode 100644 index 0000000..0b89b93 --- /dev/null +++ b/apps/bot-discord/src/commands/exile.js @@ -0,0 +1,57 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { checkForPerms } from '../utils/checkSupporterPerms.JS' +import reportToLogs from '../utils/reportToLogs.js'; +import muteMember from '../utils/muteMember.js'; + +export default { + data: new SlashCommandBuilder() + .setName('exile') + .setDescription('Exile a member to support.') + .setDMPermission(false) + .addStringOption(option => + option + .setName('user') + .setDescription('The member to exile') + .setRequired(true) + ) + .addStringOption(option => + option + .setName('reason') + .setDescription('The reason of the exile') + .setRequired(true) + ), + async execute(_, config, interaction) { + if (!checkForPerms(config, interaction.member)) return interaction.reply({ + epheremal: true, + content: 'You don\'t have the required permissions.' + }); + + await interaction.deferReply(); + + let member; + try { + member = await interaction.guild.members.fetch(interaction.getString('user')); + } catch (_) { + await interaction.editReply({ + content: 'Could not find member.' + }); + + return; + } + + const reason = interaction.getString('reason'); + const parsedDuration = await muteMember(config, member, { + duration: config.discord.mute.supportMuteDuration, + reason, + supportMute: true + }); + + reportToLogs(config, interaction.client, 'muted', null, { + reason, + actionTo: await client.users.fetch(interaction.getString('user')), + actionBy: interaction.member, + channel: interaction.channel, + expire: parsedDuration + }); + } +}; diff --git a/apps/bot-discord/src/commands/unexile.js b/apps/bot-discord/src/commands/unexile.js new file mode 100644 index 0000000..bf770f5 --- /dev/null +++ b/apps/bot-discord/src/commands/unexile.js @@ -0,0 +1,54 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { checkForPerms } from '../utils/checkModPerms.js'; +import reportToLogs from '../utils/reportToLogs.js'; +import unmuteMember from '../utils/unmuteMember.js'; + +export default { + data: new SlashCommandBuilder() + .setName('unexile') + .setDescription('Get the member back from an exilation.') + .setDMPermission(false) + .addStringOption(option => + option + .setName('user') + .setDescription('The member to unexile') + .setRequired(true) + ), + async execute(_, config, interaction) { + if (!checkForPerms(config, interaction.member)) return interaction.reply({ + epheremal: true, + content: 'You don\'t have the required permissions.' + }); + + await interaction.deferReply(); + + let member; + try { + member = await interaction.guild.members.fetch(interaction.getString('user')); + } catch (_) { + await interaction.editReply({ + content: 'Could not find member.' + }); + + return; + } + + const reason = interaction.getString('reason'); + const isExiled = await unmuteMember(config, member); + + if (!isExiled) { + await interaction.editReply({ + content: 'Member was not exiled.' + }); + + return; + } + + reportToLogs(config, interaction.client, 'unmuted', null, { + reason, + actionTo: await client.users.fetch(interaction.getString('user')), + actionBy: interaction.member, + channel: interaction.channel, + }); + } +}; diff --git a/apps/bot-discord/src/config.example.json b/apps/bot-discord/src/config.example.json index 79d2185..b0f6250 100644 --- a/apps/bot-discord/src/config.example.json +++ b/apps/bot-discord/src/config.example.json @@ -15,6 +15,7 @@ "953964264400515092", "952987428786941952" ], + "supportChannel": "1135563848586379264", "mute": { "takeRoles": [ "996121272897519687", @@ -29,7 +30,8 @@ ], "supportGiveRoles" : [ - ] + ], + "supportMuteDuration": 600000 } }, "logs": { diff --git a/apps/bot-discord/src/config.json b/apps/bot-discord/src/config.json index bf94cde..9115bcd 100644 --- a/apps/bot-discord/src/config.json +++ b/apps/bot-discord/src/config.json @@ -15,6 +15,7 @@ "953964264400515092", "952987428786941952" ], + "supportChannel": "1135563848586379264", "mute": { "takeRoles": [ "996121272897519687", @@ -29,7 +30,8 @@ ], "supportGiveRoles" : [ - ] + ], + "supportMuteDuration": 600000 } }, "logs": { diff --git a/apps/bot-discord/src/utils/muteMember.js b/apps/bot-discord/src/utils/muteMember.js index f1b3610..f4b7676 100644 --- a/apps/bot-discord/src/utils/muteMember.js +++ b/apps/bot-discord/src/utils/muteMember.js @@ -4,8 +4,15 @@ import setMuteTimeout from './setMuteTimeout.js'; parse['mo'] = parse['month'] export default async function muteMember(config, member, { duration, reason, supportMute }) { - const parsedDuration = parse(duration); - const expires = Date.now() + parsedDuration; + let expires; + + if (supportMute) { + expires = Date.now() + supportMuteDuration; + } else { + const parsedDuration = parse(duration); + expires = Date.now() + parsedDuration; + } + const takenRoles = []; for (const takeRole of supportMute ? config.discord.mute.supportTakeRoles : diff --git a/apps/bot-discord/src/utils/unmuteMember.js b/apps/bot-discord/src/utils/unmuteMember.js index d59e821..bb196ea 100644 --- a/apps/bot-discord/src/utils/unmuteMember.js +++ b/apps/bot-discord/src/utils/unmuteMember.js @@ -5,6 +5,7 @@ export default async function unmuteMember(config, member) { }); if (!mute) return false; + if (!mute.support_mute) return false; member.roles.remove(mute.support_mute ? config.mute.supportGiveRoles :