diff --git a/src/commands/getloot.ts b/src/commands/getloot.ts index 80be143..42da326 100644 --- a/src/commands/getloot.ts +++ b/src/commands/getloot.ts @@ -15,7 +15,7 @@ function getTimeDifference(date1: number , date2: number) { export default createBotCommand('getloot', async (_params, { reply, userId/*, broadcasterId*/ }) => { const user = await api.users.getUserById(userId) - // if (!user?.isSubscribedTo(broadcasterId)) {await reply('Subscribe to receive loot mandoooSmile'); return} + // if (!user?.isSubscribedTo(broadcasterId)) {await reply('Subscribe to get loot mandoooSmile'); return} const data = await lootboxReady(user) if (!data.result) { const { days, hours, minutes, seconds } = getTimeDifference(data.lastlootbox, Date.now() - 1000 * 60 * 60 * 24 * 30) diff --git a/src/commands/index.ts b/src/commands/index.ts index 9e98829..e02a8cd 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -6,5 +6,6 @@ import stats from "./stats"; import mbucks from "./mbucks"; import getloot from "./getloot"; import modme from "./modme"; +import use from "./use"; -export default [timeout, thank, give, inventory, stats, mbucks, getloot, modme] +export default [timeout, thank, give, inventory, stats, mbucks, getloot, modme, use] diff --git a/src/commands/use.ts b/src/commands/use.ts new file mode 100644 index 0000000..fe4d24a --- /dev/null +++ b/src/commands/use.ts @@ -0,0 +1,18 @@ +import { createBotCommand } from "@twurple/easy-bot"; +import { useBlaster } from "../lib/items"; +import api from "../lib/api"; + +export default createBotCommand('use', async (params, { say, broadcasterId, userId }) => { + const user = await api.users.getUserById(userId) + + if (params[0] === undefined) return + + switch(params[0].toLowerCase()) { + case 'blaster': + if (params[1] === undefined) return + await useBlaster(broadcasterId, user!, params[1], say) + break + default: + await say(`${params[0]} does not exist mandoooYikes`) + } +}) diff --git a/src/lib/items.ts b/src/lib/items.ts index e1e9401..6e743b0 100644 --- a/src/lib/items.ts +++ b/src/lib/items.ts @@ -1,7 +1,9 @@ import { HelixUser } from "@twurple/api" -import { getInventory, updateInventory } from "../lib/userHelper" +import { getInventory, updateInventory, changeBalance } from "../lib/userHelper" +import { timeout, addTimeoutToDB } from "./timeoutHelper" +import api from "./api" -const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'watergun', 'clipboard', 'lootbox'] +export const ITEMS = ['blaster', 'silverbullet', 'grenade', 'tnt', 'watergun', 'clipboard', 'lootbox'] interface itemChangeResult { result: boolean, @@ -22,3 +24,27 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1 await updateInventory(user, inv) return { result: true, reason: '', count: inv[item] } } + +export async function useBlaster(broadcasterId: string, attacker: HelixUser, targetname: string, say: (arg0: string) => Promise) { + const target = await api.users.getUserByName(targetname) + + const result = await timeout(broadcasterId, target!, 60, `You got blasted by ${attacker.name}`) + if (result.status) { + const itemResult = await changeItemCount(attacker, 'blaster') + await say(`${targetname} got mandoooGun by ${attacker.name}! mandoooGOTTEM ${attacker.name} has ${itemResult.count} blaster${itemResult.count === 1 ? '' : 's'} remaining`) + await addTimeoutToDB(attacker, target!, 'blaster') + } else { + switch (result.reason) { + case 'noexist': + await say(`${targetname} doesn't exist!`) + break + case 'banned': + await say(`${targetname} is already dead!`) + break + case 'unknown': + await say(`NO!`) + await timeout(broadcasterId, attacker, 60, "NO!") + break + } + } +}