aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush/level.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-05-27 17:15:53 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-05-27 17:15:53 -0400
commit705cead579a79d6ee86dd2e5edfcea2344bea6ce (patch)
tree3adf8875de96e84506d7b650cdc50d358a861d5c /src/commands/moulberry-bush/level.ts
parent2c74ebf6651ccdc78e9fa5799c7887fe52b1ac2d (diff)
parent1546da359646b89f13d17784eb7653a52ca61efd (diff)
downloadtanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.gz
tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.bz2
tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.zip
Merge branch 'rewrite' of https://github.com/NotEnoughUpdates/mb-bot-ts into rewrite
Diffstat (limited to 'src/commands/moulberry-bush/level.ts')
-rw-r--r--src/commands/moulberry-bush/level.ts62
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));
+ }
+}