From 7b6f8bc07ffe9f124bef669522a96dbc23cad120 Mon Sep 17 00:00:00 2001 From: qwerinope Date: Tue, 8 Apr 2025 23:43:27 +0200 Subject: [PATCH] fix !give negative numbers, !modme, automatic remod system (FUCK JAVASCRIPT) --- src/commands/admin.ts | 2 +- src/commands/modme.ts | 6 +++--- src/lib/items.ts | 4 ++-- src/lib/timeoutHelper.ts | 14 +++++++++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/commands/admin.ts b/src/commands/admin.ts index fb9ba57..79a545a 100644 --- a/src/commands/admin.ts +++ b/src/commands/admin.ts @@ -12,7 +12,7 @@ const give = createBotCommand('give', async (params, { say, broadcasterId, userI if (isNaN(parseInt(params[2]))) { await say(`Specify the amount`); return } - const data = params[1].toLowerCase() === 'qbucks' ? await changeBalance(target, parseInt(params[2])) : await changeItemCount(target, params[1].toLowerCase(), parseInt(params[2])) + const data = params[1].toLowerCase() === 'qbucks' ? await changeBalance(target, parseInt(params[2])) : await changeItemCount(target, params[1].toLowerCase(), parseInt(params[2]), true) if (data.reason === 'negative') { await say(`${target.name} only has ${data.count}. Cannot yoink ${-parseInt(params[2])} ${params[1]}`); return } else if (data.reason === 'noexist') { await say(`Can't find item ${params[1]}`); return } diff --git a/src/commands/modme.ts b/src/commands/modme.ts index 6f1a94d..2a09b6b 100644 --- a/src/commands/modme.ts +++ b/src/commands/modme.ts @@ -4,9 +4,9 @@ import api, { broadcasterApi } from "../lib/api"; const MODS = process.env.MODS if (!MODS) { console.error("Please set the MODS environment variable."); process.exit(1) } -export default createBotCommand('modme', async (_params, { userName, broadcasterId }) => { +export default createBotCommand('modme', async (_params, { userName, broadcasterId, userId }) => { if (!MODS.includes(userName)) return - if (broadcasterApi) await broadcasterApi.moderation.addModerator(broadcasterId, userName) - else await api.moderation.addModerator(broadcasterId, userName) + if (broadcasterApi) await broadcasterApi.moderation.addModerator(broadcasterId, userId) + else await api.moderation.addModerator(broadcasterId, userId) }) diff --git a/src/lib/items.ts b/src/lib/items.ts index 3bf18fb..933a5b6 100644 --- a/src/lib/items.ts +++ b/src/lib/items.ts @@ -12,7 +12,7 @@ interface itemChangeResult { inv?: inventory } -export async function changeItemCount(user: HelixUser, item: string, amount = -1): Promise { +export async function changeItemCount(user: HelixUser, item: string, amount = -1, preconfirmed=false): Promise { if (!ITEMS.includes(item)) return { result: false, reason: 'noexist', count: 0 } let inv = await getInventory(user) @@ -23,7 +23,7 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1 value: newcount, }) - if (amount > 0) await updateInventory(user, inv) + if (amount > 0 || preconfirmed === true) await updateInventory(user, inv) return { result: true, reason: '', count: inv[item], inv } } diff --git a/src/lib/timeoutHelper.ts b/src/lib/timeoutHelper.ts index f0bbd9e..2daeaa0 100644 --- a/src/lib/timeoutHelper.ts +++ b/src/lib/timeoutHelper.ts @@ -19,7 +19,7 @@ export async function timeout(broadcasterid: string, target: HelixUser, duration try { if (await tmpapi.moderation.checkUserMod(broadcasterid, target)) { await tmpapi.moderation.removeModerator(broadcasterid, target) - remodMod(broadcasterid, target, duration, tmpapi) + remodMod(broadcasterid, target, duration * 1000, tmpapi) } await tmpapi.moderation.banUser(broadcasterid, { duration, reason, user: target }) await DBValidation(target) @@ -45,8 +45,16 @@ export async function addTimeoutToDB(attacker: HelixUser, target: HelixUser, sou function remodMod(broadcasterid: string, target: HelixUser, duration: number, api: ApiClient) { setTimeout(async () => { - await api.moderation.addModerator(broadcasterid, target) - }, (duration + 3) * 1000) + const bandata = await api.moderation.getBannedUsers(broadcasterid, { userId: target.id }) + if (bandata.data.length !== 0) { + const timeoutleft = -Date.now() + Date.parse(bandata.data[0].expiryDate?.toString()! + 3000) // date when timeout expires - current date + 3 seconds constant + remodMod(broadcasterid, target, timeoutleft, api) // Call the current function with new time (recursion) + } else { // If user is still timed out it doesn't try to remod the target + try { + await api.moderation.addModerator(broadcasterid, target) + } catch (err) { console.log(err) } // This triggers when the timeout got shortened. try/catch so no runtime error + } + }, duration + 3000) // callback gets called after duration of timeout + 3 seconds } export let vulnerableUsers: string[] = []