mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
feat(bot-discord): support mute (#15)
This commit is contained in:
57
apps/bot-discord/src/commands/exile.js
Normal file
57
apps/bot-discord/src/commands/exile.js
Normal file
@@ -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
|
||||
});
|
||||
}
|
||||
};
|
||||
54
apps/bot-discord/src/commands/unexile.js
Normal file
54
apps/bot-discord/src/commands/unexile.js
Normal file
@@ -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,
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -15,6 +15,7 @@
|
||||
"953964264400515092",
|
||||
"952987428786941952"
|
||||
],
|
||||
"supportChannel": "1135563848586379264",
|
||||
"mute": {
|
||||
"takeRoles": [
|
||||
"996121272897519687",
|
||||
@@ -29,7 +30,8 @@
|
||||
],
|
||||
"supportGiveRoles" : [
|
||||
|
||||
]
|
||||
],
|
||||
"supportMuteDuration": 600000
|
||||
}
|
||||
},
|
||||
"logs": {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
"953964264400515092",
|
||||
"952987428786941952"
|
||||
],
|
||||
"supportChannel": "1135563848586379264",
|
||||
"mute": {
|
||||
"takeRoles": [
|
||||
"996121272897519687",
|
||||
@@ -29,7 +30,8 @@
|
||||
],
|
||||
"supportGiveRoles" : [
|
||||
|
||||
]
|
||||
],
|
||||
"supportMuteDuration": 600000
|
||||
}
|
||||
},
|
||||
"logs": {
|
||||
|
||||
@@ -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 :
|
||||
|
||||
@@ -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 :
|
||||
|
||||
Reference in New Issue
Block a user