diff options
Diffstat (limited to 'src/cleaners/skyblock/election.ts')
-rw-r--r-- | src/cleaners/skyblock/election.ts | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/cleaners/skyblock/election.ts b/src/cleaners/skyblock/election.ts new file mode 100644 index 0000000..78937ec --- /dev/null +++ b/src/cleaners/skyblock/election.ts @@ -0,0 +1,64 @@ + +const candidateColors = { + barry: 'e', + paul: '4', + aatrox: 'a', + foxy: '3', + cole: 'e', + marina: '5', + diaz: '5', + diana: '3', +} + +export interface MayorPerk { + name: string + description: string +} + +export interface Candidate { + name: string + perks: MayorPerk[] + votes: number + color: string | null +} + +export interface ElectionData { + last_updated: number + previous: { + year: number + winner: Candidate + candidates: Candidate[] + } + current: { + year: number + candidates: Candidate[] + } | null +} + +function cleanCandidate(data: any): Candidate { + return { + name: data.name, + perks: data.perks, + votes: data.votes, + color: candidateColors[data.name.toLowerCase()], + } +} + +export function cleanElectionResponse(data: any): ElectionData { + return { + last_updated: data.lastUpdated / 1000, + previous: { + year: data.mayor.election.year, + winner: cleanCandidate({ + name: data.mayor.name, + perks: data.mayor.perks, + votes: data.mayor.election.candidates.find(c => c.key === data.mayor.key).votes, + }), + candidates: data.mayor.election.candidates.map(cleanCandidate) + }, + current: data.current ? { + year: data.current.year, + candidates: data.current.candidates.map(cleanCandidate) + } : null + } +}
\ No newline at end of file |