mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-23 13:44:59 +05:00
replace canvas with prebuild one
This commit is contained in:
parent
87dd38a4b1
commit
7a280b204c
8 changed files with 1652 additions and 1279 deletions
|
@ -1,5 +1,5 @@
|
|||
const mongoose = require("mongoose"),
|
||||
Canvas = require("canvas");
|
||||
Canvas = require("@napi-rs/canvas");
|
||||
|
||||
const genToken = () => {
|
||||
let token = "";
|
||||
|
@ -107,7 +107,7 @@ userSchema.method("getAchievements", async function () {
|
|||
dim += 200;
|
||||
}
|
||||
|
||||
return canvas.toBuffer();
|
||||
return (await canvas.encode("png"));
|
||||
});
|
||||
|
||||
module.exports = mongoose.model("User", userSchema);
|
||||
|
|
|
@ -83,13 +83,15 @@ class Goodbye extends BaseCommand {
|
|||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||
*/
|
||||
async execute(client, interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const guildData = interaction.data.guild,
|
||||
command = interaction.options.getSubcommand();
|
||||
|
||||
if (command === "test") {
|
||||
client.emit("guildMemberRemove", interaction.member);
|
||||
client.emit("guildMemberRemove", client, interaction.member);
|
||||
|
||||
interaction.success("administration/goodbye:TEST_SUCCESS", null, { ephemeral: true });
|
||||
interaction.success("administration/goodbye:TEST_SUCCESS", null, { edit: true });
|
||||
} else {
|
||||
const state = interaction.options.getBoolean("state");
|
||||
|
||||
|
@ -103,7 +105,7 @@ class Goodbye extends BaseCommand {
|
|||
|
||||
await guildData.save();
|
||||
|
||||
interaction.success("administration/goodbye:DISABLED", null, { ephemeral: true });
|
||||
interaction.success("administration/goodbye:DISABLED", null, { edit: true });
|
||||
} else {
|
||||
const channel = interaction.options.getChannel("channel") || interaction.channel;
|
||||
const message = interaction.options.getString("message") || interaction.translate("administration/goodbye:DEFAULT_MESSAGE");
|
||||
|
|
|
@ -83,13 +83,15 @@ class Welcome extends BaseCommand {
|
|||
* @param {import("discord.js").ChatInputCommandInteraction} interaction
|
||||
*/
|
||||
async execute(client, interaction) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const guildData = interaction.data.guild,
|
||||
command = interaction.options.getSubcommand();
|
||||
|
||||
if (command === "test") {
|
||||
client.emit("guildMemberAdd", interaction.member);
|
||||
client.emit("guildMemberAdd", client, interaction.member);
|
||||
|
||||
interaction.success("administration/goodbye:TEST_SUCCESS", null, { ephemeral: true });
|
||||
interaction.success("administration/goodbye:TEST_SUCCESS", null, { edit: true });
|
||||
} else {
|
||||
const state = interaction.options.getBoolean("state");
|
||||
|
||||
|
@ -103,7 +105,7 @@ class Welcome extends BaseCommand {
|
|||
|
||||
await guildData.save();
|
||||
|
||||
interaction.success("administration/welcome:DISABLED", null, { ephemeral: true });
|
||||
interaction.success("administration/welcome:DISABLED", null);
|
||||
} else {
|
||||
const channel = interaction.options.getChannel("channel") || interaction.channel;
|
||||
const message = interaction.options.getString("message") || interaction.translate("administration/welcome:DEFAULT_MESSAGE");
|
||||
|
@ -120,7 +122,7 @@ class Welcome extends BaseCommand {
|
|||
|
||||
interaction.success("administration/welcome:ENABLED", {
|
||||
channel: `${channel.toString()}`,
|
||||
}, { ephemeral: true });
|
||||
}, { edit: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
const Canvas = require("canvas"),
|
||||
const Canvas = require("@napi-rs/canvas"),
|
||||
BaseEvent = require("../../base/BaseEvent"),
|
||||
{ AttachmentBuilder } = require("discord.js"),
|
||||
{ resolve } = require("path");
|
||||
|
||||
Canvas.registerFont(resolve("./assets/fonts/RubikMonoOne-Regular.ttf"), { family: "RubikMonoOne" });
|
||||
Canvas.registerFont(resolve("./assets/fonts/KeepCalm-Medium.ttf"), { family: "KeepCalm" });
|
||||
|
||||
const applyText = (canvas, text, defaultFontSize, width, font) => {
|
||||
const ctx = canvas.getContext("2d");
|
||||
do ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
||||
while (ctx.measureText(text).width > width);
|
||||
|
||||
return ctx.font;
|
||||
};
|
||||
{ applyText } = require("../../helpers/functions");
|
||||
|
||||
class GuildMemberAdd extends BaseEvent {
|
||||
constructor() {
|
||||
|
@ -132,7 +121,7 @@ class GuildMemberAdd extends BaseEvent {
|
|||
);
|
||||
ctx.drawImage(avatar, 45, 90, 270, 270);
|
||||
|
||||
const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: "welcome-image.png" });
|
||||
const attachment = new AttachmentBuilder((await canvas.encode("png")), { name: "welcome.png" });
|
||||
|
||||
channel.send({
|
||||
content: message,
|
||||
|
|
|
@ -1,18 +1,7 @@
|
|||
const Canvas = require("canvas"),
|
||||
const Canvas = require("@napi-rs/canvas"),
|
||||
BaseEvent = require("../../base/BaseEvent"),
|
||||
{ AttachmentBuilder } = require("discord.js"),
|
||||
{ resolve } = require("path");
|
||||
|
||||
Canvas.registerFont(resolve("./assets/fonts/RubikMonoOne-Regular.ttf"), { family: "RubikMonoOne" });
|
||||
Canvas.registerFont(resolve("./assets/fonts/KeepCalm-Medium.ttf"), { family: "KeepCalm" });
|
||||
|
||||
const applyText = (canvas, text, defaultFontSize, width, font) => {
|
||||
const ctx = canvas.getContext("2d");
|
||||
do ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
||||
while (ctx.measureText(text).width > width);
|
||||
|
||||
return ctx.font;
|
||||
};
|
||||
{ applyText } = require("../../helpers/functions");
|
||||
|
||||
class GuildMemberRemove extends BaseEvent {
|
||||
constructor() {
|
||||
|
@ -135,7 +124,7 @@ class GuildMemberRemove extends BaseEvent {
|
|||
);
|
||||
ctx.drawImage(avatar, 45, 90, 270, 270);
|
||||
|
||||
const attachment = new AttachmentBuilder(canvas.toBuffer(), { name: "goodbye-image.png" });
|
||||
const attachment = new AttachmentBuilder((await canvas.encode("png")), { name: "goodbye-image.png" });
|
||||
|
||||
channel.send({
|
||||
content: message,
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
const moment = require("moment");
|
||||
const moment = require("moment"),
|
||||
resolve = require("path"),
|
||||
Canvas = require("@napi-rs/canvas");
|
||||
|
||||
Canvas.registerFont(resolve("./assets/fonts/RubikMonoOne-Regular.ttf"), { family: "RubikMonoOne" });
|
||||
Canvas.registerFont(resolve("./assets/fonts/KeepCalm-Medium.ttf"), { family: "KeepCalm" });
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
|
@ -125,4 +130,23 @@ module.exports = {
|
|||
|
||||
return five;
|
||||
},
|
||||
|
||||
/**
|
||||
* Function to apply text on a canvas with dynamic font size based on the width constraint.
|
||||
*
|
||||
* @param {import("@napi-rs/canvas").Canvas} canvas - The canvas object where the text will be applied.
|
||||
* @param {string} text - The string of text that needs to be applied on the canvas.
|
||||
* @param {number} defaultFontSize - The initial font size for the text. It is expected to decrease with each iteration.
|
||||
* @param {number} width - The maximum width that the text can occupy before it has to shrink down.
|
||||
* @param {string} font - The name of the font used for drawing the text on the canvas.
|
||||
*
|
||||
* @return {string} - The final calculated font size in a format '<size>px <family>'.
|
||||
*/
|
||||
applyText(canvas, text, defaultFontSize, width, font) {
|
||||
const ctx = canvas.getContext("2d");
|
||||
do ctx.font = `${(defaultFontSize -= 1)}px ${font}`;
|
||||
while (ctx.measureText(text).width > width);
|
||||
|
||||
return ctx.font;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
"@discordjs/opus": "^0.9.0",
|
||||
"@discordjs/rest": "^2.2.0",
|
||||
"@discordjs/voice": "^0.16.1",
|
||||
"canvas": "^2.11.2",
|
||||
"@napi-rs/canvas": "^0.1.53",
|
||||
"chalk": "^4.1.2",
|
||||
"cron": "^2.4.4",
|
||||
"discord-api-types": "^0.37.71",
|
||||
|
|
2725
pnpm-lock.yaml
2725
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue