mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
add leaderboard command
This commit is contained in:
@@ -5,9 +5,10 @@ import getloot from "./getloot";
|
|||||||
import modme from "./modme";
|
import modme from "./modme";
|
||||||
import use from "./use";
|
import use from "./use";
|
||||||
import iteminfo from "./iteminfo"
|
import iteminfo from "./iteminfo"
|
||||||
|
import leaderboard from "./leaderboard"
|
||||||
|
|
||||||
import stats from "./stats"
|
import stats from "./stats"
|
||||||
import aliases from "./itemAliases"
|
import aliases from "./itemAliases"
|
||||||
import admin from "./admin"
|
import admin from "./admin"
|
||||||
|
|
||||||
export default [timeout, inventory, qbucks, getloot, modme, use, iteminfo, ...aliases, ...admin, ...stats]
|
export default [timeout, inventory, qbucks, getloot, modme, use, iteminfo, leaderboard, ...aliases, ...admin, ...stats]
|
||||||
|
|||||||
22
src/commands/leaderboard.ts
Normal file
22
src/commands/leaderboard.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { createBotCommand } from "@twurple/easy-bot"
|
||||||
|
import pb, { User } from "../lib/pocketbase"
|
||||||
|
import { getTimeouts } from "../lib/userHelper"
|
||||||
|
|
||||||
|
type KDData = { user: User, KD: number }
|
||||||
|
|
||||||
|
export default createBotCommand('leaderboard', async (_params, { say }) => {
|
||||||
|
const users = await pb.collection('users').getFullList()
|
||||||
|
let userKDs: KDData[] = []
|
||||||
|
for (const user of users) {
|
||||||
|
const data = await getTimeouts(user.id)
|
||||||
|
if (data.hit.blaster < 5) continue
|
||||||
|
const KD = data.shot.blaster / data.hit.blaster
|
||||||
|
const obj: KDData = { user, KD }
|
||||||
|
userKDs.push(obj)
|
||||||
|
}
|
||||||
|
if (userKDs.length === 0) { await say('No users on leaderboard yet!'); return }
|
||||||
|
userKDs.sort((data1, data2) => data2.KD - data1.KD)
|
||||||
|
const textlist: string[] = []
|
||||||
|
for (let i = 0; i < (userKDs.length < 5 ? userKDs.length : 5); i++) textlist.push(`${i + 1}. ${userKDs.at(i)!.user.firstname}: ${userKDs.at(i)!.KD.toFixed(2)}`)
|
||||||
|
await say(`${textlist.join(' | ')}`)
|
||||||
|
}, { aliases: ['kdleaderboard'] })
|
||||||
@@ -23,7 +23,7 @@ const stats = createBotCommand('stats', async (params, { say, userName }) => {
|
|||||||
`
|
`
|
||||||
THIS MONTH: Stats of ${data.me ? userName : params[0]}:
|
THIS MONTH: Stats of ${data.me ? userName : params[0]}:
|
||||||
Users blasted: ${data.stats.shot.blaster},
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(3)} K/D).
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(2)} K/D).
|
||||||
Grenades lobbed: ${data.stats.used.grenade}
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
TNTs lit: ${data.stats.used.tnt},
|
TNTs lit: ${data.stats.used.tnt},
|
||||||
Silver bullets fired: ${data.stats.shot.silverbullet},
|
Silver bullets fired: ${data.stats.shot.silverbullet},
|
||||||
@@ -50,7 +50,7 @@ const alltime = createBotCommand('alltime', async (params, { say, userName }) =>
|
|||||||
`
|
`
|
||||||
ALLTIME: Stats of ${data.me ? userName : params[0]}:
|
ALLTIME: Stats of ${data.me ? userName : params[0]}:
|
||||||
Users blasted: ${data.stats.shot.blaster},
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(3)} K/D).
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(2)} K/D).
|
||||||
Grenades lobbed: ${data.stats.used.grenade}
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
TNTs lit: ${data.stats.used.tnt},
|
TNTs lit: ${data.stats.used.tnt},
|
||||||
Silver bullets fired: ${data.stats.shot.silverbullet},
|
Silver bullets fired: ${data.stats.shot.silverbullet},
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ const BLASTERS = ['blaster', 'grenade', 'tnt']
|
|||||||
|
|
||||||
/** Get the amount of times the user has (been) shot (by) another user
|
/** Get the amount of times the user has (been) shot (by) another user
|
||||||
* The 'blaster' data is all timeouts excluding silver bullets */
|
* The 'blaster' data is all timeouts excluding silver bullets */
|
||||||
async function getTimeouts(userId: string, monthdata?: string): Promise<timeoutsGetResult> {
|
export async function getTimeouts(userId: string, monthdata?: string): Promise<timeoutsGetResult> {
|
||||||
let monthquery = ''
|
let monthquery = ''
|
||||||
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
||||||
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userId}"${monthquery}` })
|
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userId}"${monthquery}` })
|
||||||
|
|||||||
Reference in New Issue
Block a user