aboutsummaryrefslogtreecommitdiff
path: root/src/commands/moulberry-bush
diff options
context:
space:
mode:
authorTymanWasTaken <tyman@tyman.tech>2021-05-16 22:23:12 -0400
committerTymanWasTaken <tyman@tyman.tech>2021-05-16 22:23:12 -0400
commit4d63c4af57a7391dd61106b79874b8e83c14971a (patch)
tree4d9aa589b3501169d9ddfe8f0fdff50d9080b553 /src/commands/moulberry-bush
parent759e93bec4e9e2eb86db7434007345c24b0a0252 (diff)
downloadtanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.tar.gz
tanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.tar.bz2
tanzanite-4d63c4af57a7391dd61106b79874b8e83c14971a.zip
change all existing slash commands to have no repeating code, add help slash command
Diffstat (limited to 'src/commands/moulberry-bush')
-rw-r--r--src/commands/moulberry-bush/level.ts37
1 files changed, 11 insertions, 26 deletions
diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts
index 0eb0044..ab41f42 100644
--- a/src/commands/moulberry-bush/level.ts
+++ b/src/commands/moulberry-bush/level.ts
@@ -37,38 +37,23 @@ export default class LevelCommand extends BotCommand {
});
}
- async exec(message: Message, { user }: { user?: User }): Promise<void> {
- const userLevelRow = await Level.findByPk(
- user ? user.id : message.author.id
- );
+ private async getResponse(user: User): Promise<string> {
+ const userLevelRow = await Level.findByPk(user.id);
if (userLevelRow) {
- await message.reply(
- `${user ? `${user.tag}'s` : 'Your'} level is ${userLevelRow.level} (${
- userLevelRow.xp
- } XP)`
- );
+ return `${user ? `${user.tag}'s` : 'Your'} level is ${
+ userLevelRow.level
+ } (${userLevelRow.xp} XP)`;
} else {
- await message.reply(
- `${user ? `${user.tag} does` : 'You do'} not have a level yet!`
- );
+ 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): Promise<void> {
const user =
message.options.find((o) => o.name === 'user')?.user || message.user;
- const userLevelRow = await Level.findByPk(user.id);
- if (userLevelRow) {
- await message.reply(
- `${user.id !== message.user.id ? `${user.tag}'s` : 'Your'} level is ${
- userLevelRow.level
- } (${userLevelRow.xp} XP)`
- );
- } else {
- await message.reply(
- `${
- user.id !== message.user.id ? `${user.tag} does` : 'You do'
- } not have a level yet!`
- );
- }
+ await message.reply(await this.getResponse(user));
}
}