From b56f179717dd82ab44ff39ea322992971c89b154 Mon Sep 17 00:00:00 2001 From: qwerinope Date: Fri, 18 Apr 2025 16:47:50 +0200 Subject: [PATCH] stop item usage when another item is already in use --- src/commands/itemAliases.ts | 10 +++++++--- src/commands/use.ts | 13 +++++++++---- src/lib/items.ts | 6 ++++++ 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/commands/itemAliases.ts b/src/commands/itemAliases.ts index 97a1c13..0c49ad5 100644 --- a/src/commands/itemAliases.ts +++ b/src/commands/itemAliases.ts @@ -2,18 +2,21 @@ import { BotCommand, createBotCommand } from "@twurple/easy-bot"; import api from "../lib/api"; import items from "../items"; +import { ITEMBUSY, toggleBusy } from "../lib/items"; const aliascommands: BotCommand[] = [] for (const item of items) { - aliascommands.push(createBotCommand(item.name, async (params, { say, broadcasterId, userId }) => { + aliascommands.push(createBotCommand(item.name, async (params, { say, reply, broadcasterId, userId }) => { + if (ITEMBUSY) { await reply(`There is currently an item in use. Try again.`); return } const user = await api.users.getUserById(userId) + toggleBusy() switch (item.name) { case 'blaster': case 'silverbullet': case 'revive': case 'superrevive': - if (params[0] === undefined) { await say('nice miss bro'); return } + if (params[0] === undefined) { await reply('Please specify a target'); return } await item.execute(user!, say, broadcasterId, params[0].replace(/[@]/g, '')) break case 'grenade': @@ -24,10 +27,11 @@ for (const item of items) { await item.execute(user!, say) break case 'clipboard': - if (params[0] === undefined) { await say("Please specify what the clipboard asks") } + if (params[0] === undefined) { await reply("Please specify what the clipboard asks") } await item.execute(user!, say, broadcasterId, params.join(' ')) break } + toggleBusy() }, { aliases: item.aliases })) } diff --git a/src/commands/use.ts b/src/commands/use.ts index 23eaac1..65d25b9 100644 --- a/src/commands/use.ts +++ b/src/commands/use.ts @@ -1,21 +1,25 @@ import { createBotCommand } from "@twurple/easy-bot"; import api from "../lib/api"; import items from "../items"; +import { ITEMBUSY, toggleBusy } from "../lib/items"; -export default createBotCommand('use', async (params, { say, broadcasterId, userId }) => { +export default createBotCommand('use', async (params, { say, reply, broadcasterId, userId }) => { const user = await api.users.getUserById(userId) if (params[0] === undefined) return const selection = items.find(item => item.aliases.includes(params[0].toLowerCase())) - if (!selection) { say(`${params[0]} does not exist!`); return } + if (!selection) { reply(`${params[0]} does not exist!`); return } + if (ITEMBUSY) { await reply(`There is currently an item in use. Try again.`); return } + + toggleBusy() switch (selection.name) { case 'blaster': case 'silverbullet': case 'revive': case 'superrevive': - if (params[1] === undefined) { await say('nice miss bro'); return } + if (params[1] === undefined) { await reply('Please specify a target'); return } await selection.execute(user!, say, broadcasterId, params[1].replace(/[@]/g, '')) break case 'grenade': @@ -26,8 +30,9 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user await selection.execute(user!, say) break case 'clipboard': - if (params[1] === undefined) { await say("Please specify what the clipboard asks")} + if (params[1] === undefined) { await reply("Please specify what the clipboard asks") } await selection.execute(user!, say, broadcasterId, params.slice(1).join(' ')) break } + toggleBusy() }) diff --git a/src/lib/items.ts b/src/lib/items.ts index 7a4a42f..37e2a7d 100644 --- a/src/lib/items.ts +++ b/src/lib/items.ts @@ -26,3 +26,9 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1 return { result: true, reason: '', count: inv[item], inv } } + +export let ITEMBUSY = false + +export function toggleBusy() { + ITEMBUSY = !ITEMBUSY +}