mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 11:06:59 +01:00
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { getCheerEvents } from "db/dbCheerEvents";
|
|
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 [items, cheers] = await Promise.all([
|
|
getItemsUsed(target, monthdata),
|
|
getCheerEvents(target, monthdata)
|
|
]);
|
|
if (!items || !cheers) return;
|
|
|
|
const returnObj: inventory = {
|
|
blaster: 0,
|
|
silverbullet: 0,
|
|
grenade: 0,
|
|
tnt: 0,
|
|
};
|
|
|
|
for (const item of items) {
|
|
if (!returnObj[item.item]) returnObj[item.item] = 0;
|
|
returnObj[item.item]! += 1;
|
|
};
|
|
|
|
for (const cheer of cheers) {
|
|
if (!returnObj[cheer.event]) returnObj[cheer.event] = 0;
|
|
returnObj[cheer.event]! += 1
|
|
};
|
|
|
|
return returnObj;
|
|
};
|