mirror of
https://gitlab.com/qwerinope/qweribot.git
synced 2026-02-04 09:46:57 +01:00
fix testcheer command, reformat message event
This commit is contained in:
@@ -2,10 +2,10 @@ import { Command, sendMessage } from ".";
|
|||||||
import { handleCheer } from "../events/message";
|
import { handleCheer } from "../events/message";
|
||||||
import parseCommandArgs from "../lib/parseCommandArgs";
|
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);
|
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 (!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; };
|
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.
|
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);
|
}, false);
|
||||||
|
|||||||
@@ -12,14 +12,10 @@ logger.info(`Loaded the following commands: ${commands.keys().toArray().join(',
|
|||||||
eventSub.onChannelChatMessage(streamerId, streamerId, parseChatMessage);
|
eventSub.onChannelChatMessage(streamerId, streamerId, parseChatMessage);
|
||||||
|
|
||||||
async function parseChatMessage(msg: EventSubChannelChatMessageEvent) {
|
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;
|
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
|
// 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
|
// 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)
|
// 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
|
// 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 (!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:
|
// Parse commands:
|
||||||
if (msg.messageText.startsWith(commandPrefix)) {
|
if (msg.messageText.startsWith(commandPrefix)) {
|
||||||
const commandSelection = msg.messageText.slice(commandPrefix.length).split(' ')[0]!;
|
const commandSelection = msg.messageText.slice(commandPrefix.length).split(' ')[0]!;
|
||||||
const selected = commands.get(commandSelection.toLowerCase());
|
const selected = commands.get(commandSelection.toLowerCase());
|
||||||
if (!selected) return;
|
if (!selected) return;
|
||||||
if (disabledcommands.includes(selected.name)) return;
|
if (await redis.sismember('disabledcommands', selected.name)) return;
|
||||||
|
|
||||||
switch (selected.usertype) {
|
switch (selected.usertype) {
|
||||||
case "admin":
|
case "admin":
|
||||||
if (!await isAdmin(user!.id)) return;
|
if (!await isAdmin(user.id)) return;
|
||||||
break;
|
break;
|
||||||
case "streamer":
|
case "streamer":
|
||||||
if (!streamerUsers.includes(msg.chatterId)) return;
|
if (!streamerUsers.includes(msg.chatterId)) return;
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
try { await selected.execute(msg, user!); }
|
try { await selected.execute(msg, user); }
|
||||||
catch (err) {
|
catch (err) {
|
||||||
logger.err(err as string);
|
logger.err(err as string);
|
||||||
await sendMessage('ERROR: Something went wrong', msg.messageId);
|
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);
|
const selection = cheers.get(bits);
|
||||||
if (!selection) return;
|
if (!selection) return;
|
||||||
|
|
||||||
const [user, disabledcheers] = await Promise.all([
|
if (await redis.sismember('disabledcheers', selection.name)) { await sendMessage(`The ${selection.name} cheer is disabled`); return; };
|
||||||
User.initUsername(msg.chatterName),
|
|
||||||
redis.smembers('disabledcheers')
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (disabledcheers.includes(selection.name)) { await sendMessage(`The ${selection.name} cheer is disabled`); return; };
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
selection.execute(msg, user!);
|
selection.execute(msg, user);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.err(err as string);
|
logger.err(err as string);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user