mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 08:41:39 +01:00
fix !give negative numbers, !modme, automatic remod system (FUCK JAVASCRIPT)
This commit is contained in:
@@ -12,7 +12,7 @@ const give = createBotCommand('give', async (params, { say, broadcasterId, userI
|
|||||||
|
|
||||||
if (isNaN(parseInt(params[2]))) { await say(`Specify the amount`); return }
|
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 }
|
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 }
|
else if (data.reason === 'noexist') { await say(`Can't find item ${params[1]}`); return }
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import api, { broadcasterApi } from "../lib/api";
|
|||||||
const MODS = process.env.MODS
|
const MODS = process.env.MODS
|
||||||
if (!MODS) { console.error("Please set the MODS environment variable."); process.exit(1) }
|
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 (!MODS.includes(userName)) return
|
||||||
|
|
||||||
if (broadcasterApi) await broadcasterApi.moderation.addModerator(broadcasterId, userName)
|
if (broadcasterApi) await broadcasterApi.moderation.addModerator(broadcasterId, userId)
|
||||||
else await api.moderation.addModerator(broadcasterId, userName)
|
else await api.moderation.addModerator(broadcasterId, userId)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ interface itemChangeResult {
|
|||||||
inv?: inventory
|
inv?: inventory
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function changeItemCount(user: HelixUser, item: string, amount = -1): Promise<itemChangeResult> {
|
export async function changeItemCount(user: HelixUser, item: string, amount = -1, preconfirmed=false): Promise<itemChangeResult> {
|
||||||
if (!ITEMS.includes(item)) return { result: false, reason: 'noexist', count: 0 }
|
if (!ITEMS.includes(item)) return { result: false, reason: 'noexist', count: 0 }
|
||||||
let inv = await getInventory(user)
|
let inv = await getInventory(user)
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ export async function changeItemCount(user: HelixUser, item: string, amount = -1
|
|||||||
value: newcount,
|
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 }
|
return { result: true, reason: '', count: inv[item], inv }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export async function timeout(broadcasterid: string, target: HelixUser, duration
|
|||||||
try {
|
try {
|
||||||
if (await tmpapi.moderation.checkUserMod(broadcasterid, target)) {
|
if (await tmpapi.moderation.checkUserMod(broadcasterid, target)) {
|
||||||
await tmpapi.moderation.removeModerator(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 tmpapi.moderation.banUser(broadcasterid, { duration, reason, user: target })
|
||||||
await DBValidation(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) {
|
function remodMod(broadcasterid: string, target: HelixUser, duration: number, api: ApiClient) {
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
await api.moderation.addModerator(broadcasterid, target)
|
const bandata = await api.moderation.getBannedUsers(broadcasterid, { userId: target.id })
|
||||||
}, (duration + 3) * 1000)
|
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[] = []
|
export let vulnerableUsers: string[] = []
|
||||||
|
|||||||
Reference in New Issue
Block a user