Skip to content

Commit 38bbab7

Browse files
author
xyzjesper
committed
Fixed Ticket Slash Command. Fixed Interaction handeling. Added Github issues to errorHelper.ts for support
1 parent 6e8a31f commit 38bbab7

File tree

19 files changed

+379
-157
lines changed

19 files changed

+379
-157
lines changed

bun.lock

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"name": "disbot",
66
"dependencies": {
77
"@napi-rs/canvas": "^0.1.77",
8+
"@octokit/core": "^7.0.3",
89
"@prisma/client": "^6.14.0",
910
"@sentry/cli": "^2.52.0",
1011
"@sentry/node": "^10.5.0",
@@ -231,6 +232,22 @@
231232

232233
"@npmcli/fs": ["@npmcli/[email protected]", "", { "dependencies": { "semver": "^7.3.5" } }, "sha512-/xGlezI6xfGO9NwuJlnwz/K14qD1kCSAGtacBHnGzeAIuJGazcp45KP5NuyARXoKb7cwulAGWVsbeSxdG/cb0Q=="],
233234

235+
"@octokit/auth-token": ["@octokit/[email protected]", "", {}, "sha512-P4YJBPdPSpWTQ1NU4XYdvHvXJJDxM6YwpS0FZHRgP7YFkdVxsWcpWGy/NVqlAA7PcPCnMacXlRm1y2PFZRWL/w=="],
236+
237+
"@octokit/core": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/auth-token": "^6.0.0", "@octokit/graphql": "^9.0.1", "@octokit/request": "^10.0.2", "@octokit/request-error": "^7.0.0", "@octokit/types": "^14.0.0", "before-after-hook": "^4.0.0", "universal-user-agent": "^7.0.0" } }, "sha512-oNXsh2ywth5aowwIa7RKtawnkdH6LgU1ztfP9AIUCQCvzysB+WeU8o2kyyosDPwBZutPpjZDKPQGIzzrfTWweQ=="],
238+
239+
"@octokit/endpoint": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/types": "^14.0.0", "universal-user-agent": "^7.0.2" } }, "sha512-hoYicJZaqISMAI3JfaDr1qMNi48OctWuOih1m80bkYow/ayPw6Jj52tqWJ6GEoFTk1gBqfanSoI1iY99Z5+ekQ=="],
240+
241+
"@octokit/graphql": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/request": "^10.0.2", "@octokit/types": "^14.0.0", "universal-user-agent": "^7.0.0" } }, "sha512-j1nQNU1ZxNFx2ZtKmL4sMrs4egy5h65OMDmSbVyuCzjOcwsHq6EaYjOTGXPQxgfiN8dJ4CriYHk6zF050WEULg=="],
242+
243+
"@octokit/openapi-types": ["@octokit/[email protected]", "", {}, "sha512-idsIggNXUKkk0+BExUn1dQ92sfysJrje03Q0bv0e+KPLrvyqZF8MnBpFz8UNfYDwB3Ie7Z0TByjWfzxt7vseaA=="],
244+
245+
"@octokit/request": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/endpoint": "^11.0.0", "@octokit/request-error": "^7.0.0", "@octokit/types": "^14.0.0", "fast-content-type-parse": "^3.0.0", "universal-user-agent": "^7.0.2" } }, "sha512-V6jhKokg35vk098iBqp2FBKunk3kMTXlmq+PtbV9Gl3TfskWlebSofU9uunVKhUN7xl+0+i5vt0TGTG8/p/7HA=="],
246+
247+
"@octokit/request-error": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/types": "^14.0.0" } }, "sha512-KRA7VTGdVyJlh0cP5Tf94hTiYVVqmt2f3I6mnimmaVz4UG3gQV/k4mDJlJv3X67iX6rmN7gSHCF8ssqeMnmhZg=="],
248+
249+
"@octokit/types": ["@octokit/[email protected]", "", { "dependencies": { "@octokit/openapi-types": "^25.1.0" } }, "sha512-1y6DgTy8Jomcpu33N+p5w58l6xyt55Ar2I91RPiIA0xCJBXyUAhXCcmZaDWSANiha7R9a6qJJ2CRomGPZ6f46g=="],
250+
234251
"@opentelemetry/api": ["@opentelemetry/[email protected]", "", {}, "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg=="],
235252

236253
"@opentelemetry/api-logs": ["@opentelemetry/[email protected]", "", { "dependencies": { "@opentelemetry/api": "^1.3.0" } }, "sha512-9B9RU0H7Ya1Dx/Rkyc4stuBZSGVQF27WigitInx2QQoj6KUpEFYPKoWjdFTunJYxmXmh17HeBvbMa1EhGyPmqQ=="],
@@ -521,6 +538,8 @@
521538

522539
"base64id": ["[email protected]", "", {}, "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog=="],
523540

541+
"before-after-hook": ["[email protected]", "", {}, "sha512-q6tR3RPqIB1pMiTRMFcZwuG5T8vwp+vUvEG0vuI6B+Rikh5BfPp2fQ82c925FOs+b0lcFQ8CFrL+KbilfZFhOQ=="],
542+
524543
"binary-extensions": ["[email protected]", "", {}, "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw=="],
525544

526545
"bl": ["[email protected]", "", { "dependencies": { "buffer": "^5.5.0", "inherits": "^2.0.4", "readable-stream": "^3.4.0" } }, "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w=="],
@@ -731,6 +750,8 @@
731750

732751
"fast-check": ["[email protected]", "", { "dependencies": { "pure-rand": "^6.1.0" } }, "sha512-h5+1OzzfCC3Ef7VbtKdcv7zsstUQwUDlYpUTvjeUsJAssPgLn7QzbboPtL5ro04Mq0rPOsMzl7q5hIbRs2wD1A=="],
733752

753+
"fast-content-type-parse": ["[email protected]", "", {}, "sha512-ZvLdcY8P+N8mGQJahJV5G4U88CSvT1rP8ApL6uETe88MBXrBHAkZlSEySdUlyztF7ccb+Znos3TFqaepHxdhBg=="],
754+
734755
"fast-deep-equal": ["[email protected]", "", {}, "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q=="],
735756

736757
"fast-glob": ["[email protected]", "", { "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.2", "merge2": "^1.3.0", "micromatch": "^4.0.8" } }, "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg=="],
@@ -1319,6 +1340,8 @@
13191340

13201341
"unique-slug": ["[email protected]", "", { "dependencies": { "imurmurhash": "^0.1.4" } }, "sha512-9OdaqO5kwqR+1kVgHAhsp5vPNU0hnxRa26rBFNfNgM7M6pNtgzeBn3s/xbyCQL3dcjzOatcef6UUHpB/6MaETg=="],
13211342

1343+
"universal-user-agent": ["[email protected]", "", {}, "sha512-TmnEAEAsBJVZM/AADELsK76llnwcf9vMKuPz8JflO1frO8Lchitr0fNaN9d+Ap0BjKtqWqd/J17qeDnXh8CL2A=="],
1344+
13221345
"universalify": ["[email protected]", "", {}, "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg=="],
13231346

13241347
"unpipe": ["[email protected]", "", {}, "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ=="],

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "disbot",
33
"main": "./.build/startup.js",
4-
"version": "1.6.2r2",
4+
"version": "1.6.2r4",
55
"scripts": {
66
"disbot": "node ./.build/src/main/startup.js",
77
"customer": "cd /home/disbot && node ./.build/src/main/startup.js",
@@ -21,6 +21,7 @@
2121
"type": "module",
2222
"dependencies": {
2323
"@napi-rs/canvas": "^0.1.77",
24+
"@octokit/core": "^7.0.3",
2425
"@prisma/client": "^6.14.0",
2526
"@sentry/cli": "^2.52.0",
2627
"@sentry/node": "^10.5.0",

prisma/schema.prisma

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ model TicketSetups {
431431
OldTicketCategoryId String?
432432
RequiredRoles String[]
433433
SlashCommandId String?
434+
SlashCommandName String?
435+
SlashCommandDescription String?
434436
TextCommandName String?
435437
SendTranscriptToUser Boolean?
436438
GuildId String

src/helper/CommandHelper.ts

Lines changed: 81 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import colors from "colors";
2-
import {REST, Routes} from "discord.js";
2+
import {Guild, REST, Routes} from "discord.js";
33
import fs from "fs";
44
import path from "path";
55
import {pathToFileURL} from "url";
@@ -135,55 +135,92 @@ export class CommandHelper {
135135
body: [],
136136
});
137137

138-
try {
139-
const allGuilds = await client.guilds.fetch();
140-
for (const guild of allGuilds.values()) {
141-
const buildInCommandOverrides = await database.buildInCommands.findMany({
142-
where: {
143-
GuildCommandMangerId: guild.id
138+
const allGuilds = await client.guilds.fetch();
139+
for (const guild of allGuilds.values()) {
140+
const buildInCommandOverrides = await database.buildInCommands.findMany({
141+
where: {
142+
GuildCommandMangerId: guild.id
143+
}
144+
})
145+
146+
cmdlist = cmdlist
147+
.filter(cmd => {
148+
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
149+
return !(override && override.IsEnabled === false);
150+
})
151+
.map(cmd => {
152+
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
153+
if (override) {
154+
return {
155+
...cmd,
156+
name: override.CustomName,
157+
description: override.Description ?? client.commands.get(override.CodeName).data.description,
158+
default_member_permissions: override.Permissions ?? client.commands.get(override.CodeName).data.default_member_permissions
159+
};
144160
}
161+
return cmd;
145162
})
146163

147-
cmdlist = cmdlist
148-
.filter(cmd => {
149-
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
150-
return !(override && override.IsEnabled === false);
151-
})
152-
.map(cmd => {
153-
const override = buildInCommandOverrides.find(o => o.CodeName === cmd.name);
154-
if (override) {
155-
return {
156-
...cmd,
157-
name: override.CustomName,
158-
description: override.Description ?? client.commands.get(override.CodeName).data.description,
159-
default_member_permissions: override.Permissions ?? client.commands.get(override.CodeName).data.default_member_permissions
160-
};
161-
}
162-
return cmd;
163-
})
164+
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
165+
body: cmdlist,
166+
});
167+
168+
const ticketCommands = await database.ticketSetups.findMany({
169+
where: {
170+
GuildId: guild.id
171+
}
172+
})
164173

165-
await restClient.put(Routes.applicationGuildCommands(Config.Bot.DiscordApplicationId, guild.id), {
166-
body: cmdlist,
167-
});
174+
for (const ticketCommand of ticketCommands) {
175+
const clientGuild = await client.guilds.fetch(guild.id);
176+
177+
let guildCommand = null;
178+
try {
179+
guildCommand = await clientGuild.commands.fetch(ticketCommand.SlashCommandId);
180+
} catch {
181+
}
182+
183+
if (!guildCommand) {
184+
guildCommand = await clientGuild.commands.create({
185+
name: ticketCommand.SlashCommandName ?? `open-${ticketCommand.CustomId}-ticket`,
186+
description: ticketCommand.SlashCommandDescription ?? ticketCommand.CustomId,
187+
});
188+
189+
await database.ticketSetups.update({
190+
where: {
191+
CustomId: ticketCommand.CustomId,
192+
},
193+
data: {
194+
SlashCommandId: guildCommand.id,
195+
},
196+
});
197+
} else {
198+
if (
199+
guildCommand.name !== ticketCommand.SlashCommandName ||
200+
guildCommand.description !== ticketCommand.SlashCommandDescription
201+
) {
202+
const updated = await guildCommand.edit({
203+
name: ticketCommand.SlashCommandName ?? guildCommand.name,
204+
description: ticketCommand.SlashCommandDescription ?? guildCommand.description,
205+
});
206+
207+
await database.ticketSetups.update({
208+
where: {CustomId: ticketCommand.CustomId},
209+
data: {SlashCommandId: updated.id},
210+
});
211+
}
212+
}
168213
}
169-
Logger.info({
170-
timestamp: new Date().toISOString(),
171-
level: "info",
172-
label: "CommandHelper",
173-
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for ${allGuilds.size} Guilds`,
174-
botType: Config.BotType.toString() || "Unknown",
175-
action: LoggingAction.Command,
176-
});
177-
} catch (err) {
178-
Logger.error({
179-
timestamp: new Date().toISOString(),
180-
level: "error",
181-
label: "CommandHelper",
182-
message: `Failed to load commands: ${err instanceof Error ? err : String(err)}`,
183-
botType: Config.BotType.toString() || "Unknown",
184-
action: LoggingAction.Command,
185-
});
214+
186215
}
216+
Logger.info({
217+
timestamp: new Date().toISOString(),
218+
level: "info",
219+
label: "CommandHelper",
220+
message: `Discord added ${cmdlist.length} commands (${stats.subCommands} subCommands, ${stats.subCommandGroups} subCommandGroups), ${stats.userInstall} userInstall commands, ${stats.contextMenus} context menu commands from ${moduleDirectories.length} module(s) for ${allGuilds.size} Guilds`,
221+
botType: Config.BotType.toString() || "Unknown",
222+
action: LoggingAction.Command,
223+
});
187224
}
188225

189226
public static async guildLoadCommands(client: ExtendedClient) {

src/helper/errorHelper.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {convertToEmojiPng} from "./emojis.js";
1313
import {LoggingAction} from "../enums/loggingTypes.js";
1414
import {Logger} from "../main/logger.js";
1515
import {Config} from "../main/config.js";
16+
import {Octokit} from "@octokit/core";
1617

1718
colors.enable();
1819

@@ -102,8 +103,25 @@ export async function errorHandler(interaction: Interaction, client: any, error:
102103
url: Config.Logging.ErrorWebhook as string,
103104
});
104105

106+
const issue = await exportToGithubIssues(
107+
`Bug Report - ${interaction.user.tag} (${interaction.user.id}) - Interaction`,
108+
[
109+
`## Error Report:`,
110+
`> **User:** ***\`${interaction.user.username}\`*** (\`${interaction.user.id}\`)`,
111+
`> **Error:** \`${error.name}\``,
112+
`> - \`${error.message}\``,
113+
`> **Interaction Id**: \`${interaction.id}\``,
114+
`> **Interaction Type:** \`${interaction.type == 2 ? "Application Command" : interaction.type == 3 ? "Message Component" : interaction.type == 5 ? "Modal Submit" : "Unknown"}\``,
115+
`> **Interaction Name/ID:** \`${interactionName}\``,
116+
``,
117+
`## Error Stack Trace:`,
118+
``,
119+
`\`\`\`ts\n${error.stack}\n\`\`\``,
120+
].join("\n")
121+
)
122+
105123
if (!client.user) throw new Error("Client user is not defined");
106-
await webHookClient.send({
124+
const message = await webHookClient.send({
107125
withComponents: true,
108126
flags: MessageFlags.IsComponentsV2,
109127
components: [
@@ -139,7 +157,6 @@ export async function errorHandler(interaction: Interaction, client: any, error:
139157
threadName:
140158
`Bug Report - ${interaction.user.tag} (${interaction.user.id}) - Interaction`,
141159
})
142-
;
143160

144161
await interaction.editReply({
145162
components: [
@@ -149,7 +166,7 @@ export async function errorHandler(interaction: Interaction, client: any, error:
149166
.addTextDisplayComponents(
150167
new TextDisplayBuilder()
151168
.setContent([
152-
`## ${await convertToEmojiPng("check", client.user?.id)} Successfully sent your Error Report to the Discord!`,
169+
`## ${await convertToEmojiPng("check", client.user?.id)} Successfully sent your Error Report to the Discord!\n-# View your Bug Report on the Discord\n-# - https://discord.com/channels/1084507523492626522/${message.channel_id}/${message.id}\n-# View your Bug Report on the GitHub\n-# - ${issue}`,
153170
].join("\n"))
154171
)
155172
.setButtonAccessory(new ButtonBuilder()
@@ -165,4 +182,30 @@ export async function errorHandler(interaction: Interaction, client: any, error:
165182
});
166183
}
167184

185+
}
186+
187+
188+
async function exportToGithubIssues(title: string, message: string) {
189+
if (!Config.Logging.GitHubAPIToken) return
190+
191+
const octokit = new Octokit({
192+
auth: Config.Logging.GitHubAPIToken
193+
})
194+
195+
const issue = await octokit.request('POST /repos/DisBotDevelopment/DisBot-Bot/issues', {
196+
owner: 'DisBotDevelopment',
197+
repo: 'DisBot-Bot',
198+
title: String(title),
199+
body: String(message),
200+
assignees: [
201+
'xyzjesper'
202+
],
203+
labels: [
204+
'Automation', "Bug-Report"
205+
],
206+
headers: {
207+
'X-GitHub-Api-Version': '2022-11-28'
208+
}
209+
})
210+
return issue.url
168211
}

src/main/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export async function configStartup() {
6060
Logging: {
6161
ErrorWebhook: "",
6262
BotLogger: "",
63+
GitHubAPIToken: ""
6364
},
6465
BotType: "DISBOT",
6566
CONFIG_VERSION: botData.configVersion,

src/main/version.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
export const botData = {
2-
version: "1.6.2r2",
3-
configVersion: "1.2.0",
2+
version: "1.6.2r4",
3+
configVersion: "1.2.1",
44
};

0 commit comments

Comments
 (0)