-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add Ratings ticket - Add new cmd ticketstats
- Loading branch information
Showing
9 changed files
with
169 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { type Bot, Command, type Context } from "../../structures/index.js"; | ||
import { EmbedBuilder } from "discord.js"; | ||
|
||
export default class TicketStats extends Command { | ||
constructor(client: Bot) { | ||
super(client, { | ||
name: "ticketstats", | ||
nameLocalizations: { | ||
fr: "statistiquestickets", | ||
}, | ||
description: { | ||
content: "Get the current ticket statistics", | ||
usage: "ticketstats", | ||
examples: ["ticketstats"], | ||
}, | ||
descriptionLocalizations: { | ||
fr: "Obtenez les statistiques actuelles des tickets.", | ||
}, | ||
category: "general", | ||
permissions: { | ||
dev: false, | ||
client: ["SendMessages", "ViewChannel", "EmbedLinks"], | ||
user: ["ManageGuild"], | ||
}, | ||
cooldown: 3, | ||
options: [], | ||
}); | ||
} | ||
|
||
async run(_client: Bot, ctx: Context): Promise<void> { | ||
try { | ||
const allTicketStats = await this.client.db.getAllTicketStats(); | ||
|
||
if (allTicketStats.length === 0) { | ||
await ctx.sendMessage({ content: "No ticket statistics available." }); | ||
return; | ||
} | ||
|
||
const totalRatings = allTicketStats.reduce((sum, stat) => sum + stat.rating, 0); | ||
const averageRating = totalRatings / allTicketStats.length; | ||
|
||
const embed = new EmbedBuilder() | ||
.setTitle("Ticket Statistics") | ||
.setColor("#FFD700") | ||
.addFields( | ||
{ name: "Total Tickets", value: `${allTicketStats.length}`, inline: true }, | ||
{ name: "Total Ratings", value: `${totalRatings}`, inline: true }, | ||
{ name: "Average Rating", value: `${averageRating.toFixed(2)}`, inline: true }, | ||
) | ||
.setTimestamp(); | ||
|
||
await ctx.sendMessage({ embeds: [embed] }); | ||
} catch (error) { | ||
this.client.logger.error(`Failed to retrieve ticket statistics: ${error.message}`); | ||
await ctx.sendMessage({ content: "There was an error retrieving the ticket statistics." }); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters