diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-21 00:05:53 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-10-21 00:05:53 -0400 |
commit | 166d7fdf24440db71311c2cda95697c06e7b8b36 (patch) | |
tree | 23b0400362b5f3035b156200eb634d202aa54741 /src/commands/leveling | |
parent | 08f33f7d450c8920afc3b9fb8886729547065313 (diff) | |
download | tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.gz tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.tar.bz2 tanzanite-166d7fdf24440db71311c2cda95697c06e7b8b36.zip |
Refactoring, rewrote ButtonPaginator, better permission handling + support for send messages in threads, optimizations, another scam link
Diffstat (limited to 'src/commands/leveling')
-rw-r--r-- | src/commands/leveling/leaderboard.ts | 7 | ||||
-rw-r--r-- | src/commands/leveling/level.ts | 66 | ||||
-rw-r--r-- | src/commands/leveling/setLevel.ts | 4 | ||||
-rw-r--r-- | src/commands/leveling/setXp.ts | 4 |
4 files changed, 41 insertions, 40 deletions
diff --git a/src/commands/leveling/leaderboard.ts b/src/commands/leveling/leaderboard.ts index 432fc60..e3344a0 100644 --- a/src/commands/leveling/leaderboard.ts +++ b/src/commands/leveling/leaderboard.ts @@ -1,5 +1,6 @@ import { BushCommand, BushMessage, BushSlashMessage, Level } from '@lib'; import { MessageEmbed } from 'discord.js'; +import { ButtonPaginator } from '../../lib/common/ButtonPaginator'; export default class LeaderboardCommand extends BushCommand { public constructor() { @@ -32,8 +33,8 @@ export default class LeaderboardCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: [] }); } @@ -62,6 +63,6 @@ export default class LeaderboardCommand extends BushCommand { const embeds = chunked.map((c) => new MessageEmbed().setTitle(`${message.guild!.name}'s Leaderboard`).setDescription(c.join('\n')) ); - return await util.buttonPaginate(message, embeds, undefined, true, args?.page ?? undefined); + return await ButtonPaginator.send(message, embeds, undefined, true, args?.page ?? undefined); } } diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts index 2073e1a..4d7adb3 100644 --- a/src/commands/leveling/level.ts +++ b/src/commands/leveling/level.ts @@ -45,11 +45,42 @@ export default class LevelCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: [] }); } + public override async exec(message: BushMessage | BushSlashMessage, args: { user?: BushUser }): Promise<unknown> { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); + if (!(await message.guild.hasFeature('leveling'))) + return await message.util.reply( + `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${ + message.member?.permissions.has('MANAGE_GUILD') + ? ` You can toggle features using the \`${ + message.util.isSlash + ? '/' + : client.config.isDevelopment + ? 'dev ' + : message.util.parsed?.prefix ?? client.config.prefix + }features\` command.` + : '' + }` + ); + const user = args.user ?? message.author; + try { + return await message.util.reply({ + files: [new MessageAttachment(await this.getImage(user, message.guild!), 'level.png')] + }); + } catch (e) { + if (e instanceof Error && e.message === 'User does not have a level') { + return await message.util.reply({ + content: `${util.emojis.error} ${user} does not have a level.`, + allowedMentions: AllowedMentions.none() + }); + } else throw e; + } + } + private async getImage(user: BushUser, guild: BushGuild): Promise<Buffer> { const guildRows = await Level.findAll({ where: { guild: guild.id } }); const rank = guildRows.sort((a, b) => b.xp - a.xp); @@ -111,35 +142,4 @@ export default class LevelCommand extends BushCommand { // Return image in buffer form return levelCard.toBuffer(); } - - public override async exec(message: BushMessage | BushSlashMessage, args: { user?: BushUser }): Promise<unknown> { - if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`); - if (!(await message.guild.hasFeature('leveling'))) - return await message.util.reply( - `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.${ - message.member?.permissions.has('MANAGE_GUILD') - ? ` You can toggle features using the \`${ - message.util.isSlash - ? '/' - : client.config.isDevelopment - ? 'dev ' - : message.util.parsed?.prefix ?? client.config.prefix - }features\` command.` - : '' - }` - ); - const user = args.user ?? message.author; - try { - return await message.util.reply({ - files: [new MessageAttachment(await this.getImage(user, message.guild!), 'level.png')] - }); - } catch (e) { - if (e instanceof Error && e.message === 'User does not have a level') { - return await message.util.reply({ - content: `${util.emojis.error} ${user} does not have a level.`, - allowedMentions: AllowedMentions.none() - }); - } else throw e; - } - } } diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts index b98b488..9a7337a 100644 --- a/src/commands/leveling/setLevel.ts +++ b/src/commands/leveling/setLevel.ts @@ -45,8 +45,8 @@ export default class SetLevelCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'ADMINISTRATOR'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['ADMINISTRATOR'] }); } diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts index 3e00ea2..a73ae58 100644 --- a/src/commands/leveling/setXp.ts +++ b/src/commands/leveling/setXp.ts @@ -48,8 +48,8 @@ export default class SetXpCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES', 'ADMINISTRATOR'] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: ['ADMINISTRATOR'] }); } |