mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 09:26:58 +01:00
add economy command (so darkxoa for idea), streamer silverbullet doesn't get stored, minor blaster and silverbullet fixes
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user