add economy command (so darkxoa for idea), streamer silverbullet doesn't get stored, minor blaster and silverbullet fixes

This commit is contained in:
2025-12-27 00:56:35 +01:00
parent 5a17e405fa
commit aa757a563d
6 changed files with 61 additions and 11 deletions

View File

@@ -12,7 +12,8 @@ import {
type SQL,
sql,
} from "drizzle-orm";
import { itemarray } from "items";
import { itemarray, type items } from "items";
import { ANIVNAMES } from "lib/handleAnivMessage";
import type User from "user";
/** Use this function to both ensure existance and to retreive data */
@@ -120,3 +121,25 @@ export async function getKDLeaderboard(monthData?: string) {
return result;
}
type ItemCounts = Record<items, number>;
export async function getTotalItemCounts(): Promise<ItemCounts> {
const allUsers = await db
.select({ username: users.username, inventory: users.inventory })
.from(users);
const filteredUsers = allUsers.filter(
(user) =>
!Array.from<string>(ANIVNAMES).includes(user.username.toLowerCase()),
);
const counts = itemarray.reduce((acc, item) => {
acc[item] = filteredUsers.reduce((sum, user) => {
return sum + (user.inventory[item] || 0);
}, 0);
return acc;
}, {} as ItemCounts);
return counts;
}