parent
4827fdbf9f
commit
94f3589f3d
7 changed files with 190 additions and 99 deletions
@ -0,0 +1,11 @@ |
||||
import {Interaction, SlashCommandBuilder} from "discord.js"; |
||||
|
||||
export abstract class Command { |
||||
data: SlashCommandBuilder |
||||
|
||||
protected constructor(name: string, description: string) { |
||||
this.data = new SlashCommandBuilder().setName(name).setDescription(description); |
||||
} |
||||
|
||||
abstract execute(interaction: Interaction): Promise<void>; |
||||
} |
@ -0,0 +1,14 @@ |
||||
import {Interaction} from "discord.js"; |
||||
import {Command} from "../command"; |
||||
|
||||
class Ping extends Command { |
||||
constructor() { |
||||
super("ping", "One simple Ping Pong :)"); |
||||
} |
||||
async execute(interaction: Interaction) { |
||||
if (interaction.isRepliable()) |
||||
await interaction.reply("Pong!"); |
||||
} |
||||
} |
||||
|
||||
export default new Ping(); |
@ -0,0 +1,10 @@ |
||||
import {REST, Routes} from 'discord.js'; |
||||
require("dotenv").config(); |
||||
|
||||
let token = process.env["DISCORD_TOKEN"] as string; |
||||
let clientId = process.env["CLIENT_ID"] as string; |
||||
let guildId = process.env["GUILD_ID"] as string; |
||||
|
||||
const rest = new REST().setToken(token); |
||||
|
||||
rest.put(Routes.applicationGuildCommands(clientId, guildId), {body: [require("./commands/ping").data.toJSON()]}); |
@ -0,0 +1,88 @@ |
||||
import {PlatformId, RiotAPI, RiotAPITypes} from "@fightmegg/riot-api" |
||||
import AccountDTO = RiotAPITypes.Account.AccountDTO; |
||||
|
||||
const riotAPI = new RiotAPI(process.env["RIOT_API_KEY"] as string); |
||||
|
||||
export class Player { |
||||
|
||||
account: AccountDTO |
||||
startElo?: Elo |
||||
|
||||
constructor(account: AccountDTO) { |
||||
this.account = account; |
||||
} |
||||
|
||||
async fetchCurrentElo(): Promise<Elo | undefined> { |
||||
let entries = await riotAPI.league.getEntriesBySummonerId({ |
||||
region: PlatformId.EUW1, |
||||
summonerId: (await riotAPI.summoner.getByPUUID({ |
||||
region: PlatformId.EUW1, |
||||
puuid: this.account.puuid |
||||
})).id |
||||
}); |
||||
|
||||
let soloQ = entries.find(e => e.queueType == "RANKED_SOLO_5x5"); |
||||
if (soloQ && ((soloQ.wins + soloQ.losses) >= 5)){ |
||||
return { |
||||
tier: soloQ.tier, |
||||
rank: soloQ.rank, |
||||
points: soloQ.leaguePoints |
||||
}; |
||||
} |
||||
} |
||||
|
||||
toString() { |
||||
return `${this.account.gameName}#${this.account.tagLine}`; |
||||
} |
||||
|
||||
static async Create(gameName: string, tag: string) { |
||||
let account: AccountDTO; |
||||
try { |
||||
account = await riotAPI.account.getByRiotId({ |
||||
region: PlatformId.EUROPE, |
||||
gameName: gameName, |
||||
tagLine: tag |
||||
}); |
||||
} catch (error) { |
||||
console.error(`Riot ID not found: ${gameName}#${tag}!`); |
||||
return; |
||||
} |
||||
let p = new Player(account); |
||||
p.startElo = await p.fetchCurrentElo(); |
||||
return p; |
||||
} |
||||
} |
||||
|
||||
interface Elo { |
||||
tier: string, |
||||
rank: string, |
||||
points: number |
||||
} |
||||
|
||||
function eloToNumber(elo: Elo){ |
||||
let tiers: Record<string, number> = { |
||||
"CHALLENGER": 2800, |
||||
"GRANDMASTER": 2800, |
||||
"MASTER": 2800, |
||||
"DIAMOND": 2400, |
||||
"EMERALD": 2000, |
||||
"PLATINUM": 1600, |
||||
"GOLD": 1200, |
||||
"SILVER": 800, |
||||
"BRONZE": 400, |
||||
"IRON": 0, |
||||
}; |
||||
|
||||
let ranks: Record<string, number> = { |
||||
"I": 300, |
||||
"II": 200, |
||||
"III": 100, |
||||
"IV": 0, |
||||
}; |
||||
|
||||
let tier = elo.tier; |
||||
if (tier === "MASTER" || tier === "GRANDMASTER" || tier === "CHALLENGER") |
||||
return tiers[tier] + elo.points; |
||||
|
||||
return tiers[tier] + ranks[elo.rank] + elo.points; |
||||
} |
Loading…
Reference in new issue