mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 14:06:59 +01:00
add monthly and alltime stat commands
This commit is contained in:
45
src/lib/getStats.ts
Normal file
45
src/lib/getStats.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { getTimeoutsAsTarget, getTimeoutsAsUser } from "db/dbTimeouts";
|
||||
import { getItemsUsed } from "db/dbUsedItems";
|
||||
import type { inventory } from "items";
|
||||
import type User from "user";
|
||||
|
||||
export async function getTimeoutStats(target: User, thismonth: boolean) {
|
||||
const monthdata = thismonth ? new Date().toISOString().slice(0, 7) : undefined;
|
||||
|
||||
const [shot, hit] = await Promise.all([
|
||||
getTimeoutsAsUser(target, monthdata),
|
||||
getTimeoutsAsTarget(target, monthdata)
|
||||
]);
|
||||
|
||||
if (!shot || !hit) return;
|
||||
|
||||
const blasterhit = hit.filter(item => item.item !== 'silverbullet').length;
|
||||
const silverbullethit = hit.length - blasterhit;
|
||||
const blastershot = shot.filter(item => item.item !== 'silverbullet').length;
|
||||
const silverbulletshot = shot.length - blastershot;
|
||||
|
||||
return {
|
||||
hit: {
|
||||
blaster: blasterhit,
|
||||
silverbullet: silverbullethit
|
||||
},
|
||||
shot: {
|
||||
blaster: blastershot,
|
||||
silverbullet: silverbulletshot
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export async function getItemStats(target: User, thismonth: boolean) {
|
||||
const monthdata = thismonth ? new Date().toISOString().slice(0, 7) : undefined;
|
||||
|
||||
const data = await getItemsUsed(target, monthdata);
|
||||
if (!data) return;
|
||||
|
||||
const returnObj: inventory = {
|
||||
grenade: data.filter(use => use.item === 'grenade').length,
|
||||
tnt: data.filter(use => use.item === 'tnt').length
|
||||
};
|
||||
|
||||
return returnObj;
|
||||
};
|
||||
Reference in New Issue
Block a user