fix testcheer command, reformat message event

This commit is contained in:
2025-07-07 16:24:15 +02:00
parent 73d281c6c6
commit 8fd889856b
2 changed files with 17 additions and 27 deletions

View File

@@ -2,10 +2,10 @@ import { Command, sendMessage } from ".";
import { handleCheer } from "../events/message";
import parseCommandArgs from "../lib/parseCommandArgs";
export default new Command('testcheer', ['testcheer'], 'streamer', async msg => {
export default new Command('testcheer', ['testcheer'], 'streamer', async (msg, user) => {
const args = parseCommandArgs(msg.messageText);
if (!args[0]) { await sendMessage('Please specify the amount of fake bits you want to send', msg.messageId); return; };
if (isNaN(Number(args[0]))) { await sendMessage(`${args[0]} is not a valid amout of bits`); return; };
const bits = Number(args.shift()); // we shift it so the amount of bits isn't part of the handleCheer message, we already know that args[0] can be parsed as a number so this is fine.
await handleCheer(msg, bits);
await handleCheer(msg, bits, user);
}, false);

View File

@@ -12,14 +12,10 @@ logger.info(`Loaded the following commands: ${commands.keys().toArray().join(',
eventSub.onChannelChatMessage(streamerId, streamerId, parseChatMessage);
async function parseChatMessage(msg: EventSubChannelChatMessageEvent) {
if (!msg.isCheer && !msg.isRedemption) await handleChatMessage(msg)
else if (msg.isCheer && !msg.isRedemption) await handleCheer(msg, msg.bits)
};
async function handleChatMessage(msg: EventSubChannelChatMessageEvent) {
// return if double user mode is on and the chatter says something, we don't need them
if (!singleUserMode && msg.chatterId === chatterId) return;
// return if double user mode is on and the chatter says something, we don't need them
const user = await User.initUsername(msg.chatterName);
// Get user from cache or place user in cache
// Given the fact that this is the user that chats, this user object always exists and cannot be null
@@ -29,51 +25,45 @@ async function handleChatMessage(msg: EventSubChannelChatMessageEvent) {
// and both are usable to target the same user (id is the same)
// The only problem would be if a user changed their name and someone else took their name right after
const [user, disabledcommands] = await Promise.all([
User.initUsername(msg.chatterName),
redis.smembers('disabledcommands')
]);
if (!streamerUsers.includes(msg.chatterId)) user?.makeVulnerable(); // Make the user vulnerable to explosions if not streamerbot or chatterbot
if (!msg.isCheer && !msg.isRedemption) await handleChatMessage(msg, user!)
else if (msg.isCheer && !msg.isRedemption) await handleCheer(msg, msg.bits, user!);
};
async function handleChatMessage(msg: EventSubChannelChatMessageEvent, user: User) {
// Parse commands:
if (msg.messageText.startsWith(commandPrefix)) {
const commandSelection = msg.messageText.slice(commandPrefix.length).split(' ')[0]!;
const selected = commands.get(commandSelection.toLowerCase());
if (!selected) return;
if (disabledcommands.includes(selected.name)) return;
if (await redis.sismember('disabledcommands', selected.name)) return;
switch (selected.usertype) {
case "admin":
if (!await isAdmin(user!.id)) return;
if (!await isAdmin(user.id)) return;
break;
case "streamer":
if (!streamerUsers.includes(msg.chatterId)) return;
break;
};
try { await selected.execute(msg, user!); }
try { await selected.execute(msg, user); }
catch (err) {
logger.err(err as string);
await sendMessage('ERROR: Something went wrong', msg.messageId);
await user?.clearLock();
await user.clearLock();
};
};
};
export async function handleCheer(msg: EventSubChannelChatMessageEvent, bits: number) {
export async function handleCheer(msg: EventSubChannelChatMessageEvent, bits: number, user: User) {
const selection = cheers.get(bits);
if (!selection) return;
const [user, disabledcheers] = await Promise.all([
User.initUsername(msg.chatterName),
redis.smembers('disabledcheers')
]);
if (disabledcheers.includes(selection.name)) { await sendMessage(`The ${selection.name} cheer is disabled`); return; };
if (await redis.sismember('disabledcheers', selection.name)) { await sendMessage(`The ${selection.name} cheer is disabled`); return; };
try {
selection.execute(msg, user!);
selection.execute(msg, user);
} catch (err) {
logger.err(err as string);
};