mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
monthly stats implemented
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
import timeout from "./timeout";
|
import timeout from "./timeout";
|
||||||
import inventory from "./inventory";
|
import inventory from "./inventory";
|
||||||
import stats from "./stats";
|
|
||||||
import qbucks from "./qbucks";
|
import qbucks from "./qbucks";
|
||||||
import getloot from "./getloot";
|
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 aliases from './itemAliases'
|
import stats from "./stats"
|
||||||
import admin from './admin'
|
import aliases from "./itemAliases"
|
||||||
|
import admin from "./admin"
|
||||||
|
|
||||||
export default [timeout, inventory, stats, qbucks, getloot, modme, use, iteminfo, ...aliases, ...admin]
|
export default [timeout, inventory, qbucks, getloot, modme, use, iteminfo, ...aliases, ...admin, ...stats]
|
||||||
|
|||||||
@@ -3,7 +3,36 @@ import api from "../lib/api";
|
|||||||
import { getStats } from "../lib/userHelper";
|
import { getStats } from "../lib/userHelper";
|
||||||
import { HelixUser } from "@twurple/api";
|
import { HelixUser } from "@twurple/api";
|
||||||
|
|
||||||
export default createBotCommand('stats', async (params, { say, userName }) => {
|
const stats = createBotCommand('stats', async (params, { say, userName }) => {
|
||||||
|
let user: HelixUser | null
|
||||||
|
if (params.length !== 0) {
|
||||||
|
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
||||||
|
} else user = await api.users.getUserByName(userName)
|
||||||
|
if (!user) {
|
||||||
|
await say(`User ${params[0]} not found`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const monthdata = new Date().toISOString().slice(0, 7)
|
||||||
|
|
||||||
|
const data = params.length === 0 ? { me: true, stats: await getStats(user!, monthdata) } : { me: false, stats: await getStats(user!, monthdata) }
|
||||||
|
|
||||||
|
const KD = data.stats.shot.blaster / data.stats.hit.blaster
|
||||||
|
|
||||||
|
await say(
|
||||||
|
`
|
||||||
|
THIS MONTH: Stats of ${data.me ? userName : params[0]}:
|
||||||
|
Users blasted: ${data.stats.shot.blaster},
|
||||||
|
Blasted by others: ${data.stats.hit.blaster} (${isNaN(KD) ? 0 : KD.toFixed(3)} K/D).
|
||||||
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
|
TNTs lit: ${data.stats.used.tnt},
|
||||||
|
Silver bullets fired: ${data.stats.shot.silverbullet},
|
||||||
|
Silver bullets taken: ${data.stats.hit.silverbullet}
|
||||||
|
`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const alltime = createBotCommand('alltime', async (params, { say, userName }) => {
|
||||||
let user: HelixUser | null
|
let user: HelixUser | null
|
||||||
if (params.length !== 0) {
|
if (params.length !== 0) {
|
||||||
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
user = await api.users.getUserByName(params[0].replace(/[@]/g, ''))
|
||||||
@@ -19,7 +48,7 @@ export default createBotCommand('stats', async (params, { say, userName }) => {
|
|||||||
|
|
||||||
await say(
|
await say(
|
||||||
`
|
`
|
||||||
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(3)} K/D).
|
||||||
Grenades lobbed: ${data.stats.used.grenade}
|
Grenades lobbed: ${data.stats.used.grenade}
|
||||||
@@ -29,3 +58,5 @@ export default createBotCommand('stats', async (params, { say, userName }) => {
|
|||||||
`
|
`
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export default [stats, alltime]
|
||||||
|
|||||||
@@ -62,9 +62,11 @@ interface timeoutsGetResult {
|
|||||||
|
|
||||||
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
const BLASTERS = ['blaster', 'grenade', 'tnt']
|
||||||
|
|
||||||
async function getTimeouts(userDBID: string): Promise<timeoutsGetResult> {
|
async function getTimeouts(userDBID: string, monthdata?: string): Promise<timeoutsGetResult> {
|
||||||
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"` })
|
let monthquery = ''
|
||||||
const shot = await pb.collection('timeouts').getFullList({ filter: `attacker="${userDBID}"` })
|
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
||||||
|
const hit = await pb.collection('timeouts').getFullList({ filter: `target="${userDBID}"${monthquery}` })
|
||||||
|
const shot = await pb.collection('timeouts').getFullList({ filter: `attacker="${userDBID}"${monthquery}` })
|
||||||
|
|
||||||
const blasterhit = hit.filter((item) => BLASTERS.includes(item.source)).length
|
const blasterhit = hit.filter((item) => BLASTERS.includes(item.source)).length
|
||||||
const silverbullethit = hit.length - blasterhit
|
const silverbullethit = hit.length - blasterhit
|
||||||
@@ -83,8 +85,10 @@ async function getTimeouts(userDBID: string): Promise<timeoutsGetResult> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getItemUses(userDBID: string): Promise<inventory> {
|
async function getItemUses(userDBID: string, monthdata?: string): Promise<inventory> {
|
||||||
const items = await pb.collection('itemuses').getFullList({ filter: `user="${userDBID}"` })
|
let monthquery = ''
|
||||||
|
if (monthdata) monthquery = ` && created~"${monthdata}"`
|
||||||
|
const items = await pb.collection('itemuses').getFullList({ filter: `user="${userDBID}"${monthquery}` })
|
||||||
return {
|
return {
|
||||||
version: 1,
|
version: 1,
|
||||||
blaster: items.filter((item) => item.name === 'blaster').length,
|
blaster: items.filter((item) => item.name === 'blaster').length,
|
||||||
@@ -118,11 +122,11 @@ interface statsGetResult extends timeoutsGetResult {
|
|||||||
used: inventory
|
used: inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getStats(user: HelixUser): Promise<statsGetResult> {
|
export async function getStats(user: HelixUser, monthdata?: string): Promise<statsGetResult> {
|
||||||
await DBValidation(user)
|
await DBValidation(user)
|
||||||
const userDBID = await getDBID(user)
|
const userDBID = await getDBID(user)
|
||||||
const { hit, shot } = await getTimeouts(userDBID)
|
const { hit, shot } = await getTimeouts(userDBID, monthdata)
|
||||||
const uses = await getItemUses(userDBID)
|
const uses = await getItemUses(userDBID, monthdata)
|
||||||
return { hit, shot, used: uses }
|
return { hit, shot, used: uses }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user