aboutsummaryrefslogtreecommitdiff
path: root/src/commands/leveling/level.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/leveling/level.ts')
-rw-r--r--src/commands/leveling/level.ts66
1 files changed, 33 insertions, 33 deletions
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;
- }
- }
}