diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-03 11:11:00 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-03 11:11:00 -0400 |
commit | 3e845f120fa1bb0f38e54969238a4d27abad7098 (patch) | |
tree | 07b7c2191daa5d3ddb059d07bab5306a1591bf9e /src | |
parent | 0d73d6956ae2b23ad12a677749a60967bfa0bb55 (diff) | |
download | tanzanite-3e845f120fa1bb0f38e54969238a4d27abad7098.tar.gz tanzanite-3e845f120fa1bb0f38e54969238a4d27abad7098.tar.bz2 tanzanite-3e845f120fa1bb0f38e54969238a4d27abad7098.zip |
add setxp command
Diffstat (limited to 'src')
-rw-r--r-- | src/arguments/abbreviatedNumber.ts | 6 | ||||
-rw-r--r-- | src/commands/leveling/setLevel.ts | 6 | ||||
-rw-r--r-- | src/commands/leveling/setXp.ts | 78 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 4 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushCommand.ts | 3 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 2 |
6 files changed, 93 insertions, 6 deletions
diff --git a/src/arguments/abbreviatedNumber.ts b/src/arguments/abbreviatedNumber.ts new file mode 100644 index 0000000..9da7063 --- /dev/null +++ b/src/arguments/abbreviatedNumber.ts @@ -0,0 +1,6 @@ +import { BushArgumentTypeCaster } from '@lib'; +import numeral = require('numeral'); + +export const abbreviatedNumberTypeCaster: BushArgumentTypeCaster = (_, phrase): number | null => { + return numeral(phrase?.toLowerCase()).value(); +}; diff --git a/src/commands/leveling/setLevel.ts b/src/commands/leveling/setLevel.ts index be3700a..5eb97b7 100644 --- a/src/commands/leveling/setLevel.ts +++ b/src/commands/leveling/setLevel.ts @@ -54,8 +54,6 @@ export default class SetLevelCommand extends BushCommand { message: BushMessage | BushSlashMessage, { user, level }: { user: User; level: number } ): Promise<unknown> { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); if (!user.id) throw new Error('user.id is null'); @@ -71,7 +69,9 @@ export default class SetLevelCommand extends BushCommand { }); await levelEntry.update({ xp: Level.convertLevelToXp(level) }); return await message.util.send({ - content: `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`, + content: `Successfully set level of <@${ + user.id + }> to \`${level.toLocaleString()}\` (\`${levelEntry.xp.toLocaleString()}\` XP)`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/leveling/setXp.ts b/src/commands/leveling/setXp.ts new file mode 100644 index 0000000..4a07519 --- /dev/null +++ b/src/commands/leveling/setXp.ts @@ -0,0 +1,78 @@ +import { AllowedMentions, BushCommand, BushMessage, BushSlashMessage, Level } from '@lib'; +import { User } from 'discord.js'; + +export default class SetXpCommand extends BushCommand { + public constructor() { + super('setXp', { + aliases: ['setxp'], + category: 'leveling', + description: { + content: 'Sets the xp of a user', + usage: 'setlevel <user> <xp>', + examples: ['setlevel @Moulberry 69k'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the xp of?', + retry: '{error} Choose a valid user to change the xp of.' + } + }, + { + id: 'xp', + type: 'abbreviatedNumber', + prompt: { + start: 'How much xp should the user have?', + retry: "{error} Choose a valid number to set the user's xp to." + } + } + ], + slashOptions: [ + { + name: 'user', + description: 'What user would you like to change the xp of?', + type: 'USER', + required: true + }, + { + name: 'xp', + description: 'How much xp should the user have?', + type: 'INTEGER', + required: true + } + ], + slash: true, + channel: 'guild', + clientPermissions: ['SEND_MESSAGES'], + userPermissions: ['SEND_MESSAGES', 'ADMINISTRATOR'] + }); + } + + public override async exec( + message: BushMessage | BushSlashMessage, + { user, xp }: { user: User; xp: number } + ): Promise<unknown> { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This command can only be run in a guild.`); + if (!user.id) throw new Error('user.id is null'); + + const [levelEntry] = await Level.findOrBuild({ + where: { + user: user.id, + guild: message.guild.id + }, + defaults: { + user: user.id, + guild: message.guild.id + } + }); + await levelEntry.update({ xp: xp }); + return await message.util.send({ + content: `Successfully set <@${user.id}>'s xp to \`${levelEntry.xp.toLocaleString()}\` (level \`${Level.convertXpToLevel( + levelEntry.xp + ).toLocaleString()}\`).`, + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 8a21d32..ab66f60 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -22,6 +22,7 @@ import path from 'path'; import { exit } from 'process'; import readline from 'readline'; import { Sequelize } from 'sequelize'; +import { abbreviatedNumberTypeCaster } from '../../../arguments/abbreviatedNumber'; import { contentWithDurationTypeCaster } from '../../../arguments/contentWithDuration'; import { discordEmojiTypeCaster } from '../../../arguments/discordEmoji'; import { durationTypeCaster } from '../../../arguments/duration'; @@ -266,7 +267,8 @@ export class BushClient<Ready extends boolean = boolean> extends AkairoClient<Re permission: permissionTypeCaster, snowflake: snowflakeTypeCaster, discordEmoji: discordEmojiTypeCaster, - roleWithDuration: roleWithDurationTypeCaster + roleWithDuration: roleWithDurationTypeCaster, + abbreviatedNumber: abbreviatedNumberTypeCaster }); // loads all the handlers const loaders = { diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 35046d7..495a454 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -63,7 +63,8 @@ export type BaseBushArgumentType = | 'permission' | 'snowflake' | 'discordEmoji' - | 'roleWithDuration'; + | 'roleWithDuration' + | 'abbreviatedNumber'; export type BushArgumentType = BaseBushArgumentType | RegExp; diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 38b5127..3dbb0ea 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -95,7 +95,7 @@ export const guildLogsObj = { }, moderation: { description: 'Sends a message in this channel every time a moderation action is performed.', - configurable: true + configurable: false } }; export type GuildLogType = keyof typeof guildLogsObj; |