mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 07:56: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:
22
src/commands/economy.ts
Normal file
22
src/commands/economy.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { getTotalItemCounts } from "db/dbUser";
|
||||
import itemAliasMap from "items";
|
||||
import { Command, sendMessage } from "lib/commandUtils";
|
||||
|
||||
export default new Command({
|
||||
name: "economy",
|
||||
aliases: ["economy", "eco"],
|
||||
usertype: "chatter",
|
||||
execution: async (msg) => {
|
||||
const allitems = await getTotalItemCounts();
|
||||
const itemList = Object.entries(allitems)
|
||||
.sort(([, a], [, b]) => b - a)
|
||||
.map(([item, count]) => {
|
||||
const itemobj = itemAliasMap.get(item);
|
||||
if (itemobj) return `${itemobj.prettyName}: ${count}`;
|
||||
return `${item}: ${count}`; // Fallback if an item doesn't have their name as an alias
|
||||
})
|
||||
.join(" | ");
|
||||
|
||||
await sendMessage(`Total Items in circulation: ${itemList}`, msg.messageId);
|
||||
},
|
||||
});
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export default new Item({
|
||||
}
|
||||
const target = await User.initUsername(messagequery[0].toLowerCase());
|
||||
if (!target) {
|
||||
await sendMessage(`${messagequery[0]} doesn't exist`);
|
||||
await sendMessage(`${messagequery[0]} doesn't exist`, msg.messageId);
|
||||
return;
|
||||
}
|
||||
await getUserRecord(target); // make sure the user record exist in the database
|
||||
|
||||
@@ -18,7 +18,7 @@ export default new Item({
|
||||
plural: "s",
|
||||
description: "Times targeted or random vulnerable user out for 30 minutes",
|
||||
aliases: ["execute", "silverbullet"],
|
||||
specialaliases: ["blastin"],
|
||||
specialaliases: ["blastin", "fuck"],
|
||||
price: 666,
|
||||
execution: async (msg, user, specialargs) => {
|
||||
const messagequery = parseCommandArgs(
|
||||
@@ -67,7 +67,7 @@ export default new Item({
|
||||
}
|
||||
if (!target) {
|
||||
await user.clearLock();
|
||||
await sendMessage(`${messagequery[0]} doesn't exist`);
|
||||
await sendMessage(`${messagequery[0]} doesn't exist`, msg.messageId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,21 +78,25 @@ export default new Item({
|
||||
`You got blasted by ${user.displayName}!`,
|
||||
60 * 30,
|
||||
);
|
||||
if (result.status)
|
||||
if (result.status) {
|
||||
await Promise.all([
|
||||
sendMessage(
|
||||
`KEKPOINT KEKPOINT KEKPOINT ${target.displayName.toUpperCase()} RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO RIPBOZO`,
|
||||
),
|
||||
changeItemCount(user, userObj, ITEMNAME),
|
||||
createTimeoutRecord(user, target, ITEMNAME),
|
||||
createUsedItemRecord(user, ITEMNAME),
|
||||
playAlert({
|
||||
name: "userExecution",
|
||||
user: user.displayName,
|
||||
target: target.displayName,
|
||||
}),
|
||||
]);
|
||||
else {
|
||||
if (user.id !== streamerId)
|
||||
// streamer doesn't consume bullets and doesn't count for timeouts
|
||||
await Promise.all([
|
||||
changeItemCount(user, userObj, ITEMNAME),
|
||||
createTimeoutRecord(user, target, ITEMNAME),
|
||||
createUsedItemRecord(user, ITEMNAME),
|
||||
]);
|
||||
} else {
|
||||
switch (result.reason) {
|
||||
case "banned":
|
||||
await sendMessage(
|
||||
|
||||
Reference in New Issue
Block a user