3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-17 15:15:02 +00:00

Rename SpamLogs to Archives. Tweak spam archive format.

This commit is contained in:
Dragory 2018-08-18 19:51:28 +03:00
parent ff99c1a84e
commit 97f32c5f15
5 changed files with 116 additions and 92 deletions

51
src/data/GuildArchives.ts Normal file
View file

@ -0,0 +1,51 @@
import uuid from "uuid/v4"; // tslint:disable-line
import moment from "moment-timezone";
import knex from "../knex";
import SpamLog from "../models/SpamLog";
const DEFAULT_EXPIRY_DAYS = 30;
function deleteExpiredArchives() {
knex("archives")
.where("expires_at", "<=", knex.raw("NOW()"))
.delete();
}
deleteExpiredArchives();
setInterval(deleteExpiredArchives, 1000 * 60 * 60); // Clean expired archives every hour
export class GuildArchives {
protected guildId: string;
constructor(guildId) {
this.guildId = guildId;
}
generateNewLogId() {
return uuid();
}
async find(id: string): Promise<SpamLog> {
const result = await knex("archives")
.where("id", id)
.first();
return result ? new SpamLog(result) : null;
}
async create(body: string, expiresAt: moment.Moment = null) {
const id = this.generateNewLogId();
if (!expiresAt) {
expiresAt = moment().add(DEFAULT_EXPIRY_DAYS, "days");
}
await knex("archives").insert({
id,
guild_id: this.guildId,
body,
expires_at: expiresAt.format("YYYY-MM-DD HH:mm:ss")
});
return id;
}
}