mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
stop item usage when another item is already in use
This commit is contained in:
@@ -2,18 +2,21 @@ import { BotCommand, createBotCommand } from "@twurple/easy-bot";
|
|||||||
|
|
||||||
import api from "../lib/api";
|
import api from "../lib/api";
|
||||||
import items from "../items";
|
import items from "../items";
|
||||||
|
import { ITEMBUSY, toggleBusy } from "../lib/items";
|
||||||
|
|
||||||
const aliascommands: BotCommand[] = []
|
const aliascommands: BotCommand[] = []
|
||||||
|
|
||||||
for (const item of items) {
|
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)
|
const user = await api.users.getUserById(userId)
|
||||||
|
toggleBusy()
|
||||||
switch (item.name) {
|
switch (item.name) {
|
||||||
case 'blaster':
|
case 'blaster':
|
||||||
case 'silverbullet':
|
case 'silverbullet':
|
||||||
case 'revive':
|
case 'revive':
|
||||||
case 'superrevive':
|
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, ''))
|
await item.execute(user!, say, broadcasterId, params[0].replace(/[@]/g, ''))
|
||||||
break
|
break
|
||||||
case 'grenade':
|
case 'grenade':
|
||||||
@@ -24,10 +27,11 @@ for (const item of items) {
|
|||||||
await item.execute(user!, say)
|
await item.execute(user!, say)
|
||||||
break
|
break
|
||||||
case 'clipboard':
|
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(' '))
|
await item.execute(user!, say, broadcasterId, params.join(' '))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
toggleBusy()
|
||||||
}, { aliases: item.aliases }))
|
}, { aliases: item.aliases }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,25 @@
|
|||||||
import { createBotCommand } from "@twurple/easy-bot";
|
import { createBotCommand } from "@twurple/easy-bot";
|
||||||
import api from "../lib/api";
|
import api from "../lib/api";
|
||||||
import items from "../items";
|
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)
|
const user = await api.users.getUserById(userId)
|
||||||
|
|
||||||
if (params[0] === undefined) return
|
if (params[0] === undefined) return
|
||||||
const selection = items.find(item => item.aliases.includes(params[0].toLowerCase()))
|
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) {
|
switch (selection.name) {
|
||||||
case 'blaster':
|
case 'blaster':
|
||||||
case 'silverbullet':
|
case 'silverbullet':
|
||||||
case 'revive':
|
case 'revive':
|
||||||
case 'superrevive':
|
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, ''))
|
await selection.execute(user!, say, broadcasterId, params[1].replace(/[@]/g, ''))
|
||||||
break
|
break
|
||||||
case 'grenade':
|
case 'grenade':
|
||||||
@@ -26,8 +30,9 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user
|
|||||||
await selection.execute(user!, say)
|
await selection.execute(user!, say)
|
||||||
break
|
break
|
||||||
case 'clipboard':
|
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(' '))
|
await selection.execute(user!, say, broadcasterId, params.slice(1).join(' '))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
toggleBusy()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -26,3 +26,9 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1
|
|||||||
|
|
||||||
return { result: true, reason: '', count: inv[item], inv }
|
return { result: true, reason: '', count: inv[item], inv }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export let ITEMBUSY = false
|
||||||
|
|
||||||
|
export function toggleBusy() {
|
||||||
|
ITEMBUSY = !ITEMBUSY
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user