3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-13 13:25:03 +00:00

feat(mutes): clear old expired mutes for servers that have disabled the mutes plugin

This commit is contained in:
Dragory 2021-10-17 20:12:42 +03:00
parent 66b93dd31c
commit f00a7afab8
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 16 additions and 1 deletions

View file

@ -1,9 +1,11 @@
import moment from "moment-timezone";
import { Brackets, getRepository, Repository } from "typeorm";
import { Mute } from "./entities/Mute";
import { DBDateFormat } from "../utils";
import { DAYS, DBDateFormat } from "../utils";
import { BaseRepository } from "./BaseRepository";
const OLD_EXPIRED_MUTE_THRESHOLD = 7 * DAYS;
export class Mutes extends BaseRepository {
private mutes: Repository<Mute>;
@ -20,4 +22,14 @@ export class Mutes extends BaseRepository {
.andWhere("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
.createQueryBuilder("mutes")
.andWhere("expires_at IS NOT NULL")
.andWhere("expires_at <= :date", { date: thresholdDateStr })
.delete()
.execute();
}
}