parent
f244e85b27
commit
c221df5f02
5 changed files with 120 additions and 10 deletions
@ -0,0 +1,53 @@ |
||||
import {Interaction, EmbedBuilder, APIEmbedField, codeBlock} from "discord.js"; |
||||
import {Command} from "../command"; |
||||
import {UEMEloBot} from "../bot"; |
||||
import {eloToNumber, Player} from "../player"; |
||||
|
||||
class List extends Command { |
||||
constructor() { |
||||
super("list", "Spieler auflisten"); |
||||
} |
||||
async execute(interaction: Interaction) { |
||||
if (!interaction.isChatInputCommand()) |
||||
return; |
||||
|
||||
let players = (interaction.client as UEMEloBot).players; |
||||
const maxNameLength = players.reduce((max: number, next: Player) => Math.max(max, next.toString().length), 0); |
||||
const maxProgressDigits = players.reduce((max, next) => Math.max(max, Math.abs(next.getProgress()).toString().length), 0); |
||||
|
||||
// sort by progress, then current elo, descending
|
||||
players.sort((a, b) => { |
||||
const diff = b.getProgress() - a.getProgress(); |
||||
if (diff != 0) |
||||
return diff; |
||||
return eloToNumber(b.currentElo) - eloToNumber(a.currentElo); |
||||
}); |
||||
|
||||
let ranking = players.reduce((before, player, index) => { |
||||
const placement = `${index + 1})`.padStart(3, '0'); |
||||
const fill = "-".repeat(maxNameLength - `${player}`.length + 2); |
||||
const progress = Intl.NumberFormat(undefined, { |
||||
signDisplay: "always", |
||||
useGrouping: false, |
||||
}).format(player.getProgress()).padStart(maxProgressDigits + 1, " "); |
||||
return `${before}${placement} ${player} ${fill} ${progress} LP\n`; |
||||
}, ""); |
||||
ranking = ranking.trimEnd(); |
||||
|
||||
const baseURL = "https://raw.communitydragon.org/latest/plugins/rcp-fe-lol-shared-components/global/default/"; |
||||
const fileName = (players[0].currentElo?.tier.toLowerCase() ?? "unranked") + ".png"; |
||||
const iconURL = `${baseURL}${fileName}`; |
||||
|
||||
const embed = new EmbedBuilder() |
||||
.setTitle("UEM-Elo-Challenge Ranking") |
||||
.setFields([ |
||||
{name: "Leader:", value: players[0].toString()}, |
||||
{name: " ", value: codeBlock(ranking)} |
||||
]) |
||||
.setThumbnail(iconURL); |
||||
|
||||
await interaction.reply({embeds: [embed]}); |
||||
} |
||||
} |
||||
|
||||
export default new List(); |
@ -0,0 +1,30 @@ |
||||
import {Interaction, PermissionsBitField} from "discord.js"; |
||||
import {Command} from "../command"; |
||||
import {UEMEloBot} from "../bot"; |
||||
|
||||
class Remove extends Command { |
||||
constructor() { |
||||
super("remove", "Spieler entfernen"); |
||||
this.data.addStringOption(option => { |
||||
return option.setName("riot-id").setDescription("Riot ID: 'Name#Tag'").setRequired(true) |
||||
}).setDefaultMemberPermissions(PermissionsBitField.Flags.Administrator); |
||||
} |
||||
|
||||
async execute(interaction: Interaction) { |
||||
if (!interaction.isChatInputCommand()) |
||||
return; |
||||
|
||||
let client = interaction.client as UEMEloBot; |
||||
|
||||
const riotId = interaction.options.getString("riot-id", true); |
||||
const [gameName, tagLine] = riotId.split("#"); |
||||
|
||||
const player = await client.removePlayer(gameName, tagLine); |
||||
if (player) |
||||
await interaction.reply({content: `${player} entfernt!`, ephemeral: true}); |
||||
else |
||||
await interaction.reply({content: "Fehler!", ephemeral: true}); |
||||
} |
||||
} |
||||
|
||||
export default new Remove(); |
Loading…
Reference in new issue