stop item usage when another item is already in use

This commit is contained in:
2025-04-18 16:47:50 +02:00
parent a1c93ef64b
commit b56f179717
3 changed files with 22 additions and 7 deletions

View File

@@ -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 }))
}

View File

@@ -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()
})

View File

@@ -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
}