diff options
-rw-r--r-- | package.json | 2 | ||||
-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 | ||||
-rw-r--r-- | yarn.lock | 16 |
8 files changed, 111 insertions, 6 deletions
diff --git a/package.json b/package.json index 30ec4e7..e3395fe 100644 --- a/package.json +++ b/package.json @@ -38,6 +38,7 @@ "@types/module-alias": "^2", "@types/node": "^14.14.22", "@types/node-fetch": "^2", + "@types/numeral": "^2", "@types/tinycolor2": "^1", "@types/uuid": "^8.3.0", "@types/validator": "^13.6.3", @@ -68,6 +69,7 @@ "module-alias": "^2.2.2", "moment": "^2.29.1", "node-fetch": "^2.6.1", + "numeral": "^2.0.6", "pg": "^8.5.1", "pg-hstore": "^2.3.3", "prettier": "^2.3.2", 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; @@ -372,6 +372,13 @@ __metadata: languageName: node linkType: hard +"@types/numeral@npm:^2": + version: 2.0.1 + resolution: "@types/numeral@npm:2.0.1" + checksum: 58bf8b780d991adf10cab66bb71dfee1bea623a3e0f40d991ef69557cf637be6762e2637879430b1169db7374f7787f95181edc3e959b190fae10965d128fb0d + languageName: node + linkType: hard + "@types/qs@npm:*": version: 6.9.7 resolution: "@types/qs@npm:6.9.7" @@ -766,6 +773,7 @@ __metadata: "@types/module-alias": ^2 "@types/node": ^14.14.22 "@types/node-fetch": ^2 + "@types/numeral": ^2 "@types/tinycolor2": ^1 "@types/uuid": ^8.3.0 "@types/validator": ^13.6.3 @@ -792,6 +800,7 @@ __metadata: module-alias: ^2.2.2 moment: ^2.29.1 node-fetch: ^2.6.1 + numeral: ^2.0.6 pg: ^8.5.1 pg-hstore: ^2.3.3 prettier: ^2.3.2 @@ -2326,6 +2335,13 @@ discord.js@NotEnoughUpdates/discord.js: languageName: node linkType: hard +"numeral@npm:^2.0.6": + version: 2.0.6 + resolution: "numeral@npm:2.0.6" + checksum: 89f011116539692bf53fde380adeb0579623d00f782703c71c0062d4a8686770c404a041ff4eef454de53925a9f75bba1fa52726057b13d40473f707730b07c2 + languageName: node + linkType: hard + "object-assign@npm:^4.1.0": version: 4.1.1 resolution: "object-assign@npm:4.1.1" |