refactor for reduced repetition

This commit is contained in:
2026-01-11 09:17:48 -05:00
parent 3753573574
commit 7727ecdce3
5 changed files with 336 additions and 280 deletions

View File

@@ -2,20 +2,20 @@ const { SlashCommandBuilder } = require('discord.js');
const torn = require('../../torn.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('calcpayout')
.setDescription('[WIP] Calculate war payout based on participation')
.addIntegerOption(option =>
option.setName('total')
.setDescription('Full war earnings total before cuts')),
async execute(interaction) {
data: new SlashCommandBuilder()
.setName('calcpayout')
.setDescription('[WIP] Calculate war payout based on participation')
.addIntegerOption(option =>
option.setName('total')
.setDescription('Full war earnings total before cuts')),
async execute(interaction) {
const total = interaction.options.getInteger('total');
const lastWarRaw = await torn.api('https://api.torn.com/v2/faction/rankedwars?offset=0&limit=1&sort=DESC');
const lastWarID = lastWarRaw.rankedwars[0].id
const lastWar = await torn.api(`https://api.torn.com/v2/faction/${lastWarID}/rankedwarreport?`);
const ourMembers = lastWar.rankedwarreport.factions.find(faction => faction.id === 53026).members; // TODO: dont hardcore faction ID
const lastWarRaw = await torn.faction.rankedWars({ offset: 0, limit: 1, sort: 'DESC' });
const lastWarID = lastWarRaw[0].id
const lastWar = await torn.faction.rankedWarReport(lastWarID);
const ourMembers = lastWar.factions.find(faction => faction.id === 53026).members; // TODO: dont hardcore faction ID
let totalParticipants = 0;
let message = `# War Payout Calculation for War against ${lastWar.rankedwarreport.factions.find(faction => faction.id !== 53026).name} with total earnings of $${total.toLocaleString()}:\n`;
let message = `# War Payout Calculation for War against ${lastWar.factions.find(faction => faction.id !== 53026).name} with total earnings of $${total.toLocaleString()}:\n`;
ourMembers.forEach(member => {
if (member.id == 2993713) {
console.log(`User ${member.name} is calculated separately.`);
@@ -32,5 +32,5 @@ module.exports = {
console.log(`there were ${totalParticipants} participants`);
console.log(message)
interaction.reply(message);
},
},
};