aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/commands/info/pronouns.ts37
-rw-r--r--src/commands/moulberry-bush/level.ts108
-rw-r--r--src/commands/owner/reload.ts43
-rw-r--r--src/lib/extensions/BotClient.ts6
-rw-r--r--src/lib/extensions/Util.ts139
-rw-r--r--src/lib/models/Ban.ts9
-rw-r--r--src/lib/models/Modlog.ts9
-rw-r--r--src/listeners/client/syncslashcommands.ts5
8 files changed, 309 insertions, 47 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));
}
}
diff --git a/src/lib/extensions/BotClient.ts b/src/lib/extensions/BotClient.ts
index c98f50d..13c8a76 100644
--- a/src/lib/extensions/BotClient.ts
+++ b/src/lib/extensions/BotClient.ts
@@ -143,11 +143,7 @@ export class BotClient extends AkairoClient {
Models.Modlog.initModel(this.db);
Models.Ban.initModel(this.db);
Models.Level.initModel(this.db);
- try {
- await this.db.sync(); // Sync all tables to fix everything if updated
- } catch {
- // Ignore error
- }
+ await this.db.sync(); // Sync all tables to fix everything if updated
}
public async start(): Promise<void> {
diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts
index bd6823f..5e9d5e7 100644
--- a/src/lib/extensions/Util.ts
+++ b/src/lib/extensions/Util.ts
@@ -246,10 +246,13 @@ export class Util extends ClientUtil {
}
public async syncSlashCommands(force = false, guild?: string): Promise<void> {
- let fetchedGuild: Guild
+ let fetchedGuild: Guild;
if (guild) fetchedGuild = this.client.guilds.cache.get(guild);
try {
- const registered = guild === undefined ? await this.client.application.commands.fetch() : await fetchedGuild.commands.fetch();
+ const registered =
+ guild === undefined
+ ? await this.client.application.commands.fetch()
+ : await fetchedGuild.commands.fetch();
for (const [, registeredCommand] of registered) {
if (
!this.client.commandHandler.modules.find(
@@ -257,9 +260,15 @@ export class Util extends ClientUtil {
)?.execSlash ||
force
) {
- guild === undefined ? await this.client.application.commands.delete(registeredCommand.id) : await fetchedGuild.commands.delete(registeredCommand.id);
+ guild === undefined
+ ? await this.client.application.commands.delete(
+ registeredCommand.id
+ )
+ : await fetchedGuild.commands.delete(registeredCommand.id);
this.client.logger.verbose(
- chalk`{red Deleted slash command ${registeredCommand.name}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}`
+ chalk`{red Deleted slash command ${registeredCommand.name}${
+ guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''
+ }}`
);
}
}
@@ -276,25 +285,44 @@ export class Util extends ClientUtil {
if (found?.id && !force) {
if (slashdata.description !== found.description) {
- guild === undefined ? await this.client.application.commands.edit(found.id, slashdata) : fetchedGuild.commands.edit(found.id, slashdata);
+ guild === undefined
+ ? await this.client.application.commands.edit(
+ found.id,
+ slashdata
+ )
+ : fetchedGuild.commands.edit(found.id, slashdata);
this.client.logger.verbose(
- chalk`{yellow Edited slash command ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}`
+ chalk`{yellow Edited slash command ${botCommand.id}${
+ guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''
+ }}`
);
}
} else {
- guild === undefined ? await this.client.application.commands.create(slashdata) : fetchedGuild.commands.create(slashdata);
+ guild === undefined
+ ? await this.client.application.commands.create(slashdata)
+ : fetchedGuild.commands.create(slashdata);
this.client.logger.verbose(
- chalk`{green Created slash command ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}`
+ chalk`{green Created slash command ${botCommand.id}${
+ guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''
+ }}`
);
}
}
}
- return this.client.logger.log(chalk.green(`Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}`));
+ return this.client.logger.log(
+ chalk.green(
+ `Slash commands registered${
+ guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''
+ }`
+ )
+ );
} catch (e) {
console.log(chalk.red(e.stack));
return this.client.logger.error(
- chalk`{red Slash commands not registered${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}, see above error.}`
+ chalk`{red Slash commands not registered${
+ guild !== undefined ? ` in guild ${fetchedGuild.name}` : ''
+ }, see above error.}`
);
}
}
@@ -327,3 +355,94 @@ export class Util extends ClientUtil {
{ name: 'No Support', id: '790247359824396319' }
];
}
+
+// I just copy pasted this code from stackoverflow don't yell at me if there is issues for it
+export class CanvasProgressBar {
+ private x: number;
+ private y: number;
+ private w: number;
+ private h: number;
+ private color: string;
+ private percentage: number;
+ private p: number;
+ private ctx: CanvasRenderingContext2D;
+
+ constructor(
+ ctx: CanvasRenderingContext2D,
+ dimension: { x: number; y: number; width: number; height: number },
+ color: string,
+ percentage: number
+ ) {
+ ({ x: this.x, y: this.y, width: this.w, height: this.h } = dimension);
+ this.color = color;
+ this.percentage = percentage;
+ this.p;
+ this.ctx = ctx;
+ }
+
+ draw() {
+ // -----------------
+ this.p = this.percentage * this.w;
+ if (this.p <= this.h) {
+ this.ctx.beginPath();
+ this.ctx.arc(
+ this.h / 2 + this.x,
+ this.h / 2 + this.y,
+ this.h / 2,
+ Math.PI - Math.acos((this.h - this.p) / this.h),
+ Math.PI + Math.acos((this.h - this.p) / this.h)
+ );
+ this.ctx.save();
+ this.ctx.scale(-1, 1);
+ this.ctx.arc(
+ this.h / 2 - this.p - this.x,
+ this.h / 2 + this.y,
+ this.h / 2,
+ Math.PI - Math.acos((this.h - this.p) / this.h),
+ Math.PI + Math.acos((this.h - this.p) / this.h)
+ );
+ this.ctx.restore();
+ this.ctx.closePath();
+ } else {
+ this.ctx.beginPath();
+ this.ctx.arc(
+ this.h / 2 + this.x,
+ this.h / 2 + this.y,
+ this.h / 2,
+ Math.PI / 2,
+ (3 / 2) * Math.PI
+ );
+ this.ctx.lineTo(this.p - this.h + this.x, 0 + this.y);
+ this.ctx.arc(
+ this.p - this.h / 2 + this.x,
+ this.h / 2 + this.y,
+ this.h / 2,
+ (3 / 2) * Math.PI,
+ Math.PI / 2
+ );
+ this.ctx.lineTo(this.h / 2 + this.x, this.h + this.y);
+ this.ctx.closePath();
+ }
+ this.ctx.fillStyle = this.color;
+ this.ctx.fill();
+ }
+
+ // showWholeProgressBar(){
+ // this.ctx.beginPath();
+ // this.ctx.arc(this.h / 2 + this.x, this.h / 2 + this.y, this.h / 2, Math.PI / 2, 3 / 2 * Math.PI);
+ // this.ctx.lineTo(this.w - this.h + this.x, 0 + this.y);
+ // this.ctx.arc(this.w - this.h / 2 + this.x, this.h / 2 + this.y, this.h / 2, 3 / 2 *Math.PI, Math.PI / 2);
+ // this.ctx.lineTo(this.h / 2 + this.x, this.h + this.y);
+ // this.ctx.strokeStyle = '#000000';
+ // this.ctx.stroke();
+ // this.ctx.closePath();
+ // }
+
+ get PPercentage() {
+ return this.percentage * 100;
+ }
+
+ set PPercentage(x) {
+ this.percentage = x / 100;
+ }
+}
diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts
index 3ce9c06..ab7b38d 100644
--- a/src/lib/models/Ban.ts
+++ b/src/lib/models/Ban.ts
@@ -80,10 +80,11 @@ export class Ban
},
modlog: {
type: DataTypes.STRING,
- allowNull: false,
- references: {
- model: Models.Modlog
- }
+ allowNull: false
+ // references: {
+ // model: Models.Modlog,
+ // key: 'id'
+ // }
}
},
{ sequelize: sequelize }
diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts
index 7efeeed..7e24ba6 100644
--- a/src/lib/models/Modlog.ts
+++ b/src/lib/models/Modlog.ts
@@ -81,10 +81,11 @@ export class Modlog
allowNull: true
},
guild: {
- type: DataTypes.STRING,
- references: {
- model: Models.Guild
- }
+ type: DataTypes.STRING
+ // references: {
+ // model: Models.Guild,
+ // key: 'id'
+ // }
}
},
{ sequelize: sequelize }
diff --git a/src/listeners/client/syncslashcommands.ts b/src/listeners/client/syncslashcommands.ts
index da42185..febdd1b 100644
--- a/src/listeners/client/syncslashcommands.ts
+++ b/src/listeners/client/syncslashcommands.ts
@@ -10,7 +10,10 @@ export default class CreateSlashCommands extends BotListener {
async exec(): Promise<void> {
if (this.client.config.dev && this.client.config.devGuild) {
// Use guild slash commands for instant registration in dev
- await this.client.util.syncSlashCommands(false, this.client.config.devGuild);
+ await this.client.util.syncSlashCommands(
+ false,
+ this.client.config.devGuild
+ );
} else {
// Use global in production
await this.client.util.syncSlashCommands();