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
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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)