Skip to content

Commit

Permalink
prettify code :)
Browse files Browse the repository at this point in the history
  • Loading branch information
BluDood committed Oct 30, 2022
1 parent 23486ed commit 0c1dbd4
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 294 deletions.
8 changes: 2 additions & 6 deletions commands/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ 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 })
interaction.reply({
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')
Expand Down
16 changes: 4 additions & 12 deletions commands/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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!",
Expand Down
18 changes: 3 additions & 15 deletions commands/censor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 1 addition & 3 deletions commands/checkPerms.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
13 changes: 3 additions & 10 deletions commands/define.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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,
Expand Down
12 changes: 3 additions & 9 deletions commands/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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!",
Expand Down
14 changes: 3 additions & 11 deletions commands/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 4 additions & 25 deletions commands/neofetch.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
Expand All @@ -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 = [
Expand Down Expand Up @@ -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\`\`\``)
}
}
53 changes: 11 additions & 42 deletions commands/purge.js
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -54,24 +31,19 @@ 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') {
await channel.bulkDelete(amount)
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
}
],
Expand All @@ -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
}
],
Expand Down
11 changes: 2 additions & 9 deletions commands/saveEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
26 changes: 5 additions & 21 deletions commands/timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
Expand Down Expand Up @@ -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({
Expand Down
Loading

0 comments on commit 0c1dbd4

Please sign in to comment.