Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.example.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"cantAccess": [], // The roles who can't access to this ticket type
"askQuestions": true, // If the bot should ask the reason of the ticket
"questions": [
// Maximum of 5 questions can be set due to discord's limit
{
"label": "What is the reason of the ticket?",
"placeholder": "Please enter the reason",
Expand Down
1 change: 1 addition & 0 deletions locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Byla zjištěna neplatná konfigurace. Požádejte operátora bota, aby problém vyřešil!",
"ticketOpenedMessage": "Ticket byl otevřen! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "Pouze admin půže vzít ticket",
"ticketAlreadyClaimed": "Ticket už je sebrán jiným adminem!",
Expand Down
1 change: 1 addition & 0 deletions locales/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Ungültige Konfiguration erkannt. Bitten Sie den Bot-Betreiber, das Problem zu beheben!",
"ticketOpenedMessage": "Ticket geöffnet! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "Das Ticket kann nur von Teammitgliedern beansprucht werden!",
"ticketAlreadyClaimed": "Dieses Ticket wurde schon beansprucht!",
Expand Down
1 change: 1 addition & 0 deletions locales/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Εντοπίστηκε μη έγκυρη διαμόρφωση, ζητήστε από τον χειριστή του bot να τη διορθώσει!",
"ticketOpenedMessage": "Το ticket άνοιξε! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "Το ticket μπορεί να διεκδικηθεί μόνο από προσωπικό!",
"ticketAlreadyClaimed": "Το ticket έχει ήδη διεκδικηθεί!",
Expand Down
1 change: 1 addition & 0 deletions locales/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Se detectó una configuración no válida, ¡pídale al operador del bot que la arregle!",
"ticketOpenedMessage": "¡Tique abierto! --> TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "¡El tique solo puede ser reclamado por un miembro del equipo!",
"ticketAlreadyClaimed": "¡Ya se reclamó el tique!",
Expand Down
1 change: 1 addition & 0 deletions locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Configuration non valide détectée, veuillez demander à l'opérateur du bot de la corriger!",
"ticketOpenedMessage": "Ticket ouvert! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "Seuls les membres du staff peuvent réclamer un ticket !",
"ticketAlreadyClaimed": "Le ticket est déjà reçu!",
Expand Down
1 change: 1 addition & 0 deletions locales/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Invalid configuration detected, please ask the bot operator to fix it!",
"ticketOpenedMessage": "Ticket opened! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "The ticket can only be claimed by a staff!",
"ticketAlreadyClaimed": "The ticket is already claimed!",
Expand Down
1 change: 1 addition & 0 deletions locales/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"emoji": "🙋"
}
},
"invalidConfig": "Geçersiz yapılandırma algılandı, lütfen bot operatöründen düzeltmesini isteyin!",
"ticketOpenedMessage": "Bir destek talebi başlatıldı! TICKETCHANNEL",
"ticketOnlyClaimableByStaff": "Destek talepleri sadece yetkililer tarafından alınabilir!",
"ticketAlreadyClaimed": "Bu destek talebi hali hazırda başka bir yetkili tarafından alındı!",
Expand Down
30 changes: 20 additions & 10 deletions src/events/interactionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ export default class InteractionCreateEvent extends BaseEvent {
if (interaction.customId === "openTicket") {
await interaction.deferReply({ ephemeral: true }).catch((e) => console.log(e));

// Max ticket opened
const tCount = this.client.config.ticketTypes.length;
if(tCount === 0 || tCount > 25) {
await interaction.followUp({content: this.client.locales.invalidConfig, ephemeral: true});
throw new Error("ticketTypes either has nothing or exceeded 25 entries. Please check the config and restart the bot");
}

for (const role of this.client.config.rolesWhoCanNotCreateTickets) {
if (role && (interaction.member as GuildMember | null)?.roles.cache.has(role)) {
Expand All @@ -60,7 +64,8 @@ export default class InteractionCreateEvent extends BaseEvent {
return;
}
}


// Max Ticket
if (this.client.config.maxTicketOpened > 0) {
const ticketsOpened = (await this.client.prisma.$queryRaw<[{count: bigint}]>
`SELECT COUNT(*) as count FROM tickets WHERE closedby IS NULL AND creator = ${interaction.user.id}`)[0].count;
Expand Down Expand Up @@ -163,19 +168,24 @@ export default class InteractionCreateEvent extends BaseEvent {
const ticketType = this.client.config.ticketTypes.find((x) => x.codeName === interaction.values[0]);
if (!ticketType) return console.error(`Ticket type ${interaction.values[0]} not found!`);
if (ticketType.askQuestions) {
const modal = new ModalBuilder().setCustomId("askReason").setTitle(this.client.locales.modals.reasonTicketOpen.title);
// Sanity Check
const qCount = ticketType.questions.length;
if(qCount === 0 || qCount > 5)
throw new Error(`${ticketType.codeName} has either no questions or exceeded 5 questions. Check your config and restart the bot`);

ticketType.questions.forEach((x, i) => {
const modal = new ModalBuilder().setCustomId("askReason").setTitle(this.client.locales.modals.reasonTicketOpen.title);
for (const question of ticketType.questions) {
const index = ticketType.questions.indexOf(question);
const input = new TextInputBuilder()
.setCustomId(`input_${interaction.values[0]}_${i}`)
.setLabel(x.label)
.setStyle(x.style == "SHORT" ? TextInputStyle.Short : TextInputStyle.Paragraph)
.setPlaceholder(x.placeholder)
.setMaxLength(x.maxLength);
.setCustomId(`input_${interaction.values[0]}_${index}`)
.setLabel(question.label)
.setStyle(question.style == "SHORT" ? TextInputStyle.Short : TextInputStyle.Paragraph)
.setPlaceholder(question.placeholder)
.setMaxLength(question.maxLength);

const firstActionRow = new ActionRowBuilder<TextInputBuilder>().addComponents(input);
modal.addComponents(firstActionRow);
});
}

await interaction.showModal(modal).catch((e) => console.log(e));
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/structure/BaseCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CommandInteraction, SlashCommandBuilder} from "discord.js";
import {CommandInteraction, InteractionResponse, SlashCommandBuilder} from "discord.js";
import {ExtendedClient} from "./";

export default abstract class BaseCommand {
Expand All @@ -7,7 +7,7 @@ export default abstract class BaseCommand {
protected constructor(client: ExtendedClient) {
this.client = client;
}

abstract execute(interaction: CommandInteraction): void;
// eslint-disable-next-line no-unused-vars
abstract execute(interaction: CommandInteraction): void | Promise<void | InteractionResponse<boolean>>;

}
3 changes: 2 additions & 1 deletion src/structure/BaseEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default abstract class BaseEvent {
this.client = client;
}

protected abstract execute(...args: ClientEvents[keyof ClientEvents]): void
// eslint-disable-next-line no-unused-vars
protected abstract execute(...args: ClientEvents[keyof ClientEvents]): void | Promise<void>;

}
1 change: 1 addition & 0 deletions src/structure/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export type LocaleType = {
emoji: string
}
},
invalidConfig: string;
ticketOpenedMessage: string,
ticketOnlyClaimableByStaff: string,
ticketAlreadyClaimed: string,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type log = {
ticketId?: string | number;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
// eslint-disable-next-line @typescript-eslint/no-unused-vars, no-unused-vars
export const log = async(logs: log, client: ExtendedClient) => {
if (!client.config.logs) return;
if (!client.config.logsChannelId) return;
Expand Down