mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-07-07 11:07:19 +00:00
feat: timeout support
This commit is contained in:
parent
06877e90cc
commit
39e0dfa27f
23 changed files with 532 additions and 92 deletions
|
@ -3,9 +3,14 @@ import { getRepository, Repository } from "typeorm";
|
|||
import { DAYS, DBDateFormat } from "../utils";
|
||||
import { BaseRepository } from "./BaseRepository";
|
||||
import { Mute } from "./entities/Mute";
|
||||
import { MuteTypes } from "./MuteTypes";
|
||||
|
||||
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS;
|
||||
|
||||
export const MAX_TIMEOUT_DURATION = 28 * DAYS;
|
||||
// When a timeout is under this duration but the mute expires later, the timeout will be reset to max duration
|
||||
export const TIMEOUT_RENEWAL_THRESHOLD = 21 * DAYS;
|
||||
|
||||
export class Mutes extends BaseRepository {
|
||||
private mutes: Repository<Mute>;
|
||||
|
||||
|
@ -14,7 +19,16 @@ export class Mutes extends BaseRepository {
|
|||
this.mutes = getRepository(Mute);
|
||||
}
|
||||
|
||||
async getSoonExpiringMutes(threshold: number): Promise<Mute[]> {
|
||||
findMute(guildId: string, userId: string): Promise<Mute | undefined> {
|
||||
return this.mutes.findOne({
|
||||
where: {
|
||||
guild_id: guildId,
|
||||
user_id: userId,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
getSoonExpiringMutes(threshold: number): Promise<Mute[]> {
|
||||
const thresholdDateStr = moment.utc().add(threshold, "ms").format(DBDateFormat);
|
||||
return this.mutes
|
||||
.createQueryBuilder("mutes")
|
||||
|
@ -23,6 +37,16 @@ export class Mutes extends BaseRepository {
|
|||
.getMany();
|
||||
}
|
||||
|
||||
getTimeoutMutesToRenew(threshold: number): Promise<Mute[]> {
|
||||
const thresholdDateStr = moment.utc().add(threshold, "ms").format(DBDateFormat);
|
||||
return this.mutes
|
||||
.createQueryBuilder("mutes")
|
||||
.andWhere("type = :type", { type: MuteTypes.Timeout })
|
||||
.andWhere("(expires_at IS NULL OR timeout_expires_at < expires_at)")
|
||||
.andWhere("timeout_expires_at <= :date", { date: thresholdDateStr })
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async clearOldExpiredMutes(): Promise<void> {
|
||||
const thresholdDateStr = moment.utc().subtract(OLD_EXPIRED_MUTE_THRESHOLD, "ms").format(DBDateFormat);
|
||||
await this.mutes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue