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:
parent
ff99c1a84e
commit
97f32c5f15
5 changed files with 116 additions and 92 deletions
51
src/data/GuildArchives.ts
Normal file
51
src/data/GuildArchives.ts
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue