diff --git a/src/commands/getloot.ts b/src/commands/getloot.ts index 42da326..d889732 100644 --- a/src/commands/getloot.ts +++ b/src/commands/getloot.ts @@ -1,5 +1,5 @@ import { createBotCommand } from "@twurple/easy-bot"; -import { lootboxReady, resetLootboxTimer } from "../lib/lootboxes"; +import { COOLDOWN, lootboxReady, resetLootboxTimer } from "../lib/lootboxes"; import { changeItemCount } from "../lib/items" import api from "../lib/api" @@ -18,7 +18,7 @@ export default createBotCommand('getloot', async (_params, { reply, userId/*, br // 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) + const { days, hours, minutes, seconds } = getTimeDifference(data.lastlootbox, Date.now() - COOLDOWN) await reply(`lootbox ready in: ${days === 0 ? '' : `${days} day${days === 1 ? '' : 's'}, `} ${hours === 0 ? '' : `${hours} hour${hours === 1 ? '' : 's'}, `} diff --git a/src/commands/itemAliases.ts b/src/commands/itemAliases.ts index b7a204a..01d4ea4 100644 --- a/src/commands/itemAliases.ts +++ b/src/commands/itemAliases.ts @@ -1,6 +1,6 @@ import { createBotCommand } from "@twurple/easy-bot"; -import { useBlaster, useGrenade, useSilverBullet } from "../lib/items"; +import { useBlaster, useGrenade, useLootbox, useSilverBullet, useTNT } from "../lib/items"; import api from "../lib/api"; const blaster = createBotCommand('blaster', async (params, { say, broadcasterId, userId }) => { @@ -20,4 +20,14 @@ const grenade = createBotCommand('grenade', async (_params, { say, broadcasterId await useGrenade(broadcasterId, user!, say) }) -export default [blaster, silverbullet, grenade] +const tnt = createBotCommand('tnt', async (_params, { say, broadcasterId, userId }) => { + const user = await api.users.getUserById(userId) + await useTNT(broadcasterId, user!, say) +}) + +const lootbox = createBotCommand('lootbox', async (_params, { say, userId }) => { + const user = await api.users.getUserById(userId) + await useLootbox(user!, say) +}) + +export default [blaster, silverbullet, grenade, tnt, lootbox] diff --git a/src/commands/use.ts b/src/commands/use.ts index 354bbf7..92a0dbf 100644 --- a/src/commands/use.ts +++ b/src/commands/use.ts @@ -1,5 +1,5 @@ import { createBotCommand } from "@twurple/easy-bot"; -import { useBlaster, useGrenade, useSilverBullet } from "../lib/items"; +import { useBlaster, useGrenade, useLootbox, useSilverBullet, useTNT } from "../lib/items"; import api from "../lib/api"; export default createBotCommand('use', async (params, { say, broadcasterId, userId }) => { @@ -20,6 +20,13 @@ export default createBotCommand('use', async (params, { say, broadcasterId, user case 'grenade': await useGrenade(broadcasterId, user!, say) break + case 'tnt': + await useTNT(broadcasterId, user!, say) + break + case 'lootbox': + case 'loot': + await useLootbox(user!, say) + break default: await say(`${params[0]} does not exist mandoooYikes`) } diff --git a/src/lib/items.ts b/src/lib/items.ts index 5916281..809619b 100644 --- a/src/lib/items.ts +++ b/src/lib/items.ts @@ -1,5 +1,5 @@ import { HelixUser } from "@twurple/api" -import { getInventory, updateInventory } from "../lib/userHelper" +import { changeBalance, getInventory, updateInventory } from "../lib/userHelper" import { timeout, addTimeoutToDB, vulnerableUsers } from "./timeoutHelper" import api from "./api" @@ -95,3 +95,45 @@ export async function useGrenade(broadcasterId: string, attacker: HelixUser, say console.error(result.reason) } } + + +export async function useTNT(broadcasterId: string, attacker: HelixUser, say: (args0: string) => Promise) { + if (vulnerableUsers.length === 0) { await say('No chatters to blow up!'); return } + const itemResult = await changeItemCount(attacker, 'tnt') + + if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no TNT mandoooYikes'); return } + const min = vulnerableUsers.length < 3 ? vulnerableUsers.length : 3 //if less than 3 chatters, use that else 3 + const max = vulnerableUsers.length > 10 ? 10 : vulnerableUsers.length //if more than 10 chatters do 10 else 10 + const blastedusers = Math.floor(Math.random() * (max - min + 1)) + min + for (let i = 0; blastedusers > i; i++) { + const target = await api.users.getUserById(vulnerableUsers[Math.floor(Math.random() * vulnerableUsers.length)]) + const result = await timeout(broadcasterId, target!, 60, `You got hit by ${attacker.name}'s TNT`) + if (result.status) { + await say(`${target?.name} got blown up by TNT! mandoooTnt`) + await addTimeoutToDB(attacker, target!, 'tnt') + } else { + await say(`something went wrong mandoooYikes`) + console.error(result.reason) + } + } + await say(`${attacker.name} blew up ${blastedusers} with their TNT mandoooGOTTEM ${attacker.name} has ${itemResult.count} tnt${itemResult.count === 1 ? '' : 's'} remaining`) +} + +function getRandom(): number { + return Math.floor(Math.random() * 100) +} + +export async function useLootbox(user: HelixUser, say: (arg0: string) => Promise) { + const itemResult = await changeItemCount(user, 'lootbox') + if (!itemResult.result && itemResult.reason === 'negative') { await say('You have no lootboxes mandoooYikes'); return } + // Lootbox logic will for now just be get 25 mbucks, with 50% chance to get a grenade 25% chance to get a blaster and 10% chance to get TNT + let inventory = await getInventory(user) + let newitems: string[] = [] + await changeBalance(user, 25) + newitems.push('25 mbucks') + if (getRandom() <= 50) { newitems.push('1 grenade'); await changeItemCount(user, 'grenade', 1) } + if (getRandom() <= 25) { newitems.push('1 blaster'); await changeItemCount(user, 'blaster', 1) } + if (getRandom() <= 10) { newitems.push('1 tnt'); await changeItemCount(user, 'tnt', 1) } + + await say(`${user.name} got: ${newitems.join(' and ')}`) +} diff --git a/src/lib/lootboxes.ts b/src/lib/lootboxes.ts index 97bbca8..a480da3 100644 --- a/src/lib/lootboxes.ts +++ b/src/lib/lootboxes.ts @@ -1,7 +1,8 @@ import { HelixUser } from "@twurple/api" import pb from "./pocketbase" -const COOLDOWN = 1000 * 60 * 60 * 24 * 30 // 1000 milliseconds * 60 seconds * 60 minutes * 24 hours * 30 days +// const COOLDOWN = 1000 * 60 * 60 * 24 * 30 // 1000 milliseconds * 60 seconds * 60 minutes * 24 hours * 30 days +export const COOLDOWN = 1000 * 60 * 15 interface lootboxReadyResult { result: boolean,