diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-27 14:58:21 -0600 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-27 14:58:21 -0600 |
commit | 1546da359646b89f13d17784eb7653a52ca61efd (patch) | |
tree | d3af8ec1d125caecd6dc2202daed3d7922b7d1c5 /src/commands/dev/setLevel.ts | |
parent | 358113f823936a8b5613535067941a17169d942f (diff) | |
download | tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.tar.gz tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.tar.bz2 tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.zip |
Fix file naming
Diffstat (limited to 'src/commands/dev/setLevel.ts')
-rw-r--r-- | src/commands/dev/setLevel.ts | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts new file mode 100644 index 0000000..d1701c5 --- /dev/null +++ b/src/commands/dev/setLevel.ts @@ -0,0 +1,91 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { User } from 'discord.js'; +import { Message } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { Level } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class SetLevelCommand extends BushCommand { + constructor() { + super('setlevel', { + aliases: ['setlevel'], + category: 'dev', + description: { + content: 'Sets the level of a user', + usage: 'setlevel <user> <level>', + examples: ['setlevel @Moulberry 69'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the level of?', + retry: + 'Invalid user. What user would you like to change the level of?' + } + }, + { + id: 'level', + type: 'number', + prompt: { + start: 'What level would you like to set?', + retry: 'Invalid user. What level would you like to set?' + } + } + ], + ownerOnly: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to change the level of', + required: true + }, + { + type: ApplicationCommandOptionType.INTEGER, + name: 'level', + description: 'The level to set the user to', + required: true + } + ] + }); + } + + private async setLevel(user: User, level: number): Promise<string> { + const [levelEntry] = await Level.findOrBuild({ + where: { + id: user.id + }, + defaults: { + id: user.id + } + }); + levelEntry.xp = Level.convertLevelToXp(level); + await levelEntry.save(); + return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; + } + + async exec( + message: Message, + { user, level }: { user: User; level: number } + ): Promise<void> { + await message.util.send(await this.setLevel(user, level), { + allowedMentions: AllowedMentions.none() + }); + } + + async execSlash( + message: CommandInteraction, + { + user, + level + }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } + ): Promise<void> { + await message.reply(await this.setLevel(user.user, level.value), { + allowedMentions: AllowedMentions.none() + }); + } +} |