command for top armory donators

This commit is contained in:
2025-11-12 05:52:25 -05:00
parent e1cc136520
commit 8bff6d0485
3 changed files with 102 additions and 1 deletions

View File

@@ -0,0 +1,36 @@
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) {
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
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`;
ourMembers.forEach(member => {
if (member.id == 2993713) {
console.log(`User ${member.name} is calculated separately.`);
} else if (member.attacks > 0) {
console.log(`${member.name} participated with ${member.attacks} attacks.`);
totalParticipants++;
message += `- ${member.name}: Participated with a score of ${member.score} from ${member.attacks} attacks.\n`;
} else {
console.log(`${member.name} did not participate.`);
}
});
message += `## OseanWorld. earned $${total.toLocaleString()} with Yameii earning 10% off the top for a total of $${Math.ceil(total * 0.1).toLocaleString()}, leaving ${Math.floor(total * 0.9).toLocaleString()} for ${totalParticipants} participants.\n`;
message += `## Dividing that out gives each participant approximately $${Math.floor((total * 0.9) / totalParticipants).toLocaleString()} each.`;
console.log(`there were ${totalParticipants} participants`);
console.log(message)
interaction.reply(message);
},
};

View File

@@ -0,0 +1,64 @@
const { SlashCommandBuilder } = require('discord.js');
const torn = require('../../torn.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('donorboard')
.setDescription("See who's donated the most this week")
.addIntegerOption(option =>
option.setName('days')
.setDescription('Get results for a different amount of time')),
async execute(interaction) {
let days
if (!interaction.options.getInteger('days')) days = 7;
else days = interaction.options.getInteger('days');
const seconds = days * 24 * 60 * 60;
const time = new Date(new Date().getTime() - seconds * 1000);
let board = {};
await torn.faction.news("armoryDeposit", time.toISOString()).then(data => {
data.forEach(async news => {
const regex = /<a href = "http:\/\/www\.torn\.com\/profiles\.php\?XID=(\d+)">([^<]+)<\/a> deposited (\d+) x (.+)/;
const match = news.text.match(regex);
if (match) {
const id = match[1];
const name = match[2];
const count = parseInt(match[3]);
const itemName = match[4];
const item = (await torn.item.lookup(itemName));
if (!board[id]) {
board[id] = {
name: name,
totalValue: 0,
items: {}
}
}
if (!board[id].items[item.id]) {
board[id].items[item.id] = {
name: itemName,
count: 0,
value: item.value.market_price
}
}
board[id].items[item.id].count += count;
board[id].totalValue += item.value.market_price * count;
} else {
console.log("Unexpected news event: ", news.text);
}
});
});;
let message = `# Donor Board\n`;
const sortedBoard = Object.values(board).sort((a, b) => b.totalValue - a.totalValue);
for (const user of sortedBoard) {
console.log(user)
message += `## ${user.name}: $${user.totalValue.toLocaleString()}\n`;
for (const item in user.items) {
message += `- ${user.items[item].name}: ${user.items[item].count}\n`;
const totalItemValue = user.items[item].count * user.items[item].value;
message += ` - $${totalItemValue.toLocaleString()} (${user.items[item].value.toLocaleString()})\n`;
}
}
interaction.reply(message);
},
};