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/moulberry-bush/level.ts | |
parent | 358113f823936a8b5613535067941a17169d942f (diff) | |
download | tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.tar.gz tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.tar.bz2 tanzanite-1546da359646b89f13d17784eb7653a52ca61efd.zip |
Fix file naming
Diffstat (limited to 'src/commands/moulberry-bush/level.ts')
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts new file mode 100644 index 0000000..decac8a --- /dev/null +++ b/src/commands/moulberry-bush/level.ts @@ -0,0 +1,62 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { Message } from 'discord.js'; +import { CommandInteractionOption } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; +import { User } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { Level } from '../../lib/models'; + +export default class LevelCommand extends BushCommand { + constructor() { + super('level', { + aliases: ['level', 'rank'], + category: "Moulberry's Bush", + description: { + content: 'Shows the level of a user', + usage: 'level [user]', + examples: ['level', 'level @Tyman'] + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to see the level of?', + retry: + 'Invalid user. What user would you like to see the level of?', + optional: true + } + } + ], + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to get the level of', + required: false + } + ] + }); + } + + private async getResponse(user: User): Promise<string> { + const userLevelRow = await Level.findByPk(user.id); + if (userLevelRow) { + return `${user ? `${user.tag}'s` : 'Your'} level is ${ + userLevelRow.level + } (${userLevelRow.xp} XP)`; + } else { + return `${user ? `${user.tag} does` : 'You do'} not have a level yet!`; + } + } + + async exec(message: Message, { user }: { user?: User }): Promise<void> { + await message.reply(await this.getResponse(user || message.author)); + } + async execSlash( + message: CommandInteraction, + { user }: { user?: CommandInteractionOption } + ): Promise<void> { + await message.reply(await this.getResponse(user?.user || message.user)); + } +} |