diff options
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/info/pronouns.ts | 37 | ||||
-rw-r--r-- | src/commands/moulberry-bush/level.ts | 108 | ||||
-rw-r--r-- | src/commands/owner/reload.ts | 43 |
3 files changed, 165 insertions, 23 deletions
diff --git a/src/commands/info/pronouns.ts b/src/commands/info/pronouns.ts index 07d210f..97cca34 100644 --- a/src/commands/info/pronouns.ts +++ b/src/commands/info/pronouns.ts @@ -59,9 +59,17 @@ export default class PronounsCommand extends BotCommand { slashEmphemeral: true // I'll add dynamic checking to this later }); } - async sendResponse(message: Message|CommandInteraction, user: User, author: boolean): Promise<void> { + async sendResponse( + message: Message | CommandInteraction, + user: User, + author: boolean + ): Promise<void> { try { - const apiRes: { pronouns: pronounsType } = await got.get(`https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}`).json(); + const apiRes: { pronouns: pronounsType } = await got + .get( + `https://pronoundb.org/api/v1/lookup?platform=discord&id=${user.id}` + ) + .json(); if (message instanceof Message) { message.reply( new MessageEmbed({ @@ -71,7 +79,7 @@ export default class PronounsCommand extends BotCommand { text: 'Data provided by https://pronoundb.org/' } }) - ) + ); } else { message.reply({ embeds: [ @@ -83,24 +91,31 @@ export default class PronounsCommand extends BotCommand { } }) ] - }) + }); } } catch (e) { if (e instanceof HTTPError && e.response.statusCode === 404) { if (author) { - await message.reply('You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.'); + await message.reply( + 'You do not appear to have any pronouns set. Please go to https://pronoundb.org/ and set your pronouns.' + ); } else { - await message.reply(`${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.`); + await message.reply( + `${user.tag} does not appear to have any pronouns set. Please tell them to go to https://pronoundb.org/ and set their pronouns.` + ); } } else throw e; } } async exec(message: Message, { user }: { user?: User }): Promise<void> { const u = user || message.author; - await this.sendResponse(message, u, u.id === message.author.id) + await this.sendResponse(message, u, u.id === message.author.id); } - async execSlash(message: CommandInteraction, { user }: { user?: SlashCommandOption<void> }): Promise<void> { - const u = user?.user || message.user - await this.sendResponse(message, u, u.id === message.user.id) + async execSlash( + message: CommandInteraction, + { user }: { user?: SlashCommandOption<void> } + ): Promise<void> { + const u = user?.user || message.user; + await this.sendResponse(message, u, u.id === message.user.id); } -}
\ No newline at end of file +} diff --git a/src/commands/moulberry-bush/level.ts b/src/commands/moulberry-bush/level.ts index ab08361..046940a 100644 --- a/src/commands/moulberry-bush/level.ts +++ b/src/commands/moulberry-bush/level.ts @@ -5,6 +5,11 @@ import { CommandInteraction } from 'discord.js'; import { User } from 'discord.js'; import { BotCommand } from '../../lib/extensions/BotCommand'; import { Level } from '../../lib/models'; +import canvas from 'canvas'; +import { MessageAttachment } from 'discord.js'; +import { join } from 'path'; +import got from 'got/dist/source'; +import { CanvasProgressBar } from '../../lib/extensions/Util'; export default class LevelCommand extends BotCommand { constructor() { @@ -38,24 +43,121 @@ export default class LevelCommand extends BotCommand { }); } + // private simplifyXP(xp: number): string { + + // } + + // private async getImage(user: User): Promise<Buffer> { + // // I added comments because this code is impossible to read + // const [userLevelRow] = await Level.findOrBuild({ + // where: { + // id: user.id + // }, + // defaults: { + // id: user.id + // } + // }); + // const userLevel = userLevelRow.level + // const currentLevelXP = Level.convertLevelToXp(userLevel); + // const currentLevelXPProgress = userLevelRow.xp - currentLevelXP; + // const xpForNextLevel = + // Level.convertLevelToXp(userLevelRow.level + 1) - currentLevelXP; + // // Load roboto font because yes + // canvas.registerFont( + // join(__dirname, '..', '..', '..', 'Roboto-Regular.ttf'), + // { + // family: 'Roboto' + // } + // ); + // // Create image canvas + // const image = canvas.createCanvas(800, 200), + // ctx = image.getContext('2d'); + // // Fill background + // ctx.fillStyle = '#00c7eb'; + // ctx.fillRect(0, 0, image.width, image.height); + // // Draw avatar + // const avatarBuffer = await got + // .get(user.displayAvatarURL({ format: 'png', size: 128 })) + // .buffer(); + // const avatarImage = new canvas.Image(); + // avatarImage.src = avatarBuffer; + // avatarImage.height = 128 + // avatarImage.width = 128 + // const imageTopCoord = (image.height / 2) - (avatarImage.height / 2) + // ctx.drawImage(avatarImage, imageTopCoord, imageTopCoord); + // // Write tag of user + // ctx.font = '30px Roboto'; + // ctx.fillStyle = 'black'; + // const measuredTag = ctx.measureText(user.tag); + // ctx.fillText(user.tag, avatarImage.width + 70, 60); + // // Draw line under tag + // ctx.fillStyle = 'yellow'; + // ctx.fillRect( + // avatarImage.width + 70, + // 65 + measuredTag.actualBoundingBoxDescent, + // measuredTag.width, + // 3 + // ); + // // Draw leveling bar + // const fullProgressBar = new CanvasProgressBar( + // ctx, + // { + // x: avatarImage.width + 70, + // y: avatarImage.height - 10, + // height: 30, + // width: 550 + // }, + // '#6e6e6e', + // 1 + // ); + // fullProgressBar.draw(); + // const progressBar = new CanvasProgressBar( + // ctx, + // { + // x: avatarImage.width + 70, + // y: avatarImage.height - 10, + // height: 30, + // width: 550 + // }, + // 'yellow', + // currentLevelXPProgress / xpForNextLevel + // ); + // progressBar.draw(); + // // Draw level data text + // ctx.fillStyle = 'black' + // ctx.fillText(`Level: ${userLevel} XP: $`, avatarImage.width + 70, avatarImage.height - 20) + // // Return image in buffer form + // return image.toBuffer(); + // } + 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)`; + 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( + // new MessageAttachment( + // await this.getImage(user || message.author), + // 'lel.png' + // ) + // ); await message.reply(await this.getResponse(user || message.author)); } async execSlash( message: CommandInteraction, { user }: { user?: CommandInteractionOption } ): Promise<void> { + // await message.reply( + // new MessageAttachment( + // await this.getImage(user?.user || message.user), + // 'lel.png' + // ) + // ); await message.reply(await this.getResponse(user?.user || message.user)); } } diff --git a/src/commands/owner/reload.ts b/src/commands/owner/reload.ts index 0330b27..8ba6160 100644 --- a/src/commands/owner/reload.ts +++ b/src/commands/owner/reload.ts @@ -2,6 +2,8 @@ import { BotCommand } from '../../lib/extensions/BotCommand'; import { stripIndent } from 'common-tags'; import { Message } from 'discord.js'; import { CommandInteraction } from 'discord.js'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { ApplicationCommandOptionType } from 'discord-api-types'; export default class ReloadCommand extends BotCommand { constructor() { @@ -12,19 +14,36 @@ export default class ReloadCommand extends BotCommand { usage: 'reload', examples: ['reload'] }, + args: [ + { + id: 'fast', + match: 'flag', + flag: '--fast' + } + ], ownerOnly: true, - typing: true + typing: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.BOOLEAN, + name: 'fast', + description: 'Wheather to use esbuild for fast compiling or not', + required: false + } + ] }); } - private async getResponse(): Promise<string> { + private async getResponse(fast: boolean): Promise<string> { try { - await this.client.util.shell('yarn rimraf dist/'); - await this.client.util.shell('yarn tsc'); + const s = new Date(); + await this.client.util.shell(`yarn build-${fast ? 'esbuild' : 'tsc'}`); this.client.commandHandler.reloadAll(); this.client.listenerHandler.reloadAll(); this.client.inhibitorHandler.reloadAll(); - return '🔁 Successfully reloaded!'; + return `🔁 Successfully reloaded! (${ + new Date().getTime() - s.getTime() + }ms)`; } catch (e) { return stripIndent` An error occured while reloading: @@ -33,11 +52,17 @@ export default class ReloadCommand extends BotCommand { } } - public async exec(message: Message): Promise<void> { - await message.util.send(await this.getResponse()); + public async exec( + message: Message, + { fast }: { fast: boolean } + ): Promise<void> { + await message.util.send(await this.getResponse(fast)); } - public async execSlash(message: CommandInteraction): Promise<void> { - await message.reply(await this.getResponse()); + public async execSlash( + message: CommandInteraction, + { fast }: { fast: SlashCommandOption<boolean> } + ): Promise<void> { + await message.reply(await this.getResponse(fast?.value)); } } |