Skip to content

Commit

Permalink
#patch adding /campaign most command
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaribsin committed Mar 10, 2024
1 parent 81d3d0d commit d631f71
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/api-wrapper/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions src/commands/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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')
Expand All @@ -37,6 +43,7 @@ const command: Command = {
const subcmds: {[key: string]: (job: CommandInteraction) => Promise<void>} = {
// hashmap of subcommands
list,
most,
info,
};

Expand All @@ -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;

0 comments on commit d631f71

Please sign in to comment.