aboutsummaryrefslogtreecommitdiff
path: root/src/commands/leveling/setXp.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-10-03 22:57:40 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-10-03 22:57:40 -0400
commit612ed820a0600ec11ed642005377cd7f5a8a8b77 (patch)
tree6bca4e7268fd0063ff53cf64fa44df62a23dba50 /src/commands/leveling/setXp.ts
parented98ff7e2679f362f2657e77a6cf8dd3ce9b3d43 (diff)
downloadtanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.tar.gz
tanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.tar.bz2
tanzanite-612ed820a0600ec11ed642005377cd7f5a8a8b77.zip
wip
Diffstat (limited to 'src/commands/leveling/setXp.ts')
-rw-r--r--src/commands/leveling/setXp.ts34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts
index 8c3b86f..270ad68 100644
--- a/src/commands/leveling/setXp.ts
+++ b/src/commands/leveling/setXp.ts
@@ -1,4 +1,6 @@
-import { AllowedMentions, BotCommand, emojis, format, Level, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
+import { AllowedMentions, BotCommand, emojis, Level, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
+import { commas } from '#lib/common/tags.js';
+import { input } from '#lib/utils/Format.js';
import assert from 'assert/strict';
import { ApplicationCommandOptionType } from 'discord.js';
@@ -44,22 +46,36 @@ export default class SetXpCommand extends BotCommand {
assert(user.id);
if (isNaN(xp)) return await message.util.reply(`${emojis.error} Provide a valid number.`);
- if (xp > 2147483647 || xp < 0)
+
+ if (xp > Level.MAX_XP || xp < 0) {
return await message.util.reply(
- `${emojis.error} Provide an positive integer under **2,147,483,647** to set the user's xp to.`
+ commas`${emojis.error} Provide an positive integer under **${Level.MAX_XP}** to set the user's xp to.`
);
+ }
const [levelEntry] = await Level.findOrBuild({
- where: { user: user.id, guild: message.guild.id },
- defaults: { user: user.id, guild: message.guild.id }
+ where: {
+ user: user.id,
+ guild: message.guild.id
+ }
});
- await levelEntry.update({ xp: xp, user: user.id, guild: message.guild.id });
+ const res = await levelEntry
+ .update({ xp: xp, user: user.id, guild: message.guild.id })
+ .catch((e) => (e instanceof Error ? e : null));
+
+ xp = levelEntry.xp;
+ const level = Level.convertXpToLevel(xp);
+
+ if (res instanceof Error || res == null) {
+ return await message.util.reply({
+ content: commas`Unable to set <@${user.id}>'s xp to **${xp}** with error ${input(res?.message ?? '¯\\_(ツ)_/¯')}.`,
+ allowedMentions: AllowedMentions.none()
+ });
+ }
return await message.util.send({
- content: `Successfully set <@${user.id}>'s xp to ${format.input(levelEntry.xp.toLocaleString())} (level ${format.input(
- Level.convertXpToLevel(levelEntry.xp).toLocaleString()
- )}).`,
+ content: commas`${emojis.success} Successfully set <@${user.id}>'s xp to **${xp}** (level **${level}**).`,
allowedMentions: AllowedMentions.none()
});
}