Skip to content

Commit

Permalink
Merge pull request #262 from Kathund/updateMayor
Browse files Browse the repository at this point in the history
Update !mayor
  • Loading branch information
Killermaschine88 authored Sep 5, 2024
2 parents 8020135 + d3e1efb commit bcc479c
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/minecraft/commands/mayorCommand.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const minecraftCommand = require("../../contracts/minecraftCommand.js");
const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const axios = require("axios");

class MayorCommand extends minecraftCommand {
Expand All @@ -21,19 +22,18 @@ class MayorCommand extends minecraftCommand {
throw "Request to Hypixel API failed. Please try again!";
}

if (data.current.candidates.length === 0) {
this.send(
`/gc [MAYOR] ${data.mayor.name} is the current mayor of Skyblock! Perks: ${data.mayor.perks
.map((perk) => perk.name)
.join(", ")}`,
);
} else {
const currentLeader = data.current.candidates.sort((a, b) => b.votes - a.votes)[0];
this.send(
`/gc [MAYOR] ${data.mayor.name} is the current mayor of Skyblock! Perks: ${data.mayor.perks
.map((perk) => perk.name)
.join(", ")} | Current Election: ${currentLeader.name}`,
);
this.send(
`/gc [MAYOR] ${data.mayor.name} is the current mayor of Skyblock! Perks: ${data.mayor.perks
.map((perk) => perk.name)
.join(", ")}, ${data.mayor.minister.perk[0].name}`,
);
await delay(500);
if (data.current.candidates.length > 0) {
const currentLeader = data.current.candidates.sort((a, b) => (b.votes || 0) - (a.votes || 0))[0];
if (!currentLeader) return;
const totalVotes = data.current.candidates.reduce((total, candidate) => total + (candidate.votes || 0), 0);
const percentage = ((currentLeader.votes || 0) / totalVotes) * 100;
this.send(`/gc [MAYOR] Current Election: ${currentLeader.name} has ${percentage.toFixed(2)}% of the votes.`);
}
} catch (error) {
this.send(`/gc [ERROR] ${error}`);
Expand Down

0 comments on commit bcc479c

Please sign in to comment.