Skip to content

Commit

Permalink
v0.15.18
Browse files Browse the repository at this point in the history
- Update Packages
- Added ability to enable or disable the reason for closing the ticket
  • Loading branch information
LucasB25 committed Jun 5, 2024
1 parent 4a8d162 commit 6721754
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 59 deletions.
26 changes: 15 additions & 11 deletions config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,31 @@
# Ticket Bot General Settings
# ==============================================

maxActiveTicketsPerUser: 1 # Maximum number of active tickets allowed per user
menuPlaceholder: 'Select a category to open a ticket.' # The placeholder text for the select menu
maxActiveTicketsPerUser: 1 # Maximum number of active tickets allowed per user
menuPlaceholder: 'Select a category to open a ticket.' # Placeholder text for the select menu

# Roles with access to ticket channels
supportRoles:
- '111111111111111111' # Support role ID 1
- '111111111111111111' # Support role ID 2
closeTicketStaffOnly: true # Allow only staff members with specified roles to close tickets
- '111111111111111111' # Support role ID 1
- '111111111111111111' # Support role ID 2

logChannelId: '111111111111111111' # ID of the channel where ticket logs will be sent
transcriptLogsChannelId: '111111111111111111' # ID of the channel where ticket transcript logs will be sent
ticketCategoryId: '111111111111111111' # ID of the category under which ticket channels will be created
enableTranscripts: true # Enable or disable the creation and sending of ticket transcripts
enableClaimButton: true # Enable or disable the claim button for tickets
closeTicketStaffOnly: false # Allow only staff members with specified roles to close tickets

logChannelId: '111111111111111111' # ID of the channel where ticket logs will be sent
transcriptLogsChannelId: '111111111111111111' # ID of the channel where ticket transcript logs will be sent
ticketCategoryId: '111111111111111111' # ID of the category under which ticket channels will be created
enableTranscripts: true # Enable or disable the creation and sending of ticket transcripts
enableClaimButton: true # Enable or disable the claim button for tickets
enableTicketReason: true # Enable or disable the requirement for a reason when closing tickets

# ================================
# Ticket Category Settings
# ================================
# Define different categories of tickets here.
# Each category should have a unique identifier.
# The Discord limit is 25, but it's not advisable to use that many types, as each type consumes 2 categories, and Discord's maximum is 50. Using too many types could exhaust your category options for regular Discord channels...
# Note: The Discord limit is 25 select menu options, but it's not advisable to use that many.
# Each type consumes 2 categories, and Discord's maximum is 50.
# Using too many types could exhaust your category options for regular Discord channels.

ticketCategories:
# Category 1
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "AikouTicket",
"version": "0.15.16",
"version": "0.15.18",
"description": "A simple AikouTicket bot for discord",
"type": "module",
"main": "dist/index.js",
Expand Down Expand Up @@ -29,15 +29,15 @@
},
"homepage": "https://github.com/LucasB25/AikouTicket#readme",
"devDependencies": {
"@biomejs/biome": "^1.7.3",
"@types/node": "^20.14.1",
"@biomejs/biome": "^1.8.0",
"@types/node": "^20.14.2",
"@types/signale": "^1.4.7",
"@typescript-eslint/eslint-plugin": "^7.12.0",
"@typescript-eslint/parser": "^7.12.0",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-unicorn": "^53.0.0",
"prisma": "^5.14.0",
"prisma": "^5.15.0",
"ts-node": "^10.9.2"
},
"keywords": [
Expand All @@ -59,7 +59,7 @@
"underlineLabel": true
},
"dependencies": {
"@prisma/client": "^5.14.0",
"@prisma/client": "^5.15.0",
"discord-html-transcripts": "^3.2.0",
"discord.js": "^14.15.3",
"dotenv": "^16.4.5",
Expand Down
79 changes: 51 additions & 28 deletions src/events/client/InteractionCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,49 +248,72 @@ export default class InteractionCreate extends Event {
}

private async handleConfirmCloseTicketButton(interaction: any): Promise<void> {
const config = await TicketManager.readConfigFile();
const channel = interaction.channel as TextChannel;
const categoryLabelMatch = channel.topic?.match(/Ticket Type: (.+)/);
const categoryLabel = categoryLabelMatch ? categoryLabelMatch[1] : 'unknown';

const embed = new EmbedBuilder()
.setColor(this.client.color)
.setDescription('Please provide a reason for closing the ticket within 1 minute.');
if (config.enableTicketReason) {
const embed = new EmbedBuilder()
.setColor(this.client.color)
.setDescription('Please provide a reason for closing the ticket within 1 minute.');

await interaction.reply({
embeds: [embed],
ephemeral: true,
});
await interaction.reply({
embeds: [embed],
ephemeral: true,
});

let shouldCloseTicket = false;
let reason = '';
let shouldCloseTicket = false;
let reason = '';

const collector = channel.createMessageCollector({
filter: (msg) => msg.author.id === interaction.user.id,
time: 60000,
max: 1,
});
const collector = channel.createMessageCollector({
filter: (msg) => msg.author.id === interaction.user.id,
time: 60000,
max: 1,
});

collector.on('collect', async (message) => {
shouldCloseTicket = true;
reason = message.content;
await LogsManager.logTicketDeletion(interaction, this.client, interaction.user.username, categoryLabel, channel, reason);
});
collector.on('collect', async (message) => {
shouldCloseTicket = true;
reason = message.content;
await LogsManager.logTicketDeletion(interaction, this.client, interaction.user.username, categoryLabel, channel, reason);
});

collector.on('end', async () => {
if (!shouldCloseTicket) {
const embed = new EmbedBuilder()
.setColor(this.client.color)
.setDescription('Failed to close the ticket. Reason not provided within 1 minute.');

await interaction.followUp({ embeds: [embed], ephemeral: true });
return;
}

collector.on('end', async () => {
if (!shouldCloseTicket) {
const embed = new EmbedBuilder()
const announcementEmbed = new EmbedBuilder()
.setColor(this.client.color)
.setDescription('Failed to close the ticket. Reason not provided within 1 minute.');
.setDescription('This ticket will be closed in 10 seconds.');

await interaction.followUp({ embeds: [embed], ephemeral: true });
return;
}
await interaction.followUp({ embeds: [announcementEmbed], ephemeral: true });

setTimeout(async () => {
try {
await channel.delete(`Ticket closed by user with reason: ${reason}`);
} catch (error) {
this.client.logger.error('Failed to delete channel:', error);
}
}, 10000);
});
} else {
const reason = 'No reason provided';
await LogsManager.logTicketDeletion(interaction, this.client, interaction.user.username, categoryLabel, channel, reason);

const announcementEmbed = new EmbedBuilder()
.setColor(this.client.color)
.setDescription('This ticket will be closed in 10 seconds.');

await interaction.followUp({ embeds: [announcementEmbed], ephemeral: true });
await interaction.reply({
embeds: [announcementEmbed],
ephemeral: true,
});

setTimeout(async () => {
try {
Expand All @@ -299,7 +322,7 @@ export default class InteractionCreate extends Event {
this.client.logger.error('Failed to delete channel:', error);
}
}, 10000);
});
}
}

private async handleTranscriptTicketButton(interaction: any): Promise<void> {
Expand Down
23 changes: 8 additions & 15 deletions src/utils/LogsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Config {
logChannelId: Snowflake;
enableTranscripts: boolean;
transcriptLogsChannelId: Snowflake;
enableTicketReason: boolean;
}

export class LogsManager {
Expand All @@ -31,8 +32,7 @@ export class LogsManager {
interaction.user.username,
'#2FF200',
'🎟️ Ticket Created',
`- **Ticket Creator:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${
ticketChannel.name
`- **Ticket Creator:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${ticketChannel.name
} - ID: ${ticketChannel.id}) \n\n- **Category:** \n> ${categoryLabel}`,
);
await logChannel.send({ embeds: [embed] });
Expand All @@ -52,17 +52,11 @@ export class LogsManager {
try {
const config = await LogsManager.readConfigFile();
const logChannel = await LogsManager.getLogChannel(client);
const embed = LogsManager.createLogEmbed(
interaction,
userName,
'#FF2400',
'⛔ Ticket Closed',
`- **Closed By:** \n> ${interaction.user.username}\n\n- **Ticket Creator:** \n> ${
interaction.user.username
}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${ticketChannel.name} - ID: ${
ticketChannel.id
}) \n\n- **Category:** \n> ${categoryLabel}\n\n- **Reason:** \n> ${reason}`,
);
const description = config.enableTicketReason
? `- **Closed By:** \n> ${interaction.user.username}\n\n- **Ticket Creator:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${ticketChannel.name} - ID: ${ticketChannel.id}) \n\n- **Category:** \n> ${categoryLabel}\n\n- **Reason:** \n> ${reason}`
: `- **Closed By:** \n> ${interaction.user.username}\n\n- **Ticket Creator:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${ticketChannel.name} - ID: ${ticketChannel.id}) \n\n- **Category:** \n> ${categoryLabel}`;

const embed = LogsManager.createLogEmbed(interaction, userName, '#FF2400', '⛔ Ticket Closed', description);

if (config.enableTranscripts) {
await LogsManager.sendTranscript(logChannel, embed, ticketChannel as TextChannel, client);
Expand All @@ -88,8 +82,7 @@ export class LogsManager {
userName,
'#3498DB',
'📝 Transcript Generated',
`- **Transcript Generated By:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${
ticketChannel.name
`- **Transcript Generated By:** \n> ${interaction.user.username}\n\n- **Ticket:** \n> ${ticketChannel.toString()} \n> (${ticketChannel.name
} - ID: ${ticketChannel.id})`,
);

Expand Down
1 change: 1 addition & 0 deletions src/utils/TicketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface Config {
menuPlaceholder: string;
enableClaimButton: boolean;
closeTicketStaffOnly: boolean;
enableTicketReason: boolean;
ticketCategories: {
[key: string]: {
menuLabel: string;
Expand Down

0 comments on commit 6721754

Please sign in to comment.