Skip to content

Commit c654133

Browse files
author
xyzjesper
committed
Add part 2 of the Ticket System and fixes for DisBot Hosted
1 parent 291fa6b commit c654133

File tree

111 files changed

+4256
-3508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+4256
-3508
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636
"copyfiles": "^2.4.1",
3737
"cors": "^2.8.5",
3838
"discord-html-transcripts": "^3.2.0",
39-
"discord-hybrid-sharding": "^2.2.6",
40-
"discord-markdown": "^2.5.1",
41-
"discord-oauth2": "^2.12.1",
4239
"discord-welcome-card": "^4.9.3",
4340
"discord.js": "^14.21.0",
4441
"discordbotlist": "^1.1.1",

prisma/schema.prisma

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,41 +428,47 @@ model Tickets {
428428
TicketId String @unique
429429
CreatedAt DateTime
430430
ClosedAt DateTime?
431+
IsClosed Boolean @default(false)
431432
GuildId String
432433
ChannelType Int
433434
ChannelId String?
434435
ThreadId String?
435-
IsClaimed Boolean?
436-
IsArchived Boolean?
436+
LastMessageId String?
437+
IsClaimed Boolean @default(false)
438+
IsArchived Boolean? @default(false)
437439
ArchiveMessageId String?
438440
UserWhoHasClaimedId String?
439-
IsLooked Boolean?
441+
IsLocked Boolean?
440442
TicketOwnerId String
441443
AddedMemberIds String[]
442444
TranscriptChannelId String?
443445
TranscriptHTML String?
446+
TranscriptJSON String?
444447
TicketNotes String[]
445448
SendTranscriptToUser Boolean?
449+
IsAutoDone Boolean? @default(false)
446450
OldTicketCategoryId String?
447451
AutoCloseAction String[]
452+
CloseActionReason String?
448453
AutoReplyMessageTemplateId String?
449454
AutoAssignHandler String?
450455
TicketFeedbackChannelId String?
451456
WithTicketFeedback Boolean?
457+
TicketFeedback TicketFeedback?
452458
UserDMWhenCloseMessageTemplateId String?
453459
OnlyClaimMode Boolean?
454460
TicketSetupId String
455461
TicketSetup TicketSetups @relation(fields: [TicketSetupId], references: [CustomId])
456-
TicketFeedback TicketFeedback?
457462
}
458463

459464
model TicketFeedback {
460-
id String @id @default(auto()) @map("_id") @db.ObjectId
461-
TicketId String @unique
462-
Rating Int // 1–5
465+
id String @id @default(auto()) @map("_id") @db.ObjectId
466+
TicketId String @unique
467+
Rating Int? // 1–5
463468
Comment String?
464-
SubmittedAt DateTime @default(now())
465-
Ticket Tickets @relation(fields: [TicketId], references: [TicketId])
469+
Sent Boolean @default(false)
470+
SubmittedAt DateTime? @default(now())
471+
Ticket Tickets @relation(fields: [TicketId], references: [TicketId])
466472
}
467473

468474
model GuildFeatureToggles {

src/emojis/file.png

172 Bytes
Loading

src/emojis/star.png

589 Bytes
Loading
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export enum DisbotInteractionType {
1+
export enum DisBotInteractionType {
22
Command = "Command",
33
ContextMenu = "ContextMenu",
44
UserInstall = "UserInstall",

src/helper/InteractionHelper.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
PermissionResolvable,
88
PermissionsBitField
99
} from "discord.js";
10-
import {DisbotInteractionType} from "../enums/disbotInteractionType.js";
10+
import {DisBotInteractionType} from "../enums/disBotInteractionType.js";
1111
import {PermissionType} from "../enums/permissionType.js";
1212
import {convertToEmojiPng} from "./emojis.js";
1313
import {ExtendedClient} from "../types/client.js";
@@ -48,10 +48,10 @@ export class InteractionHelper {
4848
}
4949
}
5050

51-
public static async cooldownCheck(cooldown: number, interaction: Interaction, client: ExtendedClient, type: DisbotInteractionType) {
51+
public static async cooldownCheck(cooldown: number, interaction: Interaction, client: ExtendedClient, type: DisBotInteractionType) {
5252
const now = Date.now();
5353

54-
if (type == DisbotInteractionType.Command || type == DisbotInteractionType.SubCommand || type == DisbotInteractionType.SubCommandGroup) {
54+
if (type == DisBotInteractionType.Command || type == DisBotInteractionType.SubCommand || type == DisBotInteractionType.SubCommandGroup) {
5555
if (!interaction.isCommand()) return;
5656
const cooldownTime = cooldown ? cooldown : 3000;
5757
const cooldownKey = `${interaction.commandName}:${interaction.user.id}`;

src/helper/errorHelper.ts

Lines changed: 104 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
import * as Sentry from "@sentry/node";
22
import colors from "colors";
3-
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, MessageFlags, WebhookClient} from "discord.js";
3+
import {
4+
ActionRowBuilder,
5+
ButtonBuilder,
6+
ButtonStyle,
7+
ContainerBuilder, Interaction,
8+
MessageFlags, SectionBuilder, SeparatorBuilder, SeparatorSpacingSize,
9+
TextDisplayBuilder,
10+
WebhookClient
11+
} from "discord.js";
412
import {convertToEmojiPng} from "./emojis.js";
513
import {LoggingAction} from "../enums/loggingTypes.js";
614
import {Logger} from "../main/logger.js";
715
import {Config} from "../main/config.js";
816

917
colors.enable();
1018

11-
export async function errorHandler(interaction: any, client: any, error: Error) {
19+
export async function errorHandler(interaction: Interaction, client: any, error: Error) {
1220
Logger?.error({
1321
timestamp: new Date().toISOString(),
1422
level: "error",
@@ -25,18 +33,48 @@ export async function errorHandler(interaction: any, client: any, error: Error)
2533

2634

2735
await interaction.editReply({
28-
content: `## ${await convertToEmojiPng("error", client.user?.id)} An error occurred while processing your interaction.\n-# You can click the button below to report this issue to the developers.`,
2936
components: [
30-
new ActionRowBuilder<ButtonBuilder>().addComponents(
31-
new ButtonBuilder()
32-
.setCustomId("report-error")
33-
.setStyle(ButtonStyle.Danger)
34-
.setLabel("Report Error")
35-
.setEmoji("<:error:1366426689961459893>")
36-
),
37+
new ContainerBuilder()
38+
.addSectionComponents(
39+
new SectionBuilder()
40+
.addTextDisplayComponents(
41+
new TextDisplayBuilder()
42+
.setContent([
43+
`## ${await convertToEmojiPng("error", client.user?.id)} An error occurred while processing your interaction.`,
44+
`-# You can click the button below to report this issue to the developers.`
45+
].join("\n"))
46+
)
47+
.setButtonAccessory(new ButtonBuilder()
48+
.setCustomId("report-error")
49+
.setStyle(ButtonStyle.Danger)
50+
.setLabel("Report Error")
51+
.setEmoji("<:error:1366426689961459893>"))
52+
)
53+
.addSeparatorComponents(new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Large))
54+
.addSectionComponents(
55+
new SectionBuilder()
56+
.addTextDisplayComponents(
57+
new TextDisplayBuilder()
58+
.setContent([
59+
`> ### ${await convertToEmojiPng("info", client.user?.id)} What will happen if you do it.`,
60+
`> -# You will share you public user ID`,
61+
`> -# You will send an Error stack trace`,
62+
`> -# You will Interaction Related data`,
63+
`> -# \"Public Database Id's\" like uuids of you setup and or a not sensitive ID`,
64+
`> -# You will send a contact for the devs to contact you!`,
65+
].join("\n"))
66+
)
67+
.setButtonAccessory(new ButtonBuilder()
68+
.setStyle(ButtonStyle.Link)
69+
.setURL("https://doc.xyzhub.link/s/disbot/doc/troubleshooting-8PWsSMRNvH")
70+
.setLabel("Read More")
71+
.setEmoji("<:link:1321941111090057248>"))
72+
)
73+
74+
3775
],
38-
flags: MessageFlags.Ephemeral,
39-
});
76+
flags: MessageFlags.IsComponentsV2,
77+
})
4078

4179
const collector = interaction.channel?.createMessageComponentCollector({
4280
filter: (i: {
@@ -47,7 +85,7 @@ export async function errorHandler(interaction: any, client: any, error: Error)
4785
});
4886

4987
collector?.on("collect", async (i: { deferUpdate: () => any; }) => {
50-
await i.deferUpdate();
88+
await i.deferUpdate()
5189

5290
let interactionName = "Unknown";
5391
if (interaction.isCommand() || interaction.isContextMenuCommand()) {
@@ -66,47 +104,63 @@ export async function errorHandler(interaction: any, client: any, error: Error)
66104

67105
if (!client.user) throw new Error("Client user is not defined");
68106
await webHookClient.send({
69-
content: `-# <:error:1366430438444236911> **Bug Report Submitted**`,
70-
embeds: [
71-
{
72-
author: {
73-
name: `${interaction.user.tag} (${interaction.user.id})`,
74-
icon_url: interaction.user.displayAvatarURL(),
75-
},
76-
color: 0x2B2D31,
77-
description: [
78-
`<:error:1366430438444236911> **Error Report**`,
79-
`> **User:** ***\`${interaction.user.username}\`*** (\`${interaction.user.id}\`)`,
80-
`> **Error:** \`${error.name}\``,
81-
`> - \`${error.message}\``,
82-
`> **Interaction Type:** \`${interaction.type == 2 ? "Application Command" : interaction.type == 4 ? "ApplicationCommandAutocomplete" : interaction.type == 3 ? "Message Component" : interaction.type == 5 ? "Modal Submit" : interaction.type == 1 ? "Ping" : "Unknown"}\``,
83-
`> **Interaction Name/ID:** \`${interactionName}\``,
84-
].join("\n"),
85-
timestamp: new Date().toISOString(),
86-
},
87-
{
88-
author: {
89-
name: `${client.user.tag} (${client.user.id})`,
90-
icon_url: client.user.displayAvatarURL(),
91-
},
92-
color: 0x2B2D31,
93-
description: [
94-
`||\`\`\`ts\n${error.stack}\n\`\`\`||`,
95-
].join("\n"),
96-
timestamp: new Date().toISOString(),
97-
},
107+
withComponents: true,
108+
flags: MessageFlags.IsComponentsV2,
109+
components: [
110+
new ContainerBuilder()
111+
.addTextDisplayComponents(
112+
new TextDisplayBuilder()
113+
.setContent(
114+
[
115+
`<:error:1366430438444236911> **Error Report**`,
116+
`> **User:** ***\`${interaction.user.username}\`*** (\`${interaction.user.id}\`)`,
117+
`> **Error:** \`${error.name}\``,
118+
`> - \`${error.message}\``,
119+
`> **Interaction Id**: \`${interaction.id}\``,
120+
`> **Interaction Type:** \`${interaction.type == 2 ? "Application Command" : interaction.type == 3 ? "Message Component" : interaction.type == 5 ? "Modal Submit" : "Unknown"}\``,
121+
`> **Interaction Name/ID:** \`${interactionName}\``,
122+
`> **Timestamp**: <t:${Math.floor(new Date().getTime() / 1000)}:F>`
123+
].join("\n")
124+
)
125+
),
126+
new TextDisplayBuilder()
127+
.setContent([
128+
`||\`\`\`ts\n${error.stack}\n\`\`\`||`
129+
].join("\n"))
98130
],
99-
allowedMentions: {parse: []},
131+
allowedMentions: {
132+
parse: []
133+
},
100134
username: "DisBot Bug Reporter",
101-
avatarURL: client.user?.displayAvatarURL(),
102-
appliedTags: ["1366430372484878537", "1366430599811694622"],
103-
threadName: `Bug Report - ${interaction.user.tag} (${interaction.user.id}) - Interaction`,
104-
});
135+
avatarURL:
136+
client.user?.displayAvatarURL(),
137+
appliedTags:
138+
["1366430372484878537", "1366430599811694622"],
139+
threadName:
140+
`Bug Report - ${interaction.user.tag} (${interaction.user.id}) - Interaction`,
141+
})
142+
;
105143

106144
await interaction.editReply({
107-
content: `## ${await convertToEmojiPng("check", client.user?.id)} Your error report has been sent to the developers. Thank you for your help!`,
108-
components: [],
109-
embeds: [],
145+
components: [
146+
new ContainerBuilder()
147+
.addSectionComponents(
148+
new SectionBuilder()
149+
.addTextDisplayComponents(
150+
new TextDisplayBuilder()
151+
.setContent([
152+
`## ${await convertToEmojiPng("check", client.user?.id)} Successfully sent your Error Report to the Discord!`,
153+
].join("\n"))
154+
)
155+
.setButtonAccessory(new ButtonBuilder()
156+
.setStyle(ButtonStyle.Link)
157+
.setURL("https://disbot.app/discord")
158+
.setLabel("Join our Discord")
159+
.setEmoji("<:discord_cube:1325896195083604080>"))
160+
)
161+
162+
],
163+
flags: MessageFlags.IsComponentsV2,
110164
});
111165
});
112166
}

src/helper/pagination.ts

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ContainerBuilder, MessageFlags, StringSelectMenuBuilder, TextDisplayBuilder } from "discord.js";
2-
import { convertToEmojiPng } from "./emojis.js";
3-
import { PaginationData } from "../types/pagination.js";
1+
import {
2+
ActionRowBuilder, AnyComponentBuilder, AnySelectMenuInteraction,
3+
ButtonBuilder,
4+
ButtonStyle, ChannelSelectMenuBuilder,
5+
ContainerBuilder,
6+
MessageFlags, RoleSelectMenuBuilder,
7+
StringSelectMenuBuilder,
8+
TextDisplayBuilder, UserSelectMenuBuilder
9+
} from "discord.js";
10+
import {convertToEmojiPng} from "./emojis.js";
11+
import {PaginationData} from "../types/pagination.js";
412

513
export async function PaginationBuilder(data: PaginationData) {
614

@@ -9,10 +17,10 @@ export async function PaginationBuilder(data: PaginationData) {
917
const currentIndex = data.currentIndex || 0;
1018
const uuid = data.latestUUID
1119

12-
if (!data.paginationData.length) {
20+
if (data.paginationData.length <= 0) {
1321
if (!data.client.user) throw new Error("Client User is not defined");
1422
return data.interaction.reply({
15-
content: `## ${await convertToEmojiPng("error", data.client.user?.id)} No Button Found`,
23+
content: `## ${await convertToEmojiPng("error", data.client.user?.id)} No data for pagination found! Failed to Build Message`,
1624
flags: MessageFlags.Ephemeral
1725
});
1826
}
@@ -38,17 +46,33 @@ export async function PaginationBuilder(data: PaginationData) {
3846
selectMenu
3947
);
4048

49+
const container = new ContainerBuilder()
50+
51+
container
52+
.addTextDisplayComponents(message)
53+
container
54+
.addActionRowComponents(
55+
navigationRow
56+
)
57+
container
58+
.addActionRowComponents(
59+
selectMenuRow
60+
)
61+
if (data.extraComponents !== undefined) {
62+
container.addActionRowComponents(
63+
new ActionRowBuilder<ButtonBuilder | StringSelectMenuBuilder | UserSelectMenuBuilder | ChannelSelectMenuBuilder | RoleSelectMenuBuilder>().addComponents(
64+
data.extraComponents
65+
)
66+
)
67+
}
68+
4169
await data.interaction.reply({
4270
flags: MessageFlags.IsComponentsV2 | MessageFlags.Ephemeral,
43-
components: [
44-
new ContainerBuilder()
45-
.addTextDisplayComponents(message).addActionRowComponents(
46-
navigationRow
47-
).addActionRowComponents(selectMenuRow)]
71+
components: [container]
4872
});
4973
} catch (error) {
5074
console.error("Error:", error);
51-
data.interaction.reply({
75+
await data.interaction.reply({
5276
content:
5377
"## An error occurred while fetching the buttons. Please try again later",
5478
flags: MessageFlags.Ephemeral

0 commit comments

Comments
 (0)