mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-18 23:01:38 +01:00
fight greedy chatters spamming !getloot
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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`);
|
||||
});
|
||||
|
||||
12
src/user.ts
12
src/user.ts
@@ -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`);
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user