fight greedy chatters spamming !getloot

This commit is contained in:
2025-09-10 00:27:58 +02:00
parent f243677c5c
commit 354ad8211b
3 changed files with 30 additions and 1 deletions

View File

@@ -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();

View File

@@ -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`);
});

View File

@@ -108,4 +108,16 @@ export default class User {
public async clearVulnerable(): Promise<void> {
await redis.del(`user:${this.id}:vulnerable`);
};
public async setGreed(): Promise<void> {
await redis.set(`user:${this.id}:greedy`, '1');
};
public async clearGreed(): Promise<void> {
await redis.del(`user:${this.id}:greedy`);
};
public async greedy(): Promise<boolean> {
return await redis.exists(`user:${this.id}:greedy`);
};
};