From d631f7141250e7fadb08f6a8b077dc7ca899b18a Mon Sep 17 00:00:00 2001 From: jgaribsin <16392336+jgaribsin@users.noreply.github.com> Date: Sat, 9 Mar 2024 18:01:38 -0700 Subject: [PATCH] #patch adding `/campaign most` command --- src/api-wrapper/campaign.ts | 9 +++++++++ src/commands/campaign.ts | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/api-wrapper/campaign.ts b/src/api-wrapper/campaign.ts index a3104ef..b55e746 100644 --- a/src/api-wrapper/campaign.ts +++ b/src/api-wrapper/campaign.ts @@ -5,6 +5,15 @@ export function getAllCampaigns(war_id?: number) { return data[warId].Campaigns; } +export function getPopularCampaign() { + // get campaign with the most players + const warId = seasons.current; + const popularCampaign = data[warId].Campaigns.reduce((a, b) => + a.planetData.players > b.planetData.players ? a : b + ); + return popularCampaign; +} + export function getCampaignByPlanetName(planetName: string, war_id?: number) { const warId = war_id || seasons.current; const campaign = data[warId].Campaigns.find( diff --git a/src/commands/campaign.ts b/src/commands/campaign.ts index 7c73117..73fa871 100644 --- a/src/commands/campaign.ts +++ b/src/commands/campaign.ts @@ -5,6 +5,7 @@ import { } from 'discord.js'; import {Command} from '../interfaces'; import {campaignEmbeds} from '../handlers'; +import {getPopularCampaign} from '../api-wrapper'; const command: Command = { data: new SlashCommandBuilder() @@ -15,6 +16,11 @@ const command: Command = { .setName('list') .setDescription('Display all ongoing Helldiver war efforts') ) + .addSubcommand(subcommand => + subcommand + .setName('most') + .setDescription('Display the campaign with the most active Helldivers') + ) .addSubcommand(subcommand => subcommand .setName('info') @@ -37,6 +43,7 @@ const command: Command = { const subcmds: {[key: string]: (job: CommandInteraction) => Promise} = { // hashmap of subcommands list, + most, info, }; @@ -54,4 +61,12 @@ async function info(interaction: CommandInteraction) { await interaction.editReply({embeds: embeds}); } +async function most(interaction: CommandInteraction) { + const campaign = getPopularCampaign(); + campaign.planetName; + const embeds: EmbedBuilder[] = await campaignEmbeds(campaign.planetName); + + await interaction.editReply({embeds: embeds}); +} + export default command;