feat(bot-discord): more support mute features(#19)

This commit is contained in:
GramingFoxTeam
2023-08-13 18:52:53 +03:00
parent 865c682844
commit eb4eab2fb1
19 changed files with 143 additions and 20 deletions

View File

@@ -24,7 +24,7 @@ export default {
.setDescription('Reason for the ban')
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});

View File

@@ -2,6 +2,7 @@ import { SlashCommandBuilder } from 'discord.js';
import { checkForPerms } from '../utils/checkSupporterPerms.js'
import reportToLogs from '../utils/reportToLogs.js';
import muteMember from '../utils/muteMember.js';
import exileMemberToChannel from '../utils/exileMemberToChannel.js';
export default {
data: new SlashCommandBuilder()
@@ -21,7 +22,7 @@ export default {
.setRequired(true)
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});
@@ -32,11 +33,12 @@ export default {
const reason = interaction.options.getString('reason');
const parsedDuration = await muteMember(config, member, {
duration: config.discord.mute.supportMuteDuration,
reason,
supportMute: true
});
exileMemberToChannel(member, interaction.channel, null, config, true);
reportToLogs(config, interaction.client, 'muted', null, {
reason,
actionTo: await client.users.fetch(interaction.options.getString('user')),

View File

@@ -0,0 +1,28 @@
import { ContextMenuCommandBuilder, ApplicationCommandType } from 'discord.js';
import { checkForPerms } from '../utils/checkSupporterPerms.js'
import muteMember from '../utils/muteMember.js';
import exileMemberToChannel from '../utils/exileMemberToChannel.js';
export default {
data: new ContextMenuCommandBuilder()
.setName('Exile Member')
.setType(ApplicationCommandType.Message),
async execute(helper, config, interaction) {
if (
!checkForPerms(config, interaction.member)
)
return interaction.reply({
content: 'You don\'t have the permission to do this.',
ephemeral: true
});
const targetMsg = interaction.targetMessage;
muteMember(config, targetMsg.author, {
channel: interaction.channel,
reason: null,
supportMute: true
});
exileMemberToChannel(targetMsg.author, interaction.channel, targetMsg.content, config, true);
}
};

View File

@@ -7,7 +7,7 @@ export default {
},
async execute(helper, config, interaction) {
if (
checkForPerms(config, interaction.member)
!checkForPerms(config, interaction.member)
)
return interaction.reply({
content: 'You don\'t have the permission to do this.',

View File

@@ -6,7 +6,7 @@ export default {
},
async execute(helper, config, interaction) {
if (
checkForPerms(config, interaction.member)
!checkForPerms(config, interaction.member)
)
return interaction.reply({
content: 'You don\'t have the permission to do this.',

View File

@@ -27,7 +27,7 @@ export default {
.setRequired(true)
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});

View File

@@ -8,7 +8,7 @@ export default {
.setType(ApplicationCommandType.Message),
async execute(helper, config, interaction) {
if (
checkForPerms(config, interaction.member)
!checkForPerms(config, interaction.member)
)
return interaction.reply({
content: 'You don\'t have the permission to do this.',

View File

@@ -14,7 +14,7 @@ export default {
.setRequired(true)
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});

View File

@@ -15,7 +15,7 @@ export default {
.setRequired(true)
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});

View File

@@ -15,7 +15,7 @@ export default {
.setRequired(true)
),
async execute(_, config, interaction) {
if (checkForPerms(config, interaction.member)) return interaction.reply({
if (!checkForPerms(config, interaction.member)) return interaction.reply({
epheremal: true,
content: 'You don\'t have the required permissions.'
});
@@ -24,7 +24,7 @@ export default {
const member = interaction.options.getUser('user');
const isMuted = await unmuteMember(config, member, false);
const isMuted = await unmuteMember(config, member);
if (!isMuted) {
await interaction.editReply({

View File

@@ -29,7 +29,7 @@
],
"supportGiveRoles" : [
"1140310515730632814"
],
"supportMuteDuration": 600000
}

View File

@@ -29,7 +29,7 @@
],
"supportGiveRoles" : [
"1140310515730632814"
],
"supportMuteDuration": 600000
}

View File

@@ -4,14 +4,21 @@ export default {
name: Events.MessageCreate,
once: false,
execute(helper, config, msg) {
if (!msg.guild || msg.system || msg.webhookId) return;
if (!msg.guild || msg.system || msg.webhookId || msg.author.bot) return;
if (msg.content.startsWith('?')) {
const [cmd, args] = msg.content.replace('?', '').split(/\s/g);
const command = msg.client.msgCommands.get(cmd);
if (command) {
await command.execute(msg, args, config);
}
}
if (msg.member.roles.cache.some(role => role.id === config.discord.ignoreRole)) return;
if (config.discord.ignoreChannels.includes(msg.channelId)) return;
if (msg.attachments.first() && msg.attachments.first().contentType.startsWith('image')) {
helper.scanImage(msg.attachments.first().url, `${msg.channelId}/${msg.id}`);
}
if (!msg.content || msg.author.bot) return;
if (!msg.content) return;
helper.scanText(
msg.content.toLowerCase().replace(/<.*?>/g, ''),
`${msg.channelId}/${msg.id}`

View File

@@ -24,6 +24,7 @@ const client = new Client({
});
client.commands = new Collection();
client.msgCommands = new Collection();
client.trainingVotes = new Collection();
client.stickiedMessage = null;
client.stickiedMessageTimeout = null;
@@ -47,6 +48,23 @@ for (const file of commandFiles) {
}
}
const msgCommandsPath = join(__dirname, 'msgCommands');
const msgCommandFiles = readdirSync(msgCommandsPath).filter((file) =>
file.endsWith('.js')
);
for (const file of msgCommandFiles) {
const filePath = join(msgCommandsPath, file);
const command = (await import(`file://${filePath}`)).default;
if ('name' in command && 'execute' in command) {
client.msgCommands.set(command.name, command);
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "name" or "execute" property.`
);
}
}
const discordEventsPath = join(__dirname, 'events');
const discordEventFiles = readdirSync(discordEventsPath).filter((file) =>
file.endsWith('.js')

View File

@@ -0,0 +1,28 @@
import exileMemberToChannel from '../utils/exileMemberToChannel.js';
import { checkForPerms } from '../utils/checkSupporterPerms.js'
import muteMember from '../utils/muteMember.js';
export default {
name: 'exile',
async execute(msg, args, config) {
if (!checkForPerms(config, message.member)) return msg.reply('You don\'t have the permission to do this.');
if (!msg.reference) return msg.reply('You did not reply to anyone!');
const referencedMsg = await msg.channel.messages.fetch(msg.reference.messageId);
let message = referencedMsg.content;
if (args[0]) {
if (isNaN(args[0])) return msg.reply('The argument you entered is not a number!');
const msgsByAuthor = (await msg.channels.fetch({ limit: 50 })).filter(
m => m.author.id === referencedMsg.author.id
);
message = msgsByAuthor.slice(Number(`-${args[0]}`));
}
await muteMember(config, referencedMsg.author, {
supportMute: true
});
exileMemberToChannel(referencedMsg.author, msg.channel, message, config, false);
}
}

View File

@@ -1,6 +1,6 @@
export function checkForPerms(config, member) {
for (const role in config.discord.modRoles) {
if (member.roles.cache.get(role)) {
for (const role of config.discord.modRoles) {
if (member.roles.cache.has(role)) {
return true;
}
}

View File

@@ -1,6 +1,6 @@
export function checkForPerms(config, member) {
for (const role in config.discord.trainRoles) {
if (member.roles.cache.get(role)) {
for (const role of config.discord.trainRoles) {
if (member.roles.cache.has(role)) {
return true;
}
}

View File

@@ -0,0 +1,40 @@
export default async function exileMemberToChannel(member, channel, message, config, isSlash) {
const redirectChannel = await channel.client.channels.fetch(config.discord.supportChannel);
let messageContent = '';
if (Array.isArray(message)) {
for (const msg of message) {
messageContent += `${msg.content}\n`;
}
} else if (!message) message = 'No message provided';
else messageContent = message;
await redirectChannel.send({
content: `<@${member.id}>`,
embeds: [
{
title: '❗ An exiled member appears!',
fields: [
{
name: 'Their message',
value: messageContent
}
]
}
]
});
const messageParams = {
content: `<@${member.id}>`,
embeds: [
{
title: '❗ You have been exiled!',
description: 'This is due to you asking support in non-support channels. Please use the support channel next time.'
}
]
};
if (isSlash) channel.reply(messageParams);
else channel.send(messageParams);
}

View File

@@ -7,7 +7,7 @@ export default async function muteMember(config, member, { duration, reason, sup
let expires;
if (supportMute) {
expires = Math.floor((Date.now() + duration) / 1000);
expires = Math.floor((Date.now() + config.mute.supportMuteDuration) / 1000);
} else {
const parsedDuration = parse(duration);
expires = Math.floor((Date.now() + parsedDuration) / 1000);