-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from CougarCS/tutor-tutorleaderboard-dev
Create tutor-leaderboard command
- Loading branch information
Showing
4 changed files
with
161 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { SlashCommandBuilder } from "discord.js"; | ||
import { Command } from "../../interfaces/Command"; | ||
import { createEmbed } from "../../utils/embeded"; | ||
import { getTutorLeaderboard } from "../../utils/supabase"; | ||
import { commandLog, sendError } from "../../utils/logs"; | ||
|
||
const buildEmbedBody = (bodyArray: string[]): string => { | ||
return bodyArray.join('\n'); | ||
}; | ||
|
||
export const tutorleaderboard: Command = { | ||
data: new SlashCommandBuilder() | ||
.setName("tutor-leaderboard") | ||
.setDescription("See the top tutor!") | ||
.addNumberOption((option) => | ||
option | ||
.setName("number") | ||
.setDescription("Number of leaderboard spaces you want to see!") | ||
.setMaxValue(20) | ||
.setMinValue(1) | ||
.setRequired(false) | ||
), | ||
run: async (interaction) => { | ||
await interaction.deferReply({ ephemeral: false }); | ||
const number = interaction.options.get("number", false); | ||
commandLog(interaction, "/tutor-leaderboard", "Green", [ | ||
{ | ||
name: "number", | ||
value: `${number}`, | ||
}, | ||
]); | ||
|
||
const errorTitle = "❌ Tutor Leaderboard Canceled!"; | ||
|
||
const maxSlots = (number?.value || 10) as number; | ||
const leaderboardResponse = await getTutorLeaderboard(maxSlots); | ||
|
||
if (leaderboardResponse.error) { | ||
await sendError(errorTitle, leaderboardResponse.message, interaction); | ||
return; | ||
} | ||
|
||
const leaderboardString = buildEmbedBody(leaderboardResponse.data); | ||
|
||
const returnMessage = createEmbed( | ||
"<:tutor:1151206705913417828> Tutor Leaderboard!", | ||
leaderboardString || "The leaderboard is empty!" | ||
).setColor("Green"); | ||
await interaction.editReply({ embeds: [returnMessage] }); | ||
return; | ||
}, | ||
}; |
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