small refactor and small lootbox rebalance SMILERS

This commit is contained in:
2025-11-15 02:35:39 +01:00
parent a205daacb7
commit 977082f38e
89 changed files with 300 additions and 203 deletions

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { addAdmin } from "lib/admins";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import { streamerUsers } from "main";
import User from "user";

View File

@@ -1,5 +1,5 @@
import { Command, sendMessage } from "commands";
import { addInvuln } from "lib/invuln";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import { changeBalance } from "lib/changeBalance";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import items, { changeItemCount } from "items";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getKDLeaderboard } from "db/dbUser";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getTimeoutStats, getItemStats } from "lib/getStats";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getAnivTimeouts } from "db/dbAnivTimeouts";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,6 +1,6 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import User from "user";
import { redis } from "bun";
import { redis } from "lib/redis";
export default new Command({
name: 'backshot',

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import items from "items";
import { getUserRecord, updateUserRecord } from "db/dbUser";

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import { namedcheers } from "cheers";

View File

@@ -1,5 +1,6 @@
import { redis } from "bun";
import commands, { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import commands from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
export default new Command({

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import { disableRedeem, idMap, namedRedeems, sfxRedeems } from "pointRedeems";
import logger from "lib/logger";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import parseCommandArgs from "lib/parseCommandArgs";
import { changeBalance } from "lib/changeBalance";

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import { namedcheers } from "cheers";

View File

@@ -1,5 +1,6 @@
import { redis } from "bun";
import commands, { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import commands from "commands";
import parseCommandArgs from "lib/parseCommandArgs";
export default new Command({

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import logger from "lib/logger";
import parseCommandArgs from "lib/parseCommandArgs";
import { enableRedeem, idMap, namedRedeems, sfxRedeems } from "pointRedeems";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { timeout } from "lib/timeout";
export default new Command({

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getAdmins } from "lib/admins";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import { namedcheers } from "cheers";

View File

@@ -1,5 +1,6 @@
import { redis } from "bun";
import { basecommands, Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import { basecommands } from "commands";
import parseCommandArgs from "lib/parseCommandArgs";
export default new Command({

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getInvulns } from "lib/invuln";
import User from "user";

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord, updateUserRecord } from "db/dbUser";
import itemMap, { type inventory, type items } from "items";
import { buildTimeString } from "lib/dateManager";
@@ -57,7 +57,7 @@ export default new Command({
if (Math.floor(Math.random() * 5) === 0) itemDiff.grenade! += 1; // 1 in 5
if (Math.floor(Math.random() * 5) === 0) itemDiff.blaster! += 1; // 1 in 5
if (Math.floor(Math.random() * 50) === 0) itemDiff.tnt! += 1; // 1 in 50
if (Math.floor(Math.random() * 250) === 0) itemDiff.silverbullet! += 1; // 1 in 250
if (Math.floor(Math.random() * 50) === 0) itemDiff.silverbullet! += 1; // 1 in 50
};
for (const [item, amount] of Object.entries(itemDiff) as [items, number][]) {

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { itemObjectArray } from "items";
export default new Command({

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { buildTimeString } from "lib/dateManager";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getUserRecord } from "db/dbUser";
import items, { changeItemCount } from "items";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,39 +1,4 @@
import { EventSubChannelChatMessageEvent } from "@twurple/eventsub-base";
import User from "user";
export type userType = 'chatter' | 'admin' | 'streamer' | 'moderator';
export type specialExecuteArgs = {
activation?: string;
};
export type commandOptions = {
name: string;
aliases: string[];
usertype: userType;
execution: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => Promise<void>;
disableable?: boolean;
specialaliases?: string[];
};
/** The Command class represents a command */
export class Command {
public readonly name: string;
public readonly aliases: string[];
public readonly usertype: userType;
public readonly disableable: boolean;
public readonly specialaliases: string[];
public readonly execute: (message: EventSubChannelChatMessageEvent, sender: User, args?: specialExecuteArgs) => Promise<void>;
constructor(options: commandOptions) {
this.name = options.name.toLowerCase();
this.aliases = options.aliases;
this.usertype = options.usertype;
this.execute = options.execution;
this.disableable = options.disableable ?? true;
this.specialaliases = options.specialaliases ?? [];
};
};
import { Command } from 'lib/commandUtils';
import { readdir } from 'node:fs/promises';
const commands = new Map<string, Command>; // This map has all command/item aliases mapped to commands/items (many-to-one)
const specialAliasCommands = new Map<string, Command>; // This map has all special command/item aliases mapped to commands/items (just like commands map)
@@ -63,14 +28,3 @@ for (const [alias, item] of Array.from(specialAliasItems)) {
export default commands;
export { specialAliasCommands, basecommands };
import { chatterApi, chatterId, streamerId } from "main";
/** Helper function to send a message to the stream */
export const sendMessage = async (message: string, replyParentMessageId?: string) => {
try {
return await chatterApi.chat.sendChatMessageAsApp(chatterId, streamerId, message, { replyParentMessageId });
} catch (e) {
return await chatterApi.chat.sendChatMessageAsApp(chatterId, streamerId, message);
};
};

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import items from "items";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getKDLeaderboard } from "db/dbUser";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getTimeoutStats, getItemStats } from "lib/getStats";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { getBalanceLeaderboard } from "db/dbUser";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import logger from "lib/logger";
import { streamerId } from "main";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { streamerUsers } from "main";
import { removeAdmin } from "lib/admins";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,6 +1,6 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { streamerUsers } from "main";
import { redis } from "bun";
import { redis } from "lib/redis";
import parseCommandArgs from "lib/parseCommandArgs";
import User from "user";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { streamerUsers } from "main";
import { removeInvuln } from "lib/invuln";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,5 +1,5 @@
import { Command, sendMessage } from "commands";
import { redis } from "bun";
import { Command, sendMessage } from "lib/commandUtils";
import { redis } from "lib/redis";
import { timeout } from "lib/timeout";
const barrelCount = 6;

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { timeout } from "lib/timeout";
export default new Command({
@@ -8,7 +8,7 @@ export default new Command({
execution: async (msg, user) => {
const rand = Math.floor(Math.random() * 101);
if (rand > 75) await sendMessage(`${rand}% seiso YAAAA`, msg.messageId);
else if (rand > 51) await sendMessage(`${rand}% seiso POGGERS`, msg.messageId);
else if (rand > 50) await sendMessage(`${rand}% seiso POGGERS`, msg.messageId);
else if (rand === 50) await sendMessage(`${rand}% seiso ok`, msg.messageId);
else if (rand > 30) await sendMessage(`${rand}% seiso SWEAT`, msg.messageId);
else if (rand > 10) await sendMessage(`${rand}% seiso catErm`, msg.messageId);

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import { isAdmin } from "lib/admins";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { handleCheer } from "events/message";
import parseCommandArgs from "lib/parseCommandArgs";

View File

@@ -1,9 +1,9 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
import items from "items";
import { isInvuln, removeInvuln } from "lib/invuln";
import { streamerUsers } from "main";
import getloot from "./getloot";
import getloot from "commands/getloot";
export default new Command({
name: 'use',
@@ -11,8 +11,8 @@ export default new Command({
usertype: 'chatter',
disableable: false,
specialaliases: ['i'],
execution: async (msg, user) => {
const messagequery = msg.messageText.trim().split(' ').slice(1);
execution: async (msg, user, specialargs) => {
const messagequery = msg.messageText.trim().split(' ').slice(1); // This selects the item, so on "i blast mrockstar20" it would pick ["blast", "mrockstar20"]
const silent = msg.messageText.toLowerCase().startsWith('i');
if (!messagequery[0]) { if (!silent) { await sendMessage('Please specify an item you would like to use', msg.messageId); }; return; };
const selection = items.get(messagequery[0].toLowerCase());
@@ -20,6 +20,6 @@ export default new Command({
if (!selection) { if (!silent) { await sendMessage(`'${messagequery[0]}' is not an item`, msg.messageId); }; return; };
if (await redis.sismember('disabledcommands', selection.name)) { await sendMessage(`The ${selection.prettyName} item is disabled`, msg.messageId); return; };
if (await isInvuln(msg.chatterId) && !streamerUsers.includes(msg.chatterId)) { await sendMessage(`You're no longer an invuln because you used an item.`, msg.messageId); await removeInvuln(msg.chatterId); };
await selection.execute(msg, user);
await selection.execute(msg, user, specialargs);
}
});

View File

@@ -1,5 +1,5 @@
import { redis } from "bun";
import { Command, sendMessage } from "commands";
import { redis } from "lib/redis";
import { Command, sendMessage } from "lib/commandUtils";
export default new Command({
name: 'vulnchatters',

View File

@@ -1,4 +1,4 @@
import { Command, sendMessage } from "commands";
import { Command, sendMessage } from "lib/commandUtils";
import { timeout } from "lib/timeout";
// Remake of the !yabai command in ttv/kiara_tv