mirror of
https://github.com/qwerinope/qweribot.git
synced 2025-12-19 01:01:39 +01:00
store mods on redis, just like timeouts
This commit is contained in:
@@ -7,3 +7,7 @@ eventSub.onChannelBan(streamerId, async msg => {
|
||||
await redis.set(`user:${msg.userId}:timeout`, '1');
|
||||
if (msg.endDate) await redis.expire(`user:${msg.userId}:timeout`, Math.floor((msg.endDate.getTime() - Date.now()) / 1000));
|
||||
});
|
||||
|
||||
eventSub.onChannelUnban(streamerId, async msg => {
|
||||
await redis.del(`user:${msg.userId}:timeout`);
|
||||
});
|
||||
10
src/events/moderators.ts
Normal file
10
src/events/moderators.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { redis } from "bun";
|
||||
import { eventSub, streamerId } from "main";
|
||||
|
||||
eventSub.onChannelModeratorAdd(streamerId, async mod => {
|
||||
await redis.set(`user:${mod.userId}:mod`, '1');
|
||||
});
|
||||
|
||||
eventSub.onChannelModeratorRemove(streamerId, async mod => {
|
||||
await redis.del(`user:${mod.userId}:mod`);
|
||||
});
|
||||
@@ -1,6 +0,0 @@
|
||||
import { redis } from "bun";
|
||||
import { eventSub, streamerId } from "main";
|
||||
|
||||
eventSub.onChannelUnban(streamerId, async msg => {
|
||||
await redis.del(`user:${msg.userId}:timeout`);
|
||||
});
|
||||
@@ -35,10 +35,16 @@ streamerUsers.forEach(async id => await Promise.all([addAdmin(id), addInvuln(id)
|
||||
const banned = await streamerApi.moderation.getBannedUsers(streamerId).then(a => a.data);
|
||||
banned.forEach(async ban => {
|
||||
await redis.set(`user:${ban.userId}:timeout`, '1');
|
||||
if (ban.expiryDate) redis.expire(`user:${ban.userId}:timeout`, Math.floor((ban.expiryDate.getTime() - Date.now()) / 1000));
|
||||
if (ban.expiryDate) redis.expire(`user:${ban.userId}:timeout`, Math.floor((ban.expiryDate.getTime() - Date.now()) / 1000) + 1);
|
||||
logger.info(`Set the timeout/ban of ${ban.userDisplayName} in the Redis/Valkey database.`);
|
||||
});
|
||||
|
||||
const mods = await streamerApi.moderation.getModerators(streamerId).then(a => a.data);
|
||||
mods.forEach(async mod => {
|
||||
await redis.set(`user:${mod.userId}:mod`, '1');
|
||||
logger.info(`Set the mod status of ${mod.userDisplayName} in the Redis/Valkey database.`);
|
||||
});
|
||||
|
||||
await import("./events");
|
||||
|
||||
await import("./web");
|
||||
|
||||
@@ -23,7 +23,7 @@ export const timeout = async (user: User, reason: string, duration?: number): Pr
|
||||
} else return { status: false, reason: 'banned' }; // the target is timed out, but stacking is off
|
||||
} else if (banStatus === null) return { status: false, reason: 'banned' }; // target is perma banned
|
||||
|
||||
if (await streamerApi.moderation.checkUserMod(streamerId, user.id!)) {
|
||||
if (await redis.exists(`user:${user.id}:mod`)) {
|
||||
if (!duration) duration = 60; // make sure that mods don't get perma-banned
|
||||
remodMod(user, duration);
|
||||
await streamerApi.moderation.removeModerator(streamerId, user.id!);
|
||||
|
||||
Reference in New Issue
Block a user