Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple game modes #294

Merged
merged 8 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions commands/barter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ const defaultFunction = {
),
async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const searchString = interaction.options.getString('name');

if (!searchString) {
Expand All @@ -33,12 +34,14 @@ const defaultFunction = {
});
}

const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});

const matchedBarters = [];

const [items, barters, traders] = await Promise.all([
gameData.items.getAll(locale),
gameData.barters.getAll(),
gameData.traders.getAll(locale)
gameData.items.getAll({lang, gameMode}),
gameData.barters.getAll({gameMode}),
gameData.traders.getAll({lang, gameMode})
]);
const searchedItems = items.filter(item => item.name.toLowerCase().includes(searchString.toLowerCase()));

Expand All @@ -54,10 +57,13 @@ const defaultFunction = {
}

if (matchedBarters.length === 0) {
const embed = new EmbedBuilder();
embed.setDescription(t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}));
embed.setFooter({text: gameModeLabel});
return interaction.editReply({
content: t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}),
embeds: [embed],
ephemeral: true,
});
}
Expand Down Expand Up @@ -135,10 +141,10 @@ const defaultFunction = {
}

totalCost += itemCost * req.count;
embed.addFields({name: reqName, value: itemCost.toLocaleString(locale) + "₽ x " + req.count, inline: true});
embed.addFields({name: reqName, value: itemCost.toLocaleString(lang) + "₽ x " + req.count, inline: true});
}

embed.addFields({name: t('Total'), value: totalCost.toLocaleString(locale) + "₽", inline: false});
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(lang) + "₽", inline: false});

embeds.push(embed);

Expand All @@ -162,14 +168,16 @@ const defaultFunction = {
const bitemname = `[${rewardItem.name}](${rewardItem.link}) (${trader.name} LL${barter.level})`;

if (bitemname.length + 2 + otheritems.length > 2048) {
ending.setFooter({text: `${matchedBarters.length-i} ${t('additional results not shown.')}`,});
ending.setFooter({text: `${matchedBarters.length-i} ${t('additional results not shown.')} | ${gameModeLabel}`,});
break;
}
otheritems += bitemname + "\n";
}
ending.setDescription(otheritems);

embeds.push(ending);
} else {
embeds[embeds.length-1].setFooter({text: gameModeLabel});
}

return interaction.editReply({ embeds: embeds });
Expand Down
12 changes: 6 additions & 6 deletions commands/boss.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);

// Get the boss name from the command interaction
const bossName = interaction.options.getString('boss');

const bosses = await gameData.bosses.getAll(locale);
const bosses = await gameData.bosses.getAll({lang});

// Fetch all current map/boss data
const maps = await gameData.maps.getAll(locale);
const maps = await gameData.maps.getAll({lang, gameMode});

// Fetch all items
const items = await gameData.items.getAll(locale);
const items = await gameData.items.getAll({lang, gameMode});

const tiers = await getTiers();
const tiers = await getTiers(gameMode);

// Construct the embed
const embed = new EmbedBuilder();
Expand Down
32 changes: 21 additions & 11 deletions commands/craft.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const searchString = interaction.options.getString('name');

if (!searchString) {
Expand All @@ -34,12 +34,15 @@ const defaultFunction = {
});
}

const commandT = getFixedT(lang, 'command');
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});

const matchedCrafts = [];

const [items, crafts, stations] = await Promise.all([
gameData.items.getAll(locale),
gameData.crafts.getAll(),
gameData.hideout.getAll(locale),
gameData.items.getAll({lang, gameMode}),
gameData.crafts.getAll({gameMode}),
gameData.hideout.getAll({lang, gameMode}),
]);

const searchedItems = items.filter(item => item.name.toLowerCase().includes(searchString.toLowerCase()));
Expand All @@ -56,8 +59,13 @@ const defaultFunction = {
}

if (matchedCrafts.length === 0) {
const embed = new EmbedBuilder();
embed.setDescription(t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}));
embed.setFooter({text: gameModeLabel});
return interaction.editReply({
content: t('Found no results for "{{searchString}}"', {searchString: searchString}),
embeds: [embed],
ephemeral: true,
});
}
Expand Down Expand Up @@ -128,7 +136,7 @@ const defaultFunction = {
}
if (isTool) {
toolCost += itemCost * req.count;
toolsEmbed.addFields({name: reqItem.name, value: itemCost.toLocaleString(locale) + "₽ x " + req.count, inline: true});
toolsEmbed.addFields({name: reqItem.name, value: itemCost.toLocaleString(lang) + "₽ x " + req.count, inline: true});
if(!toolsEmbed.thumbnail) {
toolsEmbed.setThumbnail(reqItem.iconLink);
}
Expand All @@ -143,13 +151,13 @@ const defaultFunction = {
}
totalCost += itemCost * quantity;
//totalCost += req.item.avg24hPrice * req.count;
embed.addFields({name: reqItem.name, value: itemCost.toLocaleString(locale) + '₽ x ' + quantity, inline: true});
embed.addFields({name: reqItem.name, value: itemCost.toLocaleString(lang) + '₽ x ' + quantity, inline: true});
}
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(locale) + '₽', inline: false});
embed.addFields({name: t('Total'), value: totalCost.toLocaleString(lang) + '₽', inline: false});

embeds.push(embed);
if (toolsEmbed.data.fields?.length > 0) {
toolsEmbed.addFields({name: t('Total'), value: toolCost.toLocaleString(locale) + '₽', inline: false});
toolsEmbed.addFields({name: t('Total'), value: toolCost.toLocaleString(lang) + '₽', inline: false});
embeds.push(toolsEmbed);
}

Expand All @@ -173,7 +181,7 @@ const defaultFunction = {
const bitemname = `[${rewardItem.name}](${rewardItem.link}) (${station.name} level ${craft.level})`;

if (bitemname.length + 4 + otheritems.length > 2048) {
ending.setFooter({text: `${matchedCrafts.length-i} ${t('additional results not shown.')}`,});
ending.setFooter({text: `${matchedCrafts.length-i} ${t('additional results not shown.')} | ${gameModeLabel}`,});

break;
}
Expand All @@ -182,6 +190,8 @@ const defaultFunction = {
ending.setDescription(otheritems);

embeds.push(ending);
} else {
embeds[embeds.length-1].setFooter({text: gameModeLabel});
}

return interaction.editReply({ embeds: embeds });
Expand Down
34 changes: 34 additions & 0 deletions commands/gamemode.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';

import { getFixedT, getCommandLocalizations, comT } from '../modules/translations.mjs';
import progress from '../modules/progress-shard.mjs';
import gameData from '../modules/game-data.mjs';

const defaultFunction = {
data: new SlashCommandBuilder()
.setName('gamemode')
.setDescription('Set the game mode (regular, PVE) for bot responses')
.setNameLocalizations(getCommandLocalizations('gamemode'))
.setDescriptionLocalizations(getCommandLocalizations('gamemode_desc'))
.addStringOption(option => option
.setName('gamemode')
.setDescription('Game mode to use')
.setNameLocalizations(getCommandLocalizations('gamemode'))
.setDescriptionLocalizations(getCommandLocalizations('gamemode_option_desc'))
.setRequired(true)
.setChoices(...gameData.gameModes.choices())
),
async execute(interaction) {
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const gameMode = interaction.options.getString('gamemode');
progress.setGameMode(interaction.user.id, gameMode);
const gameModeT = comT(`game_mode_${gameMode}`, {lng: locale});
return interaction.reply({
content: `✅ ${t('Game mode set to {{gameMode}}.', {gameMode: gameModeT})}`,
ephemeral: true
});
},
};

export default defaultFunction;
42 changes: 35 additions & 7 deletions commands/goons.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import got from 'got';
import moment from 'moment/min/moment-with-locales.js';

import gameData from '../modules/game-data.mjs';
import { getFixedT, getCommandLocalizations } from '../modules/translations.mjs';
Expand All @@ -22,20 +23,46 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply({ephemeral: true});
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const mapId = interaction.options.getString('map');

if (!mapId) {
const locationEmbed = new EmbedBuilder();
locationEmbed.setTitle('Coming soon(?)');
locationEmbed.setDescription('Once we start getting a sufficient number of reports, we will be able to provide location');
const [maps, bosses, reports] = await Promise.all([
gameData.maps.getAll({lang, gameMode}),
gameData.bosses.getAll({lang, gameMode}),
gameData.goonReports.get({gameMode})
]);
const reportsEmbed = new EmbedBuilder();
const goons = bosses.find(b => b.normalizedName === 'death-knight');
if (goons) {
reportsEmbed.setThumbnail(goons.imagePortraitLink);
}
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});
let embedTitle = t('No Recent Goons Reports');
let embedDescription = t('When users submit reports, they will appear here');
if (reports.length > 1) {
embedTitle = t('Latest Goon Reports');
embedDescription = `\`${reports.map(report => {
const map = maps.find(m => m.id === report.map.id);
if (!map) {
return false;
}
const reportDate = new Date(parseInt(report.timestamp));
moment.locale(lang);
return `${map.name}: ${moment(reportDate).fromNow()}`;
}).filter(Boolean).join('\n')}\``;
}
reportsEmbed.setTitle(embedTitle);
reportsEmbed.setDescription(embedDescription);
reportsEmbed.setFooter({ text: gameModeLabel});
return interaction.editReply({
embeds: [locationEmbed],
embeds: [reportsEmbed],
});
}

const mapData = await gameData.maps.getAll(locale);
const mapData = await gameData.maps.getAll(lang);
const selectedMap = mapData.find(m => m.id === mapId);

const confirm = new ButtonBuilder()
Expand Down Expand Up @@ -77,6 +104,7 @@ const defaultFunction = {
map: selectedMap.nameId,
timestamp: new Date().getTime(),
accountId: parseInt(interaction.user.id.slice(-10)),
gameMode: gameMode,
},
}).json();

Expand Down
14 changes: 9 additions & 5 deletions commands/map.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const t = getFixedT(locale);
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const t = getFixedT(lang);
const commandT = getFixedT(lang, 'command');
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});
const mapId = interaction.options.getString('map');

const [mapData, itemData] = await Promise.all([
gameData.maps.getAll(locale),
gameData.items.getAll(locale),
gameData.maps.getAll({lang, gameMode}),
gameData.items.getAll({lang, gameMode}),
]);
const embed = new EmbedBuilder();

Expand Down Expand Up @@ -113,7 +115,9 @@ const defaultFunction = {

// If the map was made by a contributor, give them credit
if (selectedMapData.source) {
embed.setFooter({ text: t('Map made by {{author}}', {author: selectedMapData.source})});
embed.setFooter({ text: `${t('Map made by {{author}}', {author: selectedMapData.source})} | ${gameModeLabel}`});
} else {
embed.setFooter({ text: gameModeLabel});
}

return interaction.editReply({
Expand Down
28 changes: 18 additions & 10 deletions commands/price.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ const defaultFunction = {

async execute(interaction) {
await interaction.deferReply();
const locale = await progress.getServerLanguage(interaction.guildId) || interaction.locale;
const { lang, gameMode } = await progress.getInteractionSettings(interaction);
const locale = lang;
const t = getFixedT(locale);
const commandT = getFixedT(lang, 'command');
const gameModeLabel = t(`Game mode: {{gameMode}}`, {gameMode: commandT(`game_mode_${gameMode}`)});
// Get the search string from the user invoked command
const searchString = interaction.options.getString('name');

const [ items, traders, stations, barters, crafts ] = await Promise.all([
gameData.items.getAll(locale),
gameData.traders.getAll(locale),
gameData.hideout.getAll(locale),
gameData.barters.getAll(),
gameData.crafts.getAll(),
gameData.items.getAll({lang, gameMode}),
gameData.traders.getAll({lang, gameMode}),
gameData.hideout.getAll({lang, gameMode}),
gameData.barters.getAll({ gameMode}),
gameData.crafts.getAll({ gameMode}),
]);
const matchedItems = items.filter(i => i.name.toLowerCase().includes(searchString.toLowerCase()));

if (matchedItems.length === 0) {
const embed = new EmbedBuilder();
embed.setDescription(t(`Found no results for "{{searchString}}"`, {
searchString: searchString
}));
embed.setFooter({text: gameModeLabel});
return interaction.editReply({
content: t('Found no results for "{{searchString}}"', {
searchString: searchString
}),
embeds: [embed],
ephemeral: true,
});
}
Expand Down Expand Up @@ -305,7 +311,7 @@ const defaultFunction = {
const itemname = `[${matchedItems[i].name}](${matchedItems[i].link})`;

if (itemname.length + 2 + otheritems.length > 2048) {
ending.setFooter({text: `${matchedItems.length-i} ${t('additional results not shown.')}`});
ending.setFooter({text: `${matchedItems.length-i} ${t('additional results not shown.')} | ${gameModeLabel}`});

break;
}
Expand All @@ -316,6 +322,8 @@ const defaultFunction = {
ending.setDescription(otheritems);

embeds.push(ending);
} else {
embeds[embeds.length-1].setFooter({text: gameModeLabel});
}

return interaction.editReply({ embeds: embeds });
Expand Down
Loading