Skip to content

Commit

Permalink
Updated Awards Command Interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ichenglin committed Feb 25, 2023
1 parent 5048ef4 commit f54cddb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
10 changes: 6 additions & 4 deletions commands/command_awards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default class AwardsCommand extends VerificationCommand {
.setName("team")
.setDescription("The number of the team.")
.setMaxLength(8)
.setMinLength(2)
.setRequired(true)
);
return command_builder;
Expand Down Expand Up @@ -46,13 +47,14 @@ export default class AwardsCommand extends VerificationCommand {
if (!team_awards_sorted.has(award_data.award_name)) team_awards_sorted.set(award_data.award_name, []);
team_awards_sorted.get(award_data.award_name)?.push(award_data.award_event);
}

const awards_embed = new EmbedBuilder()
.setTitle(`🏅 ${team_data.team_name}'s Awards 🏅`)
.setDescription(`**${team_data.team_name} (${team_data.team_number})** had won a total of **${team_awards.length} awards**, below are the details of the awards and their events.`)
.setDescription(`**${team_data.team_name} (${team_data.team_number})** had won a total of **${team_awards.length} awards**, below are the details of the awards and their events.\n\u200B`)
.addFields(
{name: "\u200B", value: "\u200B"},
...Array.from(team_awards_sorted.entries()).map((award_data) => ({name: `🎖️ ${award_data[0]} x${award_data[1].length}`, value: `${"```"}${award_data[1].join("\n")}${"```"}`}))
)
...Array.from(team_awards_sorted.entries()).flatMap((award_data) => [
{name: `🎖️ ${award_data[0]} x${award_data[1].length} 🎖️`, value: award_data[1].map((event_data, event_index) => `▪️ \`${event_data}\``).join("\n")}
]))
.setColor("#84cc16");
await command_interaction.editReply({embeds: [awards_embed]});
}
Expand Down
11 changes: 10 additions & 1 deletion events/event_interaction_create.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseInteraction } from "discord.js";
import { BaseInteraction, ChatInputCommandInteraction, EmbedBuilder } from "discord.js";
import { verification_registry } from "..";
import Logger from "../objects/logger";
import VerificationEvent from "../templates/template_event";
Expand All @@ -13,10 +13,19 @@ export default class InteractionCreateEvent extends VerificationEvent {

public async event_trigger(interaction: BaseInteraction): Promise<void> {
try {
const time_event_begin = Date.now();
if (interaction.isChatInputCommand()) await verification_registry.command_trigger(interaction);
else if (interaction.isButton()) await verification_registry.button_trigger(interaction);
else if (interaction.isModalSubmit()) await verification_registry.modal_trigger(interaction);
Logger.send_log(`Event handling took ${Date.now() - time_event_begin} ms.`);
} catch (error) {
const interaction_element = (interaction as ChatInputCommandInteraction);
const failure_embed = new EmbedBuilder()
.setTitle("⚠️ Failure ⚠️")
.setDescription(`An error has occured while peforming the operation, please try again.`)
.setColor("#f97316");
if (interaction_element.deferred) await interaction_element.editReply({embeds: [failure_embed]});
else if (!interaction_element.replied) await interaction_element.reply({embeds: [failure_embed]});
Logger.send_log("An error has occured in event triggers.");
}
}
Expand Down
9 changes: 8 additions & 1 deletion objects/robotevent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ export default class RobotEvent {
public static async get_team_awards(team_id: number): Promise<TeamAward[]> {
const api_response = await fetch(`https://www.robotevents.com/api/v2/teams/${team_id}/awards`, {headers: this.get_authorization()}).then(response => response.json()) as any;
if (api_response.data.length <= 0) return [];
return api_response.data.map((award_data: any) => ({
const team_awards: any[] = api_response.data;
const api_response_continued = await Promise.all(new Array(api_response.meta.last_page - 1).fill(0).map((zero_lol, page_index) =>
fetch(`https://www.robotevents.com/api/v2/teams/${team_id}/awards?page=${api_response.meta.last_page - page_index}`, {headers: this.get_authorization()}).then(response => response.json())
));
for (let page_index = 0; page_index < (api_response.meta.last_page - 1); page_index++) {
team_awards.push(...api_response_continued[page_index].data);
}
return team_awards.map((award_data: any) => ({
award_id: award_data.id,
award_name: award_data.title.match(/^([^\(]+)\s\(/)[1],
award_event: award_data.event.name
Expand Down

0 comments on commit f54cddb

Please sign in to comment.