From 354ad8211bcff1ec88f7094b999fa0fb5c1e1880 Mon Sep 17 00:00:00 2001 From: qwerinope Date: Wed, 10 Sep 2025 00:27:58 +0200 Subject: [PATCH] fight greedy chatters spamming !getloot --- src/commands/getloot.ts | 18 +++++++++++++++++- src/events/bans.ts | 1 + src/user.ts | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/commands/getloot.ts b/src/commands/getloot.ts index a63f98f..c9f1631 100644 --- a/src/commands/getloot.ts +++ b/src/commands/getloot.ts @@ -3,6 +3,7 @@ import { Command, sendMessage } from "commands"; import { getUserRecord, updateUserRecord } from "db/dbUser"; import items from "items"; import { buildTimeString } from "lib/dateManager"; +import { timeout } from "lib/timeout"; const COOLDOWN = 10 * 60 * 1000; // 10 mins (ms) @@ -12,8 +13,23 @@ export default new Command('getloot', ['getloot', 'dig', 'loot'], 'chatter', asy const userData = await getUserRecord(user); const lastlootbox = Date.parse(userData.lastlootbox); const now = Date.now(); - if ((lastlootbox + COOLDOWN) > now) { await sendMessage(`Wait ${buildTimeString(now - COOLDOWN, lastlootbox)} for another lootbox.`, msg.messageId); return; }; + if ((lastlootbox + COOLDOWN) > now) { + if (await user.greedy()) { + await Promise.all([ + sendMessage(`${user.displayName} STOP BEING GREEDY!!! UltraMad UltraMad UltraMad`), + timeout(user, 'STOP BEING GREEDY!!!', 60) + ]); + return; + } else { + await Promise.all([ + user.setGreed(), + sendMessage(`Wait ${buildTimeString(now - COOLDOWN, lastlootbox)} for another lootbox.`, msg.messageId) + ]); + return; + }; + }; + await user.clearGreed(); await user.setLock(); userData.lastlootbox = new Date(now).toISOString(); diff --git a/src/events/bans.ts b/src/events/bans.ts index e2f7df3..3de026a 100644 --- a/src/events/bans.ts +++ b/src/events/bans.ts @@ -10,4 +10,5 @@ eventSub.onChannelBan(streamerId, async msg => { eventSub.onChannelUnban(streamerId, async msg => { await redis.del(`user:${msg.userId}:timeout`); + await redis.del(`user:${msg.userId}:remod`); }); diff --git a/src/user.ts b/src/user.ts index a531557..4449f8d 100644 --- a/src/user.ts +++ b/src/user.ts @@ -108,4 +108,16 @@ export default class User { public async clearVulnerable(): Promise { await redis.del(`user:${this.id}:vulnerable`); }; + + public async setGreed(): Promise { + await redis.set(`user:${this.id}:greedy`, '1'); + }; + + public async clearGreed(): Promise { + await redis.del(`user:${this.id}:greedy`); + }; + + public async greedy(): Promise { + return await redis.exists(`user:${this.id}:greedy`); + }; };