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

Use GuildSavedMessages events in logs. Fix code blocks in edit logs.

This commit is contained in:
Dragory 2018-11-24 17:59:05 +02:00
parent 1a6e680d81
commit 2c8603ca70
4 changed files with 95 additions and 37 deletions

View file

@ -11,6 +11,8 @@ const RETENTION_PERIOD = 7 * 24 * 60 * 60 * 1000; // 1 week
export class GuildSavedMessages extends BaseRepository {
private messages: Repository<SavedMessage>;
protected toBePermanent: Set<string>;
public events: QueuedEventEmitter;
constructor(guildId) {
@ -18,6 +20,8 @@ export class GuildSavedMessages extends BaseRepository {
this.messages = getRepository(SavedMessage);
this.events = new QueuedEventEmitter();
this.toBePermanent = new Set();
this.cleanup();
setInterval(() => this.cleanup(), CLEANUP_INTERVAL);
}
@ -84,6 +88,12 @@ export class GuildSavedMessages extends BaseRepository {
}
async create(data) {
const isPermanent = this.toBePermanent.has(data.id);
if (isPermanent) {
data.is_permanent = true;
this.toBePermanent.delete(data.id);
}
try {
await this.messages.insert(data);
} catch (e) {
@ -145,4 +155,18 @@ export class GuildSavedMessages extends BaseRepository {
const newData = this.msgToSavedMessageData(msg);
return this.saveEdit(msg.id, newData);
}
async setPermanent(id: string) {
const savedMsg = await this.find(id);
if (savedMsg) {
await this.messages.update(
{ id },
{
is_permanent: true
}
);
} else {
this.toBePermanent.add(id);
}
}
}