From dc087c359982930602f0e87c2ea9b8b181b7493a Mon Sep 17 00:00:00 2001 From: qwerinope Date: Wed, 25 Jun 2025 01:48:17 +0200 Subject: [PATCH] reworked !use and !info, moved functionality from timeout to item --- bot/commands/iteminfo.ts | 8 ++++---- bot/commands/useitem.ts | 8 ++++---- bot/events/message.ts | 3 ++- bot/items/blaster.ts | 36 ++++++++++++++++++++++++++++++++++++ bot/lib/timeout.ts | 10 +++------- 5 files changed, 49 insertions(+), 16 deletions(-) create mode 100644 bot/items/blaster.ts diff --git a/bot/commands/iteminfo.ts b/bot/commands/iteminfo.ts index aac7971..6ade633 100644 --- a/bot/commands/iteminfo.ts +++ b/bot/commands/iteminfo.ts @@ -2,9 +2,9 @@ import { Command, sendMessage } from "."; import items from "../items"; export default new Command('iteminfo', ['iteminfo', 'itemhelp', 'info'], [], async msg => { - const messageparts = msg.messageText.split(' '); - if (!messageparts[1]) { await sendMessage('Please specify an item you would like to get info about', msg.messageId); return; }; - const selection = items.get(messageparts[1].toLowerCase()); - if (!selection) { await sendMessage(`'${messageparts[1]}' is not an item`, msg.messageId); return; }; + const messagequery = msg.messageText.trim().split(' ').slice(1).join(' '); + if (!messagequery) { await sendMessage('Please specify an item you would like to get info about', msg.messageId); return; }; + const selection = items.get(messagequery.toLowerCase()); + if (!selection) { await sendMessage(`'${messagequery}' is not an item`, msg.messageId); return; }; await sendMessage(`Name: ${selection.prettyName}, Description: ${selection.description}, Aliases: ${selection.aliases.join(', ')}`, msg.messageId); }); diff --git a/bot/commands/useitem.ts b/bot/commands/useitem.ts index 2021195..73dafd6 100644 --- a/bot/commands/useitem.ts +++ b/bot/commands/useitem.ts @@ -2,9 +2,9 @@ import { Command, sendMessage } from "."; import items from "../items"; export default new Command('use', ['use'], [], async (msg, user) => { - const messageparts = msg.messageText.split(' '); - if (!messageparts[1]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; }; - const selection = items.get(messageparts[1].toLowerCase()); - if (!selection) { await sendMessage(`'${messageparts[1]}' is not an item`, msg.messageId); return; }; + const messagequery = msg.messageText.trim().split(' ').slice(1); + if (!messagequery[0]) { await sendMessage('Please specify an item you would like to use', msg.messageId); return; }; + const selection = items.get(messagequery[0].toLowerCase()); + if (!selection) { await sendMessage(`'${messagequery[0]}' is not an item`, msg.messageId); return; }; await selection.execute(msg, user); }); diff --git a/bot/events/message.ts b/bot/events/message.ts index 7d2985c..61c77e0 100644 --- a/bot/events/message.ts +++ b/bot/events/message.ts @@ -12,8 +12,9 @@ eventSub.onChannelChatMessage(streamerId, streamerId, async msg => { // Given the fact that this is the user that chats, this user object always exists and cannot be null // // One of the flaws with the user object is solved by creating the object with the name. - // This way, if a user changes their name, the original name stays in the cache for at least 1 hour (extendable by using that name to timeout) + // This way, if a user changes their name, the original name stays in the cache for at least 1 hour (extendable by using that name as target for item) // 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 = await User.initUsername(msg.chatterName); if (!unbannableUsers.includes(msg.chatterId)) user?.makeVulnerable(); // Make the user vulnerable to explosions diff --git a/bot/items/blaster.ts b/bot/items/blaster.ts new file mode 100644 index 0000000..688f0a8 --- /dev/null +++ b/bot/items/blaster.ts @@ -0,0 +1,36 @@ +import { Item } from "."; +import { sendMessage } from "../commands"; +import { timeout } from "../lib/timeout"; +import { User } from "../user"; + +export default new Item('blaster', 'Blaster', 's', + 'Times a specific person out for 60 seconds', + ['blaster', 'blast'], ['moderator:manage:banned_users'], + async (msg, user) => { + const slicecount = msg.messageText.startsWith('!use') ? 2 : 1; + const messagequery = msg.messageText.trim().split(' ').slice(slicecount); + if (!messagequery[0]) { await sendMessage('Please specify a target'); return; }; + const target = await User.initUsername(messagequery[0].toLowerCase()); + if (!target) { await sendMessage(`${messagequery[0]} doesn't exist`); return; }; + const result = await timeout(target, `You got blasted by ${user.displayName}!`, 60); + if (result.status) await Promise.all([ + sendMessage(`GOTTEM ${target.displayName} got BLASTED by ${user.displayName} GOTTEM`) + ]); + else { + switch (result.reason) { + case "banned": + await sendMessage(`${target.displayName} is already timed out/banned`, msg.messageId); + break; + case "illegal": + await Promise.all([ + sendMessage(`${user.displayName} Nou Nou Nou`), + timeout(user, `You can't just shoot ${target.displayName}!`, 60) + ]); + break; + case "unknown": + await sendMessage('Something went wrong...', msg.messageId); + break; + }; + }; + } +); diff --git a/bot/lib/timeout.ts b/bot/lib/timeout.ts index 80f5dbe..644a234 100644 --- a/bot/lib/timeout.ts +++ b/bot/lib/timeout.ts @@ -2,18 +2,14 @@ import { streamerApi, streamerId, unbannableUsers } from ".."; import { User } from "../user"; type SuccessfulTimeout = { status: true }; -type UnSuccessfulTimeout = { status: false; reason: 'noexist' | 'banned' | 'unknown' | 'illegal' }; +type UnSuccessfulTimeout = { status: false; reason: 'banned' | 'unknown' | 'illegal' }; type TimeoutResult = SuccessfulTimeout | UnSuccessfulTimeout; /** Give a user a timeout/ban - * @param target - userid or User class to timeout/ban + * @param user - user class of target to timeout/ban * @param reason - reason for timeout/ban * @param duration - duration of timeout. don't specifiy for ban */ -export const timeout = async (target: string | User, reason: string, duration?: number): Promise => { - // set the user object to either the predefined user obj or a new user obj - const user = typeof (target) === 'string' ? await User.initUsername(target) : target; - if (!user) return { status: false, reason: 'noexist' }; - +export const timeout = async (user: User, reason: string, duration?: number): Promise => { if (unbannableUsers.includes(user.id)) return { status: false, reason: 'illegal' }; // Check if user already has a timeout