diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/dev/eval.ts | 4 | ||||
-rw-r--r-- | src/commands/leveling/level.ts | 18 | ||||
-rw-r--r-- | src/commands/moderation/slowmode.ts | 2 | ||||
-rw-r--r-- | src/commands/moulberry-bush/neuRepo.ts | 11 |
4 files changed, 12 insertions, 23 deletions
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index fdef3ac..dd21454 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -18,9 +18,9 @@ import { type CommandMessage, type SlashMessage } from '#lib'; +import canvas from '@napi-rs/canvas'; import { Snowflake as Snowflake_ } from '@sapphire/snowflake'; import assert from 'assert/strict'; -import { Canvas } from 'canvas'; import { exec } from 'child_process'; import { ActionRow, @@ -56,7 +56,7 @@ const { transpile } = ts, /* eslint-enable @typescript-eslint/no-unused-vars */ // prettier-ignore -assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, path, ts, fileURLToPath, promisify, assert, transpile, sh, SnowflakeUtil, __dirname); +assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, path, ts, fileURLToPath, promisify, assert, transpile, sh, SnowflakeUtil, __dirname); export default class EvalCommand extends BushCommand { public constructor() { diff --git a/src/commands/leveling/level.ts b/src/commands/leveling/level.ts index 219ae19..ea2a724 100644 --- a/src/commands/leveling/level.ts +++ b/src/commands/leveling/level.ts @@ -9,9 +9,9 @@ import { type OptArgType, type SlashMessage } from '#lib'; +import canvas from '@napi-rs/canvas'; import { SimplifyNumber } from '@notenoughupdates/simplify-number'; import assert from 'assert/strict'; -import canvas from 'canvas'; import { ApplicationCommandOptionType, AttachmentBuilder, Guild, PermissionFlagsBits, User } from 'discord.js'; assert(canvas); assert(SimplifyNumber); @@ -82,11 +82,6 @@ export default class LevelCommand extends BushCommand { gray = '#23272A', highlight = user.hexAccentColor ?? '#5865F2'; - // ! Broken on node v18 - install the font instead - /* // Load roboto font - canvas.registerFont(join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..', 'assets', 'Roboto-Regular.ttf'), { - family: 'Roboto' - }); */ // Create image canvas const levelCard = canvas.createCanvas(800, 200), ctx = levelCard.getContext('2d'); @@ -96,12 +91,9 @@ export default class LevelCommand extends BushCommand { // Draw avatar const AVATAR_SIZE = 128; const avatarImage = new canvas.Image(); - avatarImage.src = user.displayAvatarURL({ extension: 'png', size: AVATAR_SIZE }); - - await new Promise((resolve, reject) => { - avatarImage.onload = () => resolve(undefined); - avatarImage.onerror = (e) => reject(e); - }); + avatarImage.src = Buffer.from( + await (await fetch(user.displayAvatarURL({ extension: 'png', size: AVATAR_SIZE }))).arrayBuffer() + ); const imageTopCoord = levelCard.height / 2 - AVATAR_SIZE / 2; ctx.drawImage(avatarImage, imageTopCoord, imageTopCoord, AVATAR_SIZE, AVATAR_SIZE); @@ -133,6 +125,6 @@ export default class LevelCommand extends BushCommand { ctx.fillText(`Level: ${userLevel} XP: ${xpTxt} Rank: ${rankTxt}`, AVATAR_SIZE + 70, AVATAR_SIZE - 20); // Return image in buffer form - return levelCard.toBuffer(); + return levelCard.toBuffer('image/png'); } } diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index 44ed84f..2e603c6 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -63,6 +63,8 @@ export default class SlowmodeCommand extends BushCommand { args.channel ??= message.channel!; + assert(args.channel); + if ( args.channel.type !== ChannelType.GuildText && args.channel.type !== ChannelType.GuildNews && diff --git a/src/commands/moulberry-bush/neuRepo.ts b/src/commands/moulberry-bush/neuRepo.ts index fcb6f23..4baae7d 100644 --- a/src/commands/moulberry-bush/neuRepo.ts +++ b/src/commands/moulberry-bush/neuRepo.ts @@ -1,5 +1,5 @@ import { BushCommand, clientSendAndPermCheck, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; -import canvas from 'canvas'; +import canvas from '@napi-rs/canvas'; import { ApplicationCommandOptionType, AttachmentBuilder, @@ -7,9 +7,8 @@ import { CacheType, PermissionFlagsBits } from 'discord.js'; -import { dirname, join } from 'path'; +import { join } from 'path'; import tinycolor from 'tinycolor2'; -import { fileURLToPath } from 'url'; import { formattingInfo, RawNeuItem } from '../../../lib/utils/Minecraft.js'; export default class NeuRepoCommand extends BushCommand { @@ -66,10 +65,6 @@ export default class NeuRepoCommand extends BushCommand { } public toolTip(item: RawNeuItem): Buffer { - canvas.registerFont(join(dirname(fileURLToPath(import.meta.url)), '..', '..', '..', '..', 'assets', 'Faithful.ttf'), { - family: 'Faithful' - }); - const background = '#100010'; const width = 250; @@ -143,7 +138,7 @@ export default class NeuRepoCommand extends BushCommand { item.displayname.split(''); - return itemRender.toBuffer(); + return itemRender.toBuffer('image/png'); } // stolen from NEU and modified |