aboutsummaryrefslogtreecommitdiff
path: root/src/commands/leveling
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/leveling')
-rw-r--r--src/commands/leveling/leaderboard.ts6
-rw-r--r--src/commands/leveling/level.ts5
-rw-r--r--src/commands/leveling/setLevel.ts8
-rw-r--r--src/commands/leveling/setXp.ts5
4 files changed, 15 insertions, 9 deletions
diff --git a/src/commands/leveling/leaderboard.ts b/src/commands/leveling/leaderboard.ts
index eb8b90c..0871811 100644
--- a/src/commands/leveling/leaderboard.ts
+++ b/src/commands/leveling/leaderboard.ts
@@ -1,4 +1,5 @@
import { BushCommand, ButtonPaginator, Level, type ArgType, type BushMessage, type BushSlashMessage } from '#lib';
+import assert from 'assert';
import { ApplicationCommandOptionType, Embed, PermissionFlagsBits } from 'discord.js';
export default class LeaderboardCommand extends BushCommand {
@@ -28,7 +29,8 @@ export default class LeaderboardCommand extends BushCommand {
}
public override async exec(message: BushMessage | BushSlashMessage, args: { page: ArgType<'integer'> }) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`);
+ assert(message.inGuild());
+
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.${
@@ -43,7 +45,7 @@ export default class LeaderboardCommand extends BushCommand {
(val, index) => `\`${index + 1}\` <@${val.user}> - Level ${val.level} (${val.xp.toLocaleString()} xp)`
);
const chunked = util.chunk(mappedRanks, 25);
- const embeds = chunked.map((c) => new Embed().setTitle(`${message.guild!.name}'s Leaderboard`).setDescription(c.join('\n')));
+ const embeds = chunked.map((c) => new Embed().setTitle(`${message.guild.name}'s Leaderboard`).setDescription(c.join('\n')));
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 271c3f6..803703e 100644
--- a/src/commands/leveling/level.ts
+++ b/src/commands/leveling/level.ts
@@ -47,7 +47,8 @@ export default class LevelCommand extends BushCommand {
}
public override async exec(message: BushMessage | BushSlashMessage, args: { user: OptionalArgType<'user'> }) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a server.`);
+ assert(message.inGuild());
+
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.${
@@ -59,7 +60,7 @@ export default class LevelCommand extends BushCommand {
const user = args.user ?? message.author;
try {
return await message.util.reply({
- files: [new MessageAttachment(await this.getImage(user, message.guild!), 'level.png')]
+ 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') {
diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts
index 1016280..e74d885 100644
--- a/src/commands/leveling/setLevel.ts
+++ b/src/commands/leveling/setLevel.ts
@@ -1,4 +1,5 @@
import { AllowedMentions, BushCommand, Level, type ArgType, type BushMessage, type BushSlashMessage } from '#lib';
+import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js';
export default class SetLevelCommand extends BushCommand {
@@ -38,10 +39,11 @@ export default class SetLevelCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{ user, level }: { user: ArgType<'user'>; level: ArgType<'integer'> }
) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`);
- if (!user.id) throw new Error('user.id is null');
+ assert(message.inGuild());
+ assert(user.id);
- if (isNaN(level)) return await message.util.reply(`${util.emojis.error} Provide a valid number to set the user's level to.`);
+ if (isNaN(level) || !Number.isInteger(level))
+ return await message.util.reply(`${util.emojis.error} Provide a valid number to set the user's level to.`);
if (level > 6553 || level < 0)
return await message.util.reply(`${util.emojis.error} You cannot set a level higher than \`6553\`.`);
diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts
index a86c58a..7b1b432 100644
--- a/src/commands/leveling/setXp.ts
+++ b/src/commands/leveling/setXp.ts
@@ -1,4 +1,5 @@
import { AllowedMentions, BushCommand, Level, type ArgType, type BushMessage, type BushSlashMessage } from '#lib';
+import assert from 'assert';
import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js';
export default class SetXpCommand extends BushCommand {
@@ -39,8 +40,8 @@ export default class SetXpCommand extends BushCommand {
message: BushMessage | BushSlashMessage,
{ user, xp }: { user: ArgType<'user'>; xp: ArgType<'abbreviatedNumber'> }
) {
- if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`);
- if (!user.id) throw new Error('user.id is null');
+ assert(message.inGuild());
+ assert(user.id);
if (isNaN(xp)) return await message.util.reply(`${util.emojis.error} Provide a valid number.`);
if (xp > 2147483647 || xp < 0)