Skip to content

Commit

Permalink
#patch updated /discord, disabled /community, now removes failed …
Browse files Browse the repository at this point in the history
…scheduled messages from db

- updated discord command and invites to use new support server and github
- updated kofi link to dedicated hellcom link
- added superstore rotation to API data db writes
- disabled community command in favour of a channel in the support server
- fixed an issue if there's more than 10 campaigns, `/campaign list` would fail
- on failing a message update or announcement, now removes that entry from the db so the error won't be repeated
  • Loading branch information
jgaribsin committed Apr 21, 2024
1 parent d852394 commit beb804d
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 60 deletions.
50 changes: 36 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/newrelic": "^9.14.3",
"@types/node": "^20.8.2",
"@types/node-cron": "^3.0.11",
"drizzle-kit": "^0.20.14",
"drizzle-kit": "^0.20.16",
"gts": "^5.2.0",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
Expand All @@ -46,4 +46,4 @@
"postgres": "^3.4.3",
"winston": "^3.12.0"
}
}
}
1 change: 1 addition & 0 deletions src/api-wrapper/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export type StrippedApiData = {
ActivePlanets: MergedPlanetData[];
PlanetAttacks: {source: string; target: string}[];
Events: GlobalEvent[];
SuperStore?: StoreRotation;
Players: {
[key in Faction]: number;
};
Expand Down
6 changes: 4 additions & 2 deletions src/commands/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ const subcmds: {[key: string]: (job: CommandInteraction) => Promise<void>} = {

async function list(interaction: CommandInteraction) {
const embeds: EmbedBuilder[] = await campaignEmbeds();

await interaction.editReply({embeds: embeds});
if (embeds.length > 10) {
await interaction.editReply({embeds: embeds.slice(0, 10)});
await interaction.followUp({embeds: embeds.slice(10), ephemeral: true});
} else await interaction.editReply({embeds: embeds});
}

async function info(interaction: CommandInteraction) {
Expand Down
29 changes: 16 additions & 13 deletions src/commands/discord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const {
KOFI_LINK,
TOP_GG_LINK,
BOT_OWNER,
GITHUB_LINK,
} = config;

const command: Command = {
Expand All @@ -26,35 +27,37 @@ const command: Command = {
name: 'Major (@theyodastream)',
iconURL: owner?.avatarURL?.() || undefined,
})
.setTitle('Leviathan Alliance - Helldivers 2 Community')
.setThumbnail(client.user?.avatarURL() || null)
.setTitle('HellCom Testing Grounds (Support Server)')
.setDescription(
`**Welcome to the [HellCom Testing Grounds!](${DISCORD_INVITE})** ` +
"Here you can discuss HellCom stuff, check the latest patches, suggest new features and report bugs. You're also welcome to just hang out and chat with fellow Helldivers about the game, no pressure! "
)
.setFields(
{
name: 'HellCom is part of Leviathan Alliance!',
value:
`**[Leviathan Alliance](${DISCORD_INVITE})** is a community of welcoming, like-minded Helldivers who are passionate about Helldivers 2! We also built this server knowing that the official Helldivers Discord can be hectic and overwhelming, so we hope you can find friendly Helldivers more easily here!` +
'\n\n' +
'HellCom has a dedicated section where you can see patchnotes for HellCom, report bugs, give suggestions or just chat about the bot. Patchnotes are posted in <#1218200640283611196> (if this says unknown, you need to join the server and get the HellCom role).',
},
{
name: 'Adding HellCom to your own Servers',
value:
'HellCom is free for anyone to add to their own servers! ' +
`You can add HellCom to your own server via the official **[Discord App Directory (click)](${DISCORD_APPLICATION_DIRECTORY})**.`,
value: `Anyone can add HellCom to their server via the official **[Discord App Directory (click)](${DISCORD_APPLICATION_DIRECTORY})**.`,
},
{
name: "Supporting HellCom's Development",
value:
'HellCom is a personal project, worked on in my spare time. ' +
`If you'd like to help cover hosting costs, or just support me in general, you can with my **[ko-fi link (click)](${KOFI_LINK})**.` +
`If you'd like to help cover hosting costs or just support me in general you can use my **[ko-fi link](${KOFI_LINK})**.` +
'\n' +
`Alternatively, you can support HellCom is via voting for and/or reviewing it on **[top.gg (click)](${TOP_GG_LINK})** so fellow Helldivers can find it more easily!`,
'Donating on ko-fi will grant you access to premium channels with the *highest priority for suggestions and support requests*!' +
'\n\n' +
`Alternatively, you can support HellCom is via voting for and/or reviewing it on **[top.gg](${TOP_GG_LINK})** and starring it on **[GitHub](${GITHUB_LINK})** so fellow Helldivers can find it more easily!`,
}
)
.setURL(DISCORD_INVITE)
.setFooter({text: FOOTER_MESSAGE})
.setColor(EMBED_COLOUR),
],
});
await interaction.followUp({
content: DISCORD_INVITE,
ephemeral: true,
});
},
};

Expand Down
2 changes: 1 addition & 1 deletion src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const commandList: Command[] = [
discord,
dispatches,
history,
community,
// community,
map,
// steam,
// wiki,
Expand Down
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const configObj: Record<string, string | number | undefined> = {
`/discord | v${version} | made by Major (@theyodastream)`,
DISCORD_APPLICATION_DIRECTORY:
'https://discord.com/application-directory/1213944670288347176',
DISCORD_INVITE: 'https://discord.gg/levialliance',
KOFI_LINK: 'https://ko-fi.com/theyodastream',
DISCORD_INVITE: 'https://discord.gg/kbhWz6mYfx',
KOFI_LINK: 'https://ko-fi.com/hellcombot',
TOP_GG_LINK: 'https://top.gg/bot/1213944670288347176',
GITHUB_LINK: 'https://github.com/helldivers-2/discord-bot',

// Project info
VERSION: version,
Expand Down
33 changes: 17 additions & 16 deletions src/handlers/cron/compareData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export async function compareData(): Promise<WarDifferences | void> {
ActivePlanets: data.ActivePlanets,
PlanetAttacks: data.PlanetAttacks,
Events: data.Events,
SuperStore: data.SuperStore,
Players: data.Players,
UTCOffset: data.UTCOffset,
};
Expand Down Expand Up @@ -121,74 +122,74 @@ export async function compareData(): Promise<WarDifferences | void> {
// TODO: compare major order
// check the list of old campaigns to see if it doesn't exist in the new data
// if not, then we either lost or won a planet
for (const campaign of oldData.Campaigns) {
const {planetName} = campaign;
for (const oldCampaign of oldData.Campaigns) {
const {planetName} = oldCampaign;
const newCampaign = newData.Campaigns.find(
c => c.planetName === planetName
);

if (!newCampaign) {
logger.info(`Campaign on ${planetName} has ended`, {type: 'info'});
const oldOwner = campaign.planetData.owner;
const oldOwner = oldCampaign.planetData.owner;
const newOwner = data.Planets.find(p => p.name === planetName)?.owner;

// if there is an old campaign, check if the owner has changed
// if both the old and new owner are humans, then we won a defence
if (oldOwner === 'Humans' && newOwner === 'Humans') {
differences.WonPlanets.push({
...campaign,
...oldCampaign,
});
logger.info(`Planet ${planetName} has been successfully defended`, {
type: 'info',
});
wonPlanetUpdate(campaign, channelIds);
wonPlanetUpdate(oldCampaign, channelIds);
}
// if it changed, then we either liberated something, or failed to defend
if (oldOwner !== newOwner) {
if (newOwner === 'Humans') {
// we won the campaign
// eg. helldivers have successfully liberated <planet>!
differences.WonPlanets.push({
...campaign,
...oldCampaign,
});
logger.info(`Planet ${planetName} has been successfully LIBERATED`, {
type: 'info',
});
wonPlanetUpdate(campaign, channelIds);
wonPlanetUpdate(oldCampaign, channelIds);
} else if (oldOwner === 'Humans') {
// we lost the campaign (probably a defend planet)
// eg. helldivers were not able to defend <planet>!
differences.LostPlanets.push({
...campaign,
...oldCampaign,
});
logger.info(`Planet ${planetName} DEFENCE has failed`, {
type: 'info',
});
lostPlanetUpdate(campaign, channelIds);
lostPlanetUpdate(oldCampaign, channelIds);
}
}
}
}
// compare old and new campaigns
for (const campaign of newData.Campaigns) {
const {planetName} = campaign;
for (const newCampaign of newData.Campaigns) {
const {planetName} = newCampaign;
const oldCampaign = oldData.Campaigns.find(
c => c.planetName === planetName
);
if (!oldCampaign) {
differences.NewCampaigns.push(campaign);
differences.NewCampaigns.push(newCampaign);
// if there isn't an old campaign, then this is a new campaign
logger.info(`New campaign on ${planetName}`, {type: 'info'});
newCampaignUpdate(campaign, channelIds);
newCampaignUpdate(newCampaign, channelIds);
}
// if old campaign was defend, and new is liberate, then we failed a defend mission
else if (
oldCampaign.campaignType === 'Defend' &&
campaign.campaignType === 'Liberation'
newCampaign.campaignType === 'Liberation'
) {
differences.LostPlanets.push(campaign);
differences.LostPlanets.push(newCampaign);
logger.info(`Planet ${planetName} DEFENCE has failed`, {type: 'info'});
lostDefenceUpdate(campaign, channelIds);
lostDefenceUpdate(oldCampaign, channelIds);
}
}
// compare news feeds
Expand Down
1 change: 1 addition & 0 deletions src/handlers/cron/dbData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export async function dbData() {
ActivePlanets: data.ActivePlanets,
PlanetAttacks: data.PlanetAttacks,
Events: data.Events,
SuperStore: data.SuperStore,
Players: data.Players,
UTCOffset: data.UTCOffset,
};
Expand Down
Loading

0 comments on commit beb804d

Please sign in to comment.