Skip to content

Commit d6431c0

Browse files
author
xyzjesper
committed
Fixed Tag Module and fixed welcome- and leave module
1 parent 36ee7f4 commit d6431c0

28 files changed

+468
-387
lines changed

bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@top-gg/sdk": "^3.1.6",
3030
"@types/body-parser": "^1.19.6",
3131
"@types/js-yaml": "^4.0.9",
32-
"axios": "1.11.0",
32+
"axios": "1.12.2",
3333
"body-parser": "^2.2.0",
3434
"canvacord": "^6.0.2",
3535
"canvas": "^3.2.0",

prisma/schema.prisma

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ model Tags {
686686
UUID String @unique
687687
TagId String @unique
688688
TriggerKeywords String[] // SOON && NEW
689-
MessageId String
689+
MessageTemplateId String?
690690
IsShlashCommand Boolean
691-
ShlashCommandId String @unique
691+
ShlashCommandId String?
692692
IsTextInputCommand Boolean
693693
IsEnabled Boolean
694694
PermissionRoleId String?

src/helper/databaseHelper.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,4 +314,12 @@ export async function initUsersToDatabase(client: ExtendedClient, user: User) {
314314
} catch (err) {
315315

316316
}
317+
}
318+
319+
export async function migrateDataBase(client: ExtendedClient) {
320+
321+
let migrations = 0
322+
323+
Logger.info(`Loaded ${migrations} migrations for the Database`.magenta)
324+
317325
}

src/helper/utilityHelper.ts

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
ButtonInteraction, ChatInputCommandInteraction, Message, MessageFlags,
44
ModalSubmitInteraction
55
} from "discord.js";
6-
import {createCanvas} from "canvas";
6+
import {createCanvas, loadImage} from "canvas";
77
import FormData from "form-data";
88
import {Config} from "../main/config.js";
99
import axios from "axios";
@@ -12,6 +12,7 @@ import {ExtendedClient} from "../types/client.js";
1212
import {convertToEmojiPng} from "./emojis.js";
1313
import fs from "fs";
1414
import path from "path";
15+
import {DrawCardOptions} from "../types/drawcardoptions.js";
1516

1617
export function getInteractionData(interaction: ButtonInteraction | ModalSubmitInteraction | AnySelectMenuInteraction, split: number) {
1718
return interaction.customId.split(":")[split];
@@ -115,4 +116,70 @@ export async function isInDevelopment(
115116
content: `## ${emoji} ${message}`,
116117
})
117118
}
118-
}
119+
}
120+
121+
export async function drawCardCanvas(opts: DrawCardOptions): Promise<Buffer> {
122+
const width = 800;
123+
const height = 300;
124+
const canvas = createCanvas(width, height);
125+
const ctx = canvas.getContext("2d");
126+
127+
const bg = await loadImage(opts.card.background);
128+
ctx.drawImage(bg, 0, 0, width, height);
129+
130+
131+
if (opts.card.rounded) {
132+
ctx.save();
133+
ctx.beginPath();
134+
const radius = 25;
135+
ctx.moveTo(radius, 0);
136+
ctx.lineTo(width - radius, 0);
137+
ctx.quadraticCurveTo(width, 0, width, radius);
138+
ctx.lineTo(width, height - radius);
139+
ctx.quadraticCurveTo(width, height, width - radius, height);
140+
ctx.lineTo(radius, height);
141+
ctx.quadraticCurveTo(0, height, 0, height - radius);
142+
ctx.lineTo(0, radius);
143+
ctx.quadraticCurveTo(0, 0, radius, 0);
144+
ctx.closePath();
145+
ctx.clip();
146+
ctx.drawImage(bg, 0, 0, width, height);
147+
ctx.restore();
148+
}
149+
150+
if (opts.card.border) {
151+
ctx.lineWidth = 6;
152+
ctx.strokeStyle = "#555252";
153+
ctx.strokeRect(0, 0, width, height);
154+
}
155+
156+
const avatar = await loadImage(opts.avatar.image);
157+
const avatarSize = 128;
158+
const avatarX = 40;
159+
const avatarY = height / 2 - avatarSize / 2;
160+
161+
ctx.save();
162+
ctx.beginPath();
163+
ctx.arc(avatarX + avatarSize / 2, avatarY + avatarSize / 2, avatarSize / 2, 0, Math.PI * 2);
164+
ctx.closePath();
165+
ctx.clip();
166+
ctx.drawImage(avatar, avatarX, avatarY, avatarSize, avatarSize);
167+
ctx.restore();
168+
169+
ctx.beginPath();
170+
ctx.arc(avatarX + avatarSize / 2, avatarY + avatarSize / 2, avatarSize / 2 + opts.avatar.outlineWidth, 0, Math.PI * 2);
171+
ctx.strokeStyle = opts.avatar.outlineColor;
172+
ctx.lineWidth = opts.avatar.outlineWidth;
173+
ctx.stroke();
174+
ctx.fillStyle = opts.text.color;
175+
ctx.font = "bold 36px Sans";
176+
ctx.fillText(opts.text.title, 200, 100);
177+
178+
ctx.font = "24px Sans";
179+
ctx.fillText(opts.text.subtitle, 200, 150);
180+
181+
ctx.font = "20px Sans";
182+
ctx.fillText(opts.text.text, 200, 200);
183+
184+
return canvas.toBuffer("image/png");
185+
}

src/main/database.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {PrismaClient} from "../prisma/index.js";
33
import {LoggingAction} from "../enums/loggingTypes.js";
44
import {Logger} from "./logger.js";
55
import colors from "colors"
6-
import {initGuildsToDatabase, setupDisBotConfig} from "../helper/databaseHelper.js";
6+
import {initGuildsToDatabase, migrateDataBase, setupDisBotConfig} from "../helper/databaseHelper.js";
77
import {Config} from "./config.js";
88
import * as process from "node:process";
99

@@ -37,6 +37,7 @@ export async function connectToDatabase(client: ExtendedClient) {
3737
export async function initDataToDatabase(client: ExtendedClient) {
3838

3939
try {
40+
await migrateDataBase(client)
4041
await initGuildsToDatabase(client)
4142
await setupDisBotConfig(client)
4243

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,98 @@
1-
import { ChannelType, InteractionContextType, PermissionsBitField, SlashCommandBuilder } from "discord.js";
1+
import {ChannelType, InteractionContextType, PermissionsBitField, SlashCommandBuilder} from "discord.js";
22

33
export default {
4-
help: {
5-
name: 'Leave',
6-
description: 'Leave Steup',
7-
usage: '/leave',
8-
examples: [],
9-
aliases: [],
10-
docsLink: 'https://docs.disbot.app/docs/commands/leave'
11-
},
12-
data: new SlashCommandBuilder()
13-
.setName("leave")
14-
.setDescription("Leave Steup")
15-
.setDescriptionLocalizations({ de: "Leave System Setup" })
16-
.setContexts(InteractionContextType.Guild)
17-
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
4+
help: {
5+
name: 'Leave',
6+
description: 'Leave Steup',
7+
usage: '/leave',
8+
examples: [],
9+
aliases: [],
10+
docsLink: 'https://docs.disbot.app/docs/commands/leave'
11+
},
12+
data: new SlashCommandBuilder()
13+
.setName("leave")
14+
.setDescription("Leave Steup")
15+
.setDescriptionLocalizations({de: "Leave System Setup"})
16+
.setContexts(InteractionContextType.Guild)
17+
.setDefaultMemberPermissions(PermissionsBitField.Flags.ManageGuild)
1818

19-
.addSubcommand((subCommand) =>
20-
subCommand
21-
.setName("message")
22-
.setDescription("Use a Message for the Leave System")
23-
.setDescriptionLocalizations({
24-
de: "Nutze eine Nachricht für das Leave System"
25-
})
19+
.addSubcommand((subCommand) =>
20+
subCommand
21+
.setName("message")
22+
.setDescription("Use a Message for the Leave System")
23+
.setDescriptionLocalizations({
24+
de: "Nutze eine Nachricht für das Leave System"
25+
})
2626

27-
.addChannelOption((options) =>
28-
options
29-
.setName("channel")
30-
.setDescription("Set the Leave Channel")
31-
.setDescriptionLocalizations({ de: "Setze den Leave Channel" })
32-
.addChannelTypes(
33-
ChannelType.GuildText,
34-
ChannelType.GuildAnnouncement
35-
)
36-
.setRequired(true)
27+
.addChannelOption((options) =>
28+
options
29+
.setName("channel")
30+
.setDescription("Set the Leave Channel")
31+
.setDescriptionLocalizations({de: "Setze den Leave Channel"})
32+
.addChannelTypes(
33+
ChannelType.GuildText,
34+
ChannelType.GuildAnnouncement
35+
)
36+
.setRequired(true)
37+
)
3738
)
38-
)
39-
.addSubcommand((subCommand) =>
40-
subCommand
41-
.setName("image")
42-
.setDescription("OoO, This Command is currently disabled because we are re-coding the image generation")
43-
.setDescriptionLocalizations({
44-
de: "OoO, This Command is currently disabled because we are re-coding the image generation"
45-
})
39+
.addSubcommand((subCommand) =>
40+
subCommand
41+
.setName("image")
42+
.setDescription("Create a Image to your welcome message")
43+
.setDescriptionLocalizations({
44+
de: "Erstelle ein Image zu deiner Willkommens nachricht"
45+
})
4646

47-
.addChannelOption((options) =>
48-
options
49-
.setName("channel")
50-
.setDescription("Set the Willkommen Channel")
51-
.setDescriptionLocalizations({ de: "Setze den Willkommen Channel" })
52-
.addChannelTypes(
53-
ChannelType.GuildText,
54-
ChannelType.GuildAnnouncement
55-
)
56-
.setRequired(true)
47+
.addChannelOption((options) =>
48+
options
49+
.setName("channel")
50+
.setDescription("Set the Willkommen Channel")
51+
.setDescriptionLocalizations({de: "Setze den Willkommen Channel"})
52+
.addChannelTypes(
53+
ChannelType.GuildText,
54+
ChannelType.GuildAnnouncement
55+
)
56+
.setRequired(true)
57+
)
5758
)
58-
)
5959

60-
.addSubcommand((subCommand) =>
61-
subCommand
62-
.setName("remove")
63-
.setDescription("Remove the Messages from the Database.")
64-
.setDescriptionLocalizations({
65-
de: "Entferne die Nachrichten aus der Datenbank."
66-
})
67-
)
60+
.addSubcommand((subCommand) =>
61+
subCommand
62+
.setName("remove")
63+
.setDescription("Remove the Messages from the Database.")
64+
.setDescriptionLocalizations({
65+
de: "Entferne die Nachrichten aus der Datenbank."
66+
})
67+
)
6868

69-
.addSubcommand((subCommand) =>
70-
subCommand
71-
.setName("toggle")
72-
.setDescription("Toggle Leave System")
73-
.setDescriptionLocalizations({
74-
de: "Schalte Leave System aus/an"
75-
})
76-
.addStringOption((option) =>
77-
option
78-
.setName("toggle")
79-
.setDescription("Toggle Leave System")
80-
.setDescriptionLocalizations({
81-
de: "Schalte Leave System aus/an"
82-
})
83-
.setRequired(true)
84-
.addChoices(
85-
{
86-
name: "✅ Activate the System",
87-
value: "on",
88-
name_localizations: { de: "✅ Aktiviere das System" }
89-
},
90-
{
91-
name: "❌ Deactivate the System",
92-
value: "off",
93-
name_localizations: { de: "❌ Deaktiviere das System" }
94-
}
95-
)
69+
.addSubcommand((subCommand) =>
70+
subCommand
71+
.setName("toggle")
72+
.setDescription("Toggle Leave System")
73+
.setDescriptionLocalizations({
74+
de: "Schalte Leave System aus/an"
75+
})
76+
.addStringOption((option) =>
77+
option
78+
.setName("toggle")
79+
.setDescription("Toggle Leave System")
80+
.setDescriptionLocalizations({
81+
de: "Schalte Leave System aus/an"
82+
})
83+
.setRequired(true)
84+
.addChoices(
85+
{
86+
name: "✅ Activate the System",
87+
value: "on",
88+
name_localizations: {de: "✅ Aktiviere das System"}
89+
},
90+
{
91+
name: "❌ Deactivate the System",
92+
value: "off",
93+
name_localizations: {de: "❌ Deaktiviere das System"}
94+
}
95+
)
96+
)
9697
)
97-
)
9898
};

src/modules/leave/events/guildMemberLeave.ts

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import {ExtendedClient} from "../../../types/client.js";
1111
import {drawCard, LinearGradient} from "discord-welcome-card";
1212
import {database} from "../../../main/database.js";
13+
import {drawCardCanvas} from "../../../helper/utilityHelper.js";
1314

1415
export default {
1516
name: Events.GuildMemberRemove,
@@ -70,7 +71,7 @@ export default {
7071

7172
let imageBuffer = null;
7273
if (data.Image) {
73-
imageBuffer = await drawCard({
74+
imageBuffer = await drawCardCanvas({
7475
theme: (data.ImageData?.Theme as "dark" | "circuit" | "code") ?? "dark",
7576
text: {
7677
title: replaceVars(data.ImageData?.Title) ?? "Goodbye!",
@@ -83,28 +84,20 @@ export default {
8384
avatar: {
8485
image: member.displayAvatarURL({extension: "png"}),
8586
outlineWidth: 5,
86-
outlineColor: new LinearGradient({
87-
col: data.ImageData?.Gradient?.split(",")[0] ?? "#fff",
88-
off: 0,
89-
offset: 1,
90-
color: data.ImageData?.Gradient?.split(",")[1] ?? "#000"
91-
})
87+
outlineColor: data.ImageData?.Gradient?.split(",")[0] ?? "#fff"
9288
},
9389
card: {
94-
background: data.ImageData?.Background ?? "https://i.imgur.com/kjEQRRI.png",
90+
background: data.ImageData?.Background ?? "https://cdn.xyzhub.link/u/czdZgx.png",
9591
blur: 1,
9692
border: true,
9793
rounded: true
9894
}
9995
});
10096
}
101-
102-
const payload: Parameters<TextChannel["send"]>[0] = {};
103-
if (embedJson) payload.embeds = [new EmbedBuilder(embedJson)];
104-
if (content) payload.content = content;
105-
if (imageBuffer) payload.files = [imageBuffer];
106-
107-
if (Object.keys(payload).length === 0) return;
108-
await channel.send(payload);
97+
await channel.send({
98+
content: content ? content : "ㅤ",
99+
embeds: embedJson ? [new EmbedBuilder(embedJson)] : [],
100+
files: imageBuffer ? [new AttachmentBuilder(imageBuffer)] : []
101+
});
109102
}
110103
};

0 commit comments

Comments
 (0)