From 0c1dbd45a117ce6baae9fcf9c81194bee0669dfe Mon Sep 17 00:00:00 2001 From: BluDood Date: Sun, 30 Oct 2022 19:55:05 +0100 Subject: [PATCH] prettify code :) --- commands/avatar.js | 8 ++----- commands/ban.js | 16 ++++--------- commands/censor.js | 18 +++----------- commands/checkPerms.js | 4 +--- commands/define.js | 13 +++------- commands/kick.js | 12 +++------- commands/lock.js | 14 +++-------- commands/neofetch.js | 29 ++++------------------ commands/purge.js | 53 +++++++++-------------------------------- commands/saveEmoji.js | 11 ++------- commands/timeout.js | 26 ++++---------------- commands/unban.js | 8 ++----- commands/unlock.js | 14 +++-------- commands/untimeout.js | 15 +++--------- commands/yourmom.js | 4 +--- console.js | 8 +------ events/messageCreate.js | 4 +--- events/messageDelete.js | 8 ++----- filters/phishing.js | 4 +--- index.js | 12 +++------- setup.js | 37 +++++++--------------------- utils/checkBotPerms.js | 4 +--- utils/checkUserPerms.js | 6 +---- utils/deploy.js | 19 ++++----------- utils/log.js | 20 ++++------------ utils/moderation.js | 8 ++----- 26 files changed, 81 insertions(+), 294 deletions(-) diff --git a/commands/avatar.js b/commands/avatar.js index 5cd119b..66e16ab 100644 --- a/commands/avatar.js +++ b/commands/avatar.js @@ -7,9 +7,7 @@ module.exports = { data: new SlashCommandBuilder() .setName('avatar') .setDescription("Get your or another user's avatar") - .addUserOption(option => - option.setName('target').setDescription('User to show avatar for') - ), + .addUserOption(option => option.setName('target').setDescription('User to show avatar for')), async execute(interaction) { const user = interaction.options.getUser('target') || interaction.user const avatar = format => user.avatarURL({ format }) @@ -17,9 +15,7 @@ module.exports = { embeds: [ { title: `${user.username}'s avatar`, - description: `Download as [png](${avatar('png')}), [jpeg](${avatar( - 'jpeg' - )}) or [webp](${avatar('webp')}).`, + description: `Download as [png](${avatar('png')}), [jpeg](${avatar('jpeg')}) or [webp](${avatar('webp')}).`, color: accent, image: { url: avatar('png') diff --git a/commands/ban.js b/commands/ban.js index d736204..c70da1c 100644 --- a/commands/ban.js +++ b/commands/ban.js @@ -10,15 +10,9 @@ module.exports = { data: new SlashCommandBuilder() .setName('ban') .setDescription('Ban a member.') - .addUserOption(option => - option.setName('target').setDescription('User to ban').setRequired(true) - ) - .addStringOption(option => - option.setName('reason').setDescription('Reason for the ban') - ) - .addNumberOption(option => - option.setName('deletedays').setDescription('Days to delete messages') - ), + .addUserOption(option => option.setName('target').setDescription('User to ban').setRequired(true)) + .addStringOption(option => option.setName('reason').setDescription('Reason for the ban')) + .addNumberOption(option => option.setName('deletedays').setDescription('Days to delete messages')), async execute(interaction) { if (!checkUserPerms(interaction)) return interaction.reply({ @@ -28,9 +22,7 @@ module.exports = { const target = interaction.options.getUser('target') const reason = interaction.options.getString('reason') || 'N/A' const days = interaction.options.getNumber('deletedays') || 0 - const member = await interaction.guild.members - .fetch({ user: target, force: true }) - .catch(() => null) + const member = await interaction.guild.members.fetch({ user: target, force: true }).catch(() => null) if (!member) return interaction.reply({ content: "I can't find that user!", diff --git a/commands/censor.js b/commands/censor.js index 78395f8..369c0ed 100644 --- a/commands/censor.js +++ b/commands/censor.js @@ -13,27 +13,15 @@ module.exports = { subcommand .setName('add') .setDescription('Add a censored word') - .addStringOption(option => - option - .setName('word') - .setDescription('The word to censor') - .setRequired(true) - ) + .addStringOption(option => option.setName('word').setDescription('The word to censor').setRequired(true)) ) .addSubcommand(subcommand => subcommand .setName('remove') .setDescription('Remove a censored word') - .addStringOption(option => - option - .setName('word') - .setDescription('The word to remove') - .setRequired(true) - ) + .addStringOption(option => option.setName('word').setDescription('The word to remove').setRequired(true)) ) - .addSubcommand(subcommand => - subcommand.setName('list').setDescription('List all censored words') - ), + .addSubcommand(subcommand => subcommand.setName('list').setDescription('List all censored words')), async execute(interaction) { const word = interaction.options.getString('word')?.toLowerCase() if (!checkUserPerms(interaction)) diff --git a/commands/checkPerms.js b/commands/checkPerms.js index 0e6fed7..61b7c73 100644 --- a/commands/checkPerms.js +++ b/commands/checkPerms.js @@ -5,9 +5,7 @@ const { const checkUserPerms = require('../utils/checkUserPerms') module.exports = { - data: new SlashCommandBuilder() - .setName('check') - .setDescription('Check if are allowed to moderate using this bot.'), + data: new SlashCommandBuilder().setName('check').setDescription('Check if are allowed to moderate using this bot.'), async execute(interaction) { if (checkUserPerms(interaction)) return interaction.reply({ diff --git a/commands/define.js b/commands/define.js index 217093a..a089101 100644 --- a/commands/define.js +++ b/commands/define.js @@ -8,12 +8,7 @@ module.exports = { data: new SlashCommandBuilder() .setName('define') .setDescription('Define a word with Urban Dictionary!') - .addStringOption(option => - option - .setName('query') - .setDescription('Word to search for') - .setRequired(true) - ), + .addStringOption(option => option.setName('query').setDescription('Word to search for').setRequired(true)), async execute(interaction) { // my api ;) const api = 'https://urbanapi.up.railway.app' @@ -24,10 +19,8 @@ module.exports = { validateStatus: false }) .catch(() => null) - if (!res?.data?.success) - return interaction.editReply('An error has occured!') - if (res.status === 404) - return interaction.editReply('Could not find that word!') + if (!res?.data?.success) return interaction.editReply('An error has occured!') + if (res.status === 404) return interaction.editReply('Could not find that word!') const embed = { color: accent, title: res.data.result[0].word, diff --git a/commands/kick.js b/commands/kick.js index 44c527f..324d37c 100644 --- a/commands/kick.js +++ b/commands/kick.js @@ -10,12 +10,8 @@ module.exports = { data: new SlashCommandBuilder() .setName('kick') .setDescription('Kick a member.') - .addUserOption(option => - option.setName('target').setDescription('User to kick').setRequired(true) - ) - .addStringOption(option => - option.setName('reason').setDescription('Reason for the kick') - ), + .addUserOption(option => option.setName('target').setDescription('User to kick').setRequired(true)) + .addStringOption(option => option.setName('reason').setDescription('Reason for the kick')), async execute(interaction) { if (!checkUserPerms(interaction)) return interaction.reply({ @@ -24,9 +20,7 @@ module.exports = { }) const target = interaction.options.getUser('target') const reason = interaction.options.getString('reason') || 'N/A' - const member = await interaction.guild.members - .fetch({ user: target, force: true }) - .catch(() => null) + const member = await interaction.guild.members.fetch({ user: target, force: true }).catch(() => null) if (!member) return interaction.reply({ content: "I can't find that user!", diff --git a/commands/lock.js b/commands/lock.js index 237b447..0637066 100644 --- a/commands/lock.js +++ b/commands/lock.js @@ -9,24 +9,16 @@ module.exports = { data: new SlashCommandBuilder() .setName('lock') .setDescription('Lock a channel') - .addChannelOption(option => - option.setName('channel').setDescription('Channel to lock') - ), + .addChannelOption(option => option.setName('channel').setDescription('Channel to lock')), async execute(interaction) { if (!checkUserPerms(interaction)) return interaction.reply({ content: 'You do not have permission to do that!', ephemeral: true }) - const channel = - interaction.options.getChannel('channel') || interaction.channel + const channel = interaction.options.getChannel('channel') || interaction.channel if (!channel) return interaction.reply('I cannot access that channel!') - if ( - !channel - .permissionsFor(interaction.guild.roles.everyone) - .has('SEND_MESSAGES') - ) - return interaction.reply('This channel is already locked!') + if (!channel.permissionsFor(interaction.guild.roles.everyone).has('SEND_MESSAGES')) return interaction.reply('This channel is already locked!') try { channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SEND_MESSAGES: false diff --git a/commands/neofetch.js b/commands/neofetch.js index 27d294e..090224d 100644 --- a/commands/neofetch.js +++ b/commands/neofetch.js @@ -1,11 +1,7 @@ const { SlashCommandBuilder } = require('@discordjs/builders') const { Instance } = require('chalk') const os = require('os') -const { - getDependency, - getVersion, - getPackageAmount -} = require('../utils/packagejson') +const { getDependency, getVersion, getPackageAmount } = require('../utils/packagejson') const chalk = new Instance({ level: 1 @@ -15,13 +11,7 @@ module.exports = { data: new SlashCommandBuilder() .setName('neofetch') .setDescription('Information about this bot') - .addBooleanOption(option => - option - .setName('minimal') - .setDescription( - 'Show minimal message without ASCII art. Better for mobile screens.' - ) - ), + .addBooleanOption(option => option.setName('minimal').setDescription('Show minimal message without ASCII art. Better for mobile screens.')), async execute(interaction) { const minimal = interaction.options.getBoolean('minimal') let uptime = process.uptime() @@ -33,12 +23,7 @@ module.exports = { const cpus = os.cpus() const cpu_name = cpus[0].model - const memes = [ - `${chalk.red('People who asked')}: 0`, - `${chalk.red('Amount of bitches achieved')}: 0`, - `${chalk.red('Yo mama')}: phat`, - `${chalk.red('Favorite number')}: 69` - ] + const memes = [`${chalk.red('People who asked')}: 0`, `${chalk.red('Amount of bitches achieved')}: 0`, `${chalk.red('Yo mama')}: phat`, `${chalk.red('Favorite number')}: 69`] // prettier-ignore const info = [ @@ -85,12 +70,6 @@ module.exports = { const offset = Math.floor((ascii.length - info.length) / 2) return minimal ? interaction.reply(`\`\`\`ansi\n \n ${info.join('\n ')}\n \`\`\``) - : interaction.reply( - `\`\`\`ansi\n${chalk.blue( - ascii - .map((a, i) => ' ' + a + ' ' + (info[i - offset] || '')) - .join('\n') - )}\n\n\n\`\`\`` - ) + : interaction.reply(`\`\`\`ansi\n${chalk.blue(ascii.map((a, i) => ' ' + a + ' ' + (info[i - offset] || '')).join('\n'))}\n\n\n\`\`\``) } } diff --git a/commands/purge.js b/commands/purge.js index a426205..b3b79df 100644 --- a/commands/purge.js +++ b/commands/purge.js @@ -13,39 +13,16 @@ module.exports = { subcommand .setName('channel') .setDescription('Purge messages by channel') - .addNumberOption(option => - option - .setName('amount') - .setDescription('Amount of messages to purge (max 100)') - .setRequired(true) - ) - .addChannelOption(option => - option - .setName('channel') - .setDescription('Channel to purge messages in') - ) + .addNumberOption(option => option.setName('amount').setDescription('Amount of messages to purge (max 100)').setRequired(true)) + .addChannelOption(option => option.setName('channel').setDescription('Channel to purge messages in')) ) .addSubcommand(subcommand => subcommand .setName('user') .setDescription('Purge messages by user') - .addUserOption(option => - option - .setName('user') - .setDescription('User to purge messages for') - .setRequired(true) - ) - .addNumberOption(option => - option - .setName('amount') - .setDescription('Amount of messages to purge (max 100)') - .setRequired(true) - ) - .addChannelOption(option => - option - .setName('channel') - .setDescription('Channel to purge messages in') - ) + .addUserOption(option => option.setName('user').setDescription('User to purge messages for').setRequired(true)) + .addNumberOption(option => option.setName('amount').setDescription('Amount of messages to purge (max 100)').setRequired(true)) + .addChannelOption(option => option.setName('channel').setDescription('Channel to purge messages in')) ), async execute(interaction) { if (!checkUserPerms(interaction)) @@ -54,14 +31,11 @@ module.exports = { ephemeral: true }) const amount = interaction.options.getNumber('amount') - const channel = - interaction.options.getChannel('channel') || interaction.channel + const channel = interaction.options.getChannel('channel') || interaction.channel const user = interaction.options.getUser('user') - if (amount > 100) - return interaction.reply('You can only purge up to 100 messages at once.') - if (amount < 1) - return interaction.reply('You must purge at least 1 message.') + if (amount > 100) return interaction.reply('You can only purge up to 100 messages at once.') + if (amount < 1) return interaction.reply('You must purge at least 1 message.') const command = interaction.options.getSubcommand() if (command === 'channel') { @@ -69,9 +43,7 @@ module.exports = { await interaction.reply({ embeds: [ { - title: `Purged ${amount} message${amount === 1 ? '' : 's'} in #${ - channel.name - }!`, + title: `Purged ${amount} message${amount === 1 ? '' : 's'} in #${channel.name}!`, color: accent } ], @@ -93,15 +65,12 @@ module.exports = { .filter(m => m.author.id === user.id) .toJSON() .splice(0, amount) - if (userMessages.length === 0) - return interaction.reply('Could not find any messages by that user.') + if (userMessages.length === 0) return interaction.reply('Could not find any messages by that user.') await channel.bulkDelete(userMessages) await interaction.reply({ embeds: [ { - title: `Purged ${amount} message${amount == 1 ? '' : 's'} by ${ - user.tag - } in #${channel.name}!`, + title: `Purged ${amount} message${amount == 1 ? '' : 's'} by ${user.tag} in #${channel.name}!`, color: accent } ], diff --git a/commands/saveEmoji.js b/commands/saveEmoji.js index 02a3e56..f9b5bd0 100644 --- a/commands/saveEmoji.js +++ b/commands/saveEmoji.js @@ -4,18 +4,11 @@ module.exports = { data: new SlashCommandBuilder() .setName('saveemoji') .setDescription('Converts an emoji to an image.') - .addStringOption(option => - option - .setName('emoji') - .setDescription('Emoji to convert') - .setRequired(true) - ), + .addStringOption(option => option.setName('emoji').setDescription('Emoji to convert').setRequired(true)), async execute(interaction) { const emojiName = interaction.options.getString('emoji') const isCustom = emojiName.startsWith('<:') && emojiName.endsWith('>') - const emoji = isCustom - ? `https://cdn.discordapp.com/emojis/${emojiName.match(/[0-9]+/)[0]}.png` - : `https://emojicdn.elk.sh/${emojiName}?style=apple` + const emoji = isCustom ? `https://cdn.discordapp.com/emojis/${emojiName.match(/[0-9]+/)[0]}.png` : `https://emojicdn.elk.sh/${emojiName}?style=apple` return interaction.reply(emoji) } } diff --git a/commands/timeout.js b/commands/timeout.js index aed36e3..d06f5e2 100644 --- a/commands/timeout.js +++ b/commands/timeout.js @@ -10,27 +10,13 @@ module.exports = { data: new SlashCommandBuilder() .setName('timeout') .setDescription('Time out a member.') - .addUserOption(option => - option - .setName('target') - .setDescription('User to timeout') - .setRequired(true) - ) - .addStringOption(option => - option - .setName('duration') - .setDescription('Duration for the timeout (s, m, h, d, w, M, y)') - .setRequired(true) - ) - .addStringOption(option => - option.setName('reason').setDescription('Reason for the timeout') - ), + .addUserOption(option => option.setName('target').setDescription('User to timeout').setRequired(true)) + .addStringOption(option => option.setName('duration').setDescription('Duration for the timeout (s, m, h, d, w, M, y)').setRequired(true)) + .addStringOption(option => option.setName('reason').setDescription('Reason for the timeout')), async execute(interaction) { const target = interaction.options.getUser('target') const reason = interaction.options.getString('reason') || 'N/A' - const member = await interaction.guild.members - .fetch({ user: target, force: true }) - .catch(() => null) + const member = await interaction.guild.members.fetch({ user: target, force: true }).catch(() => null) if (!member) return interaction.reply({ content: "I can't find that user!", @@ -84,9 +70,7 @@ module.exports = { moderator: { id: interaction.user.id }, - duration: `Duration: ${amount} ${unitNames[unit]}${ - amount == 1 ? '' : 's' - }` + duration: `Duration: ${amount} ${unitNames[unit]}${amount == 1 ? '' : 's'}` }) if (!dm) await interaction.followUp({ diff --git a/commands/unban.js b/commands/unban.js index c46ac4d..ae63c7f 100644 --- a/commands/unban.js +++ b/commands/unban.js @@ -9,12 +9,8 @@ module.exports = { data: new SlashCommandBuilder() .setName('unban') .setDescription('Revokes the ban for a member.') - .addUserOption(option => - option.setName('target').setDescription('User to unban').setRequired(true) - ) - .addStringOption(option => - option.setName('reason').setDescription('Reason for the unban') - ), + .addUserOption(option => option.setName('target').setDescription('User to unban').setRequired(true)) + .addStringOption(option => option.setName('reason').setDescription('Reason for the unban')), async execute(interaction) { if (!checkUserPerms(interaction)) return interaction.reply({ diff --git a/commands/unlock.js b/commands/unlock.js index 8a5d6a8..47c82cf 100644 --- a/commands/unlock.js +++ b/commands/unlock.js @@ -9,24 +9,16 @@ module.exports = { data: new SlashCommandBuilder() .setName('unlock') .setDescription('Unlock a channel') - .addChannelOption(option => - option.setName('channel').setDescription('Channel to unlock') - ), + .addChannelOption(option => option.setName('channel').setDescription('Channel to unlock')), async execute(interaction) { if (!checkUserPerms(interaction)) return interaction.reply({ content: 'You do not have permission to do that!', ephemeral: true }) - const channel = - interaction.options.getChannel('channel') || interaction.channel + const channel = interaction.options.getChannel('channel') || interaction.channel if (!channel) return interaction.reply('I cannot access that channel!') - if ( - channel - .permissionsFor(interaction.guild.roles.everyone) - .has('SEND_MESSAGES') - ) - return interaction.reply('This channel is not locked!') + if (channel.permissionsFor(interaction.guild.roles.everyone).has('SEND_MESSAGES')) return interaction.reply('This channel is not locked!') try { channel.permissionOverwrites.edit(interaction.guild.roles.everyone, { SEND_MESSAGES: null diff --git a/commands/untimeout.js b/commands/untimeout.js index 5463027..95dd41a 100644 --- a/commands/untimeout.js +++ b/commands/untimeout.js @@ -10,21 +10,12 @@ module.exports = { data: new SlashCommandBuilder() .setName('untimeout') .setDescription('Remove the timeout a member.') - .addUserOption(option => - option - .setName('target') - .setDescription('User to remove timeout for') - .setRequired(true) - ) - .addStringOption(option => - option.setName('reason').setDescription('Reason for the timeout removal') - ), + .addUserOption(option => option.setName('target').setDescription('User to remove timeout for').setRequired(true)) + .addStringOption(option => option.setName('reason').setDescription('Reason for the timeout removal')), async execute(interaction) { const target = interaction.options.getUser('target') const reason = interaction.options.getString('reason') || 'N/A' - const member = await interaction.guild.members - .fetch({ user: target, force: true }) - .catch(() => null) + const member = await interaction.guild.members.fetch({ user: target, force: true }).catch(() => null) if (!member) return interaction.reply({ content: "I can't find that user!", diff --git a/commands/yourmom.js b/commands/yourmom.js index 0026a38..fc622fd 100644 --- a/commands/yourmom.js +++ b/commands/yourmom.js @@ -5,9 +5,7 @@ const { } = require('../config.json') module.exports = { - data: new SlashCommandBuilder() - .setName('yourmom') - .setDescription("yo momma so phat she couldn't run this command"), + data: new SlashCommandBuilder().setName('yourmom').setDescription("yo momma so phat she couldn't run this command"), async execute(interaction) { const joke = await axios.get('https://api.yomomma.info').catch(() => null) if (joke?.data.joke) diff --git a/console.js b/console.js index e8f526a..6be2d4e 100644 --- a/console.js +++ b/console.js @@ -35,13 +35,7 @@ const commands = { uptime %= 3600 const minutes = Math.floor(uptime / 60) const seconds = Math.floor(uptime % 60) - console.log( - chalk.yellow( - `\nUptime: ${hours ? `${hours} hours, ` : ''}${ - minutes ? `${minutes} minutes and ` : '' - }${seconds} seconds.` - ) - ) + console.log(chalk.yellow(`\nUptime: ${hours ? `${hours} hours, ` : ''}${minutes ? `${minutes} minutes and ` : ''}${seconds} seconds.`)) }, q: () => { console.log('Goodbye!') diff --git a/events/messageCreate.js b/events/messageCreate.js index fe164c1..3ce5937 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -11,9 +11,7 @@ module.exports = { await message.delete() const messaged = JSON.parse(fs.readFileSync('./databases/messaged.json')) if (messaged[message.author.id]?.time > Date.now() / 1000) return - message.author.send( - "Sorry, you can't send that link here!\nThe link was referring to a known phishing scam, so i deleted the message for you." - ) + message.author.send("Sorry, you can't send that link here!\nThe link was referring to a known phishing scam, so i deleted the message for you.") if (!messaged[message.author.id]) messaged[message.author.id] = {} messaged[message.author.id].time = Date.now() / 1000 + 300 fs.writeFileSync('./databases/messaged.json', JSON.stringify(messaged)) diff --git a/events/messageDelete.js b/events/messageDelete.js index 23cd406..e3eab67 100644 --- a/events/messageDelete.js +++ b/events/messageDelete.js @@ -5,8 +5,7 @@ const sleep = require('../utils/sleep') module.exports = { event: 'messageDelete', async listener(message) { - if (!fs.existsSync('./databases/deleted.txt')) - fs.writeFileSync('./databases/deleted.txt', 'false', 'utf-8') + if (!fs.existsSync('./databases/deleted.txt')) fs.writeFileSync('./databases/deleted.txt', 'false', 'utf-8') if (fs.readFileSync('./databases/deleted.txt', 'utf-8') === 'true') { return fs.writeFileSync('./databases/deleted.txt', 'false', 'utf-8') } @@ -18,10 +17,7 @@ module.exports = { }) const deletionLog = fetchedLogs.entries.first() const { executor, target } = deletionLog || {} - if ( - target?.id === message.author.id && - deletionLog.createdAt > message.createdAt - ) + if (target?.id === message.author.id && deletionLog.createdAt > message.createdAt) log(message.guild, 'messageDelete', { moderator: { id: executor.id diff --git a/filters/phishing.js b/filters/phishing.js index ffe1ed5..dd7681f 100644 --- a/filters/phishing.js +++ b/filters/phishing.js @@ -7,9 +7,7 @@ module.exports = { const detected = [] for (let match of matches) { const domain = match.split('://')[1] - const phish = await axios - .get(`https://phish.sinking.yachts/v2/check/${domain}`) - .catch(() => null) + const phish = await axios.get(`https://phish.sinking.yachts/v2/check/${domain}`).catch(() => null) if (!phish?.data) continue detected.push(match) } diff --git a/index.js b/index.js index bec6fdf..11a88d8 100644 --- a/index.js +++ b/index.js @@ -4,9 +4,7 @@ const deploy = require('./utils/deploy') const bconsole = require('./console') if (!fs.existsSync('./config.json')) { - console.log( - "Looks like you haven't set up the bot yet! Please run 'npm run setup' and try again." - ) + console.log("Looks like you haven't set up the bot yet! Please run 'npm run setup' and try again.") process.exit() } @@ -17,9 +15,7 @@ const client = new Client({ }) client.commands = new Collection() -const commandFiles = fs - .readdirSync('./commands') - .filter(file => file.endsWith('.js')) +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')) for (const file of commandFiles) { const command = require(`./commands/${file}`) client.commands.set(command.data.name, command) @@ -31,9 +27,7 @@ client.once('ready', async c => { deploy(c.user.id) }) -for (const eventFile of fs - .readdirSync('./events') - .filter(file => file.endsWith('.js'))) { +for (const eventFile of fs.readdirSync('./events').filter(file => file.endsWith('.js'))) { const event = require(`./events/${eventFile}`) client.on(event.event, event.listener) } diff --git a/setup.js b/setup.js index 0d288df..7447ace 100644 --- a/setup.js +++ b/setup.js @@ -34,42 +34,25 @@ function readline() { process.exit() } } - console.log( - 'Welcome to the BluBot setup!\nThis script will set up your bot with its token, guild, channels and roles.\nPress Enter to continue...' - ) + console.log('Welcome to the BluBot setup!\nThis script will set up your bot with its token, guild, channels and roles.\nPress Enter to continue...') await readline() console.log('Please enter your Discord bot token:') current.token = await readline() - console.log( - 'Now enter the guild ID of your server. You can find this by enabling Developer Mode and right-clicking your guild.' - ) + console.log('Now enter the guild ID of your server. You can find this by enabling Developer Mode and right-clicking your guild.') current.guildId = await readline() - console.log( - "That's a really nice server you got! Just kidding, i'm not sentient ;(\nWould you like to customize your bot with custom colors for embeds? [y/N]" - ) + console.log("That's a really nice server you got! Just kidding, i'm not sentient ;(\nWould you like to customize your bot with custom colors for embeds? [y/N]") const customColors = (await readline()).toLowerCase() if (customColors === 'y') { - console.log( - 'Alright. Please enter a HEX color you would like as an accent color. This will apply to generic embeds. Leave blank for default.' - ) + console.log('Alright. Please enter a HEX color you would like as an accent color. This will apply to generic embeds. Leave blank for default.') current.customization.accent = await readline() - console.log( - 'Now enter a HEX color you would like as a "good" color. This will apply to embeds which remove a moderation. Leave blank for default.' - ) + console.log('Now enter a HEX color you would like as a "good" color. This will apply to embeds which remove a moderation. Leave blank for default.') current.customization.colors.good = await readline() - console.log( - 'Now enter a HEX color you would like as a "medium" color. This will apply to embeds which add a semi-fatal moderation like a kick or timeout. Leave blank for default.' - ) + console.log('Now enter a HEX color you would like as a "medium" color. This will apply to embeds which add a semi-fatal moderation like a kick or timeout. Leave blank for default.') current.customization.colors.medium = await readline() - console.log( - 'Now enter a HEX color you would like as a "bad" color. This will apply to embeds which add a fatal moderation like a ban. Leave blank for default.' - ) + console.log('Now enter a HEX color you would like as a "bad" color. This will apply to embeds which add a fatal moderation like a ban. Leave blank for default.') current.customization.colors.bad = await readline() } - console.log( - (customColors === 'y' ? '' : "Alright, i'll use the default colors. ") + - 'Now, time to set up your moderation roles. Enter all your moderation role IDs here, separated by a comma.' - ) + console.log((customColors === 'y' ? '' : "Alright, i'll use the default colors. ") + 'Now, time to set up your moderation roles. Enter all your moderation role IDs here, separated by a comma.') current.modRoles = (await readline()).split(',').map(r => parseInt(r.trim())) console.log("Got that. Now enter the channel you'd like me to send logs to:") current.channels.logs = parseInt((await readline()).trim()) @@ -86,8 +69,6 @@ Does this look correct? [Y/n] process.exit() } fs.writeFileSync('config.json', JSON.stringify(current)) - console.log( - "Success! Install dependencies with the command 'npm install', and start the bot with 'npm start'!" - ) + console.log("Success! Install dependencies with the command 'npm install', and start the bot with 'npm start'!") process.exit() })() diff --git a/utils/checkBotPerms.js b/utils/checkBotPerms.js index 31019ce..feef26f 100644 --- a/utils/checkBotPerms.js +++ b/utils/checkBotPerms.js @@ -18,9 +18,7 @@ module.exports = interaction => { 'MODERATE_MEMBERS' ] const currentPerms = interaction.guild.me.permissions.serialize() - const missingPerms = requiredPerms.filter( - perm => currentPerms[perm] === false - ) + const missingPerms = requiredPerms.filter(perm => currentPerms[perm] === false) if (missingPerms.length === 0) return true return missingPerms } diff --git a/utils/checkUserPerms.js b/utils/checkUserPerms.js index 8c1cdab..c8439d4 100644 --- a/utils/checkUserPerms.js +++ b/utils/checkUserPerms.js @@ -1,10 +1,6 @@ const { modRoles } = require('../config.json') module.exports = interaction => { const roles = interaction.member.roles.cache.map(r => r.id) - if ( - roles.some(id => modRoles.includes(id)) || - interaction.member.permissions.has('ADMINISTRATOR') - ) - return true + if (roles.some(id => modRoles.includes(id)) || interaction.member.permissions.has('ADMINISTRATOR')) return true return false } diff --git a/utils/deploy.js b/utils/deploy.js index b83f2fe..561ea19 100644 --- a/utils/deploy.js +++ b/utils/deploy.js @@ -8,22 +8,15 @@ module.exports = id => { const { guildId, token } = require('../config.json') const commands = [] - const commandFiles = fs - .readdirSync('./commands') - .filter(file => file.endsWith('.js')) + const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')) for (const file of commandFiles) { const command = require(`../commands/${file}`) commands.push(command.data.toJSON()) } - const commandsHash = crypto - .createHash('sha256') - .update(JSON.stringify(commands)) - .digest('hex') - if (!fs.existsSync('./databases/commandsHash.txt')) - fs.writeFileSync('./databases/commandsHash.txt', '') - if (fs.readFileSync('./databases/commandsHash.txt', 'utf-8') === commandsHash) - return + const commandsHash = crypto.createHash('sha256').update(JSON.stringify(commands)).digest('hex') + if (!fs.existsSync('./databases/commandsHash.txt')) fs.writeFileSync('./databases/commandsHash.txt', '') + if (fs.readFileSync('./databases/commandsHash.txt', 'utf-8') === commandsHash) return fs.writeFileSync('./databases/commandsHash.txt', commandsHash) const rest = new REST({ version: '9' }).setToken(token) @@ -32,9 +25,7 @@ module.exports = id => { .put(Routes.applicationGuildCommands(id, guildId), { body: commands }) .then(() => // so it doesn't interfere with the console animation - sleep(1000).then(() => - console.log('Successfully updated guild commands.') - ) + sleep(1000).then(() => console.log('Successfully updated guild commands.')) ) .catch(console.error) } diff --git a/utils/log.js b/utils/log.js index 2acff11..19d0999 100644 --- a/utils/log.js +++ b/utils/log.js @@ -23,9 +23,7 @@ module.exports = (guild, type, info) => { }, { name: 'Time', - value: `\n` + value: `\n` } ] }, @@ -42,9 +40,7 @@ module.exports = (guild, type, info) => { }, { name: 'Time', - value: `\n` + value: `\n` } ] }, @@ -65,9 +61,7 @@ module.exports = (guild, type, info) => { }, { name: 'Time', - value: `\n` + value: `\n` } ] } @@ -109,9 +103,7 @@ module.exports = (guild, type, info) => { }, messageDelete: () => { const embed = JSON.parse(JSON.stringify(templates.message)) - embed.title = `Message deleted by ${ - info.moderator ? 'moderator' : 'user' - }` + embed.title = `Message deleted by ${info.moderator ? 'moderator' : 'user'}` embed.color = resolveColor(colors.bad || '#f45450') if (info.moderator) embed.fields.splice(2, 0, { @@ -132,9 +124,7 @@ module.exports = (guild, type, info) => { }, purge: () => { const embed = JSON.parse(JSON.stringify(templates.channel)) - embed.title = `Purged ${info.amount} message${ - info.amount === 1 ? '' : 's' - }${info.target ? ` by ${info.target.tag}` : ''}` + embed.title = `Purged ${info.amount} message${info.amount === 1 ? '' : 's'}${info.target ? ` by ${info.target.tag}` : ''}` embed.color = resolveColor(colors.medium || '#fdbc40') if (info.target) embed.fields.splice(0, 0, { diff --git a/utils/moderation.js b/utils/moderation.js index 8134f92..769dc8a 100644 --- a/utils/moderation.js +++ b/utils/moderation.js @@ -4,9 +4,7 @@ const log = require('./log') async function ban(target, reason, deleteMessages) { if (!target.bannable) return 'that user is not bannable!' - const ban = await target - .ban(target, { days: deleteMessages, reason: reason }) - .catch(() => false) + const ban = await target.ban(target, { days: deleteMessages, reason: reason }).catch(() => false) if (ban == false) return 'I could not ban that user!' return true } @@ -42,9 +40,7 @@ async function untimeout(target, reason) { async function purge(channel, amount, reason, target) { if (!channel.manageable) return 'that channel is not manageable!' - let messages = await channel.messages - .fetch({ limit: amount }, { cache: false, force: true }) - .catch(() => false) + let messages = await channel.messages.fetch({ limit: amount }, { cache: false, force: true }).catch(() => false) if (target) messages = messages.filter(m => m.author.id == target.id) if (messages == false) return 'an unknown error occurred!' if (messages.size == 0) return 'there are no messages to purge!'