Created
May 27, 2022 22:21
-
-
Save PhantomNimbi/8cf7760373fe03511f7ff37adb0bc1df to your computer and use it in GitHub Desktop.
Pylon.Bot Mute System
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as CONFIG from '../modules/config'; | |
import * as CMD from '../modules/config/commands'; | |
import * as KV from '../modules/betterKV'; | |
const GROUP = CONFIG.CLIENT.COMMANDS; | |
const CHANNELS = CONFIG.CHANNELS; | |
const EMBEDS = CONFIG.EMBEDS; | |
const IMAGES = CONFIG.IMAGES; | |
const ROLES = CONFIG.PERMISSIONS.ROLE; | |
const MODERATOR_ROLE = ROLES.MODERATOR; | |
const DEFAULT_ROLE = ROLES.MEMBER; | |
const MUTE_ROLE = ROLES.MUTE; | |
interface structure { | |
index: string; | |
reason: string[]; | |
author: string[]; | |
timestamp: number[]; | |
} | |
GROUP.subcommand( | |
{ | |
name: CMD.MUTE_COMMAND.NAME, | |
description: CMD.MUTE_COMMAND.DESCRIPTION, | |
filters: CMD.MUTE_COMMAND.PERMISSIONS, | |
}, | |
(subCommand) => { | |
subCommand.on( | |
{ | |
name: CMD.MUTE_COMMAND.SUBCOMMAND.ADD.NAME, | |
description: CMD.MUTE_COMMAND.SUBCOMMAND.ADD.DESCRIPTION, | |
aliases: CMD.MUTE_COMMAND.SUBCOMMAND.ADD.ALIASES, | |
filters: CMD.MUTE_COMMAND.SUBCOMMAND.ADD.PERMISSIONS, | |
}, | |
(ctx) => ({ | |
member: ctx.guildMember(), | |
reason: ctx.text(), | |
}), | |
async (message, { member, reason }) => { | |
try { | |
const logging_channel = await discord.getGuildTextChannel( | |
CONFIG.CHANNELS.LOGGING_CHANNEL | |
); | |
console.log('exect'); | |
if (!message.member.roles.some((r) => MODERATOR_ROLE.includes(r))) { | |
await message.reply('You are not permitted to use this command.'); | |
return; | |
} | |
if (member.roles.some((r) => MODERATOR_ROLE.includes(r))) { | |
await message.reply("You can't warn a teammember."); | |
return; | |
} | |
if (member.user.bot) { | |
await message.reply("You can't warn a bot."); | |
return; | |
} | |
await member.removeRole(DEFAULT_ROLE); | |
await member.addRole(MUTE_ROLE); | |
const MUTE_embed = new discord.Embed(); | |
MUTE_embed.setTitle(CONFIG.EMBEDS.MUTE_HEADER_TEXT.ADD); | |
MUTE_embed.addField({ | |
name: 'User', | |
value: member.toMention(), | |
inline: true, | |
}); | |
MUTE_embed.addField({ | |
name: 'Warned By', | |
value: message.member.toMention(), | |
inline: true, | |
}); | |
MUTE_embed.addField({ | |
name: 'Reason', | |
value: '```\n' + reason + '\n```', | |
inline: false, | |
}); | |
await logging_channel?.sendMessage({ embed: MUTE_embed }); | |
const oldData = await KV.GetData( | |
`warncase-${member.user.id}`, | |
'warncases' | |
); | |
if (oldData === undefined) | |
await KV.SaveData( | |
{ | |
index: `warncase-${member.user.id}`, | |
reason: [reason], | |
author: [message.member.user.id], | |
timestamp: [Date.now()], | |
}, | |
'warncases' | |
); | |
else | |
await KV.UpdateDataValues( | |
`warncase-${member.user.id}`, | |
(data: structure) => { | |
data.reason.push(reason); | |
data.author.push(message.member.user.id); | |
data.timestamp.push(Date.now()); | |
return data; | |
}, | |
'warncases' | |
); | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
subCommand.on( | |
{ | |
name: CMD.MUTE_COMMAND.SUBCOMMAND.LIST.NAME, | |
description: CMD.MUTE_COMMAND.SUBCOMMAND.LIST.DESCRIPTION, | |
aliases: CMD.MUTE_COMMAND.SUBCOMMAND.LIST.ALIASES, | |
filters: CMD.MUTE_COMMAND.SUBCOMMAND.LIST.PERMISSIONS, | |
}, | |
(ctx) => ({ | |
member: ctx.guildMember(), | |
reason: ctx.text(), | |
}), | |
async (message, { member, reason }) => { | |
try { | |
if (!message.member.roles.some((r) => MODERATOR_ROLE.includes(r))) { | |
await message.reply('You are not permitted to use this command.'); | |
return; | |
} | |
const infos: undefined | structure = await KV.GetData( | |
`mutecase-${member.user.id}`, | |
'mutecases' | |
); | |
if (infos === undefined) | |
await message.reply('No cases for this user!'); | |
else { | |
let msg: string = `Mute cases for user <@${member.user.id}>: `; | |
console.log(infos); | |
for (let i: number = 0; i < infos.reason.length; ++i) { | |
msg = msg.replace( | |
msg, | |
msg + | |
`\nAuthor: <@${infos.author[i] ?? 'no id'}>. Reason: ${ | |
infos.reason[i] ?? 'no reason' | |
}. Timestamp: ${new Date(infos.timestamp[i])}.` | |
); | |
} | |
await message.reply(msg); | |
} | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
subCommand.on( | |
{ | |
name: CMD.MUTE_COMMAND.SUBCOMMAND.REMOVE.NAME, | |
description: CMD.MUTE_COMMAND.SUBCOMMAND.REMOVE.DESCRIPTION, | |
aliases: CMD.MUTE_COMMAND.SUBCOMMAND.REMOVE.ALIASES, | |
filters: CMD.MUTE_COMMAND.SUBCOMMAND.REMOVE.PERMISSIONS, | |
}, | |
(ctx) => ({ | |
member: ctx.guildMember(), | |
reason: ctx.text(), | |
}), | |
async (message, { member, reason }) => { | |
try { | |
if (!message.member.roles.some((r) => MODERATOR_ROLE.includes(r))) { | |
await message.reply('You are not permitted to use this command.'); | |
return; | |
} | |
if (await KV.DeleteData(`warncase-${member.user.id}`, 'warncases')) { | |
await member.removeRole(MUTE_ROLE); | |
await member.addRole(DEFAULT_ROLE); | |
await message.reply( | |
`Warn cases for the user ${member.toMention()} were succesfully deleted.` | |
); | |
} else | |
await message.reply( | |
`No warn cases were deleted for the user ${member.toMention()}. Probably were no data saved before...` | |
); | |
} catch (e) { | |
const channel = await discord.getTextChannel(CHANNELS.ERROR_CHANNEL); | |
if (!channel) throw new Error(':x: Invalid Error Channel Specified!'); | |
const embed = new discord.Embed(); | |
embed.setDescription( | |
'```ts\n[' + e.name + '(' + e.code + '): ' + e.message + ']\n```' | |
); | |
embed.addField({ | |
name: 'Error Stack', | |
value: '```ts\n' + e.stack + '\n```', | |
inline: false, | |
}); | |
embed.addField({ | |
name: 'Error Code', | |
value: '```\n' + String(e.code) + '\n```', | |
inline: true, | |
}); | |
embed.addField({ | |
name: 'Channel ID', | |
value: '```\n' + String(message.channelId) + '\n```', | |
inline: true, | |
}); | |
embed.setThumbnail({ url: IMAGES.PYLON_LOGO }); | |
embed.setColor(EMBEDS.DEFAULT_COLOR.ORANGE); | |
embed.setTimestamp(new Date().toISOString()); | |
embed.setFooter({ | |
text: EMBEDS.FOOTER_TEXT, | |
iconUrl: IMAGES.PYLON_LOGO, | |
}); | |
console.error(e); | |
channel?.sendMessage({ embed: embed }); | |
} | |
} | |
); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment