mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35:02 +00:00
feat: save deleted spam logs; server spam logs from a web server; update Knub to 9.6.4
This commit is contained in:
parent
847ee11195
commit
16be52a5e7
10 changed files with 167 additions and 10 deletions
|
@ -35,7 +35,7 @@
|
|||
|
||||
"COMMAND": "🤖 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) used command in **#{channel.name}**:\n`{command}`",
|
||||
|
||||
"SPAM_DELETE": "🛑 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) spam deleted in **#{channel.name}**: {description} (more than {limit} in {interval}s)",
|
||||
"SPAM_DELETE": "🛑 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) spam deleted in **#{channel.name}**: {description} (more than {limit} in {interval}s) {logUrl}",
|
||||
"CENSOR": "🛑 **{member.user.username}#{member.user.discriminator}** (`{member.id}`) censored message in **#{channel.name}** (`{channel.id}`) {reason}:\n```{messageText}```",
|
||||
"CLEAN": "🚿 **{mod.username}#{mod.discriminator}** (`{mod.id}`) cleaned **{count}** message(s) in **#{channel.name}**",
|
||||
|
||||
|
|
72
src/data/GuildSpamLogs.ts
Normal file
72
src/data/GuildSpamLogs.ts
Normal file
|
@ -0,0 +1,72 @@
|
|||
import uuid from "uuid/v4"; // tslint:disable-line
|
||||
import moment from "moment-timezone";
|
||||
import knex from "../knex";
|
||||
import SpamLog from "../models/SpamLog";
|
||||
import { Message } from "eris";
|
||||
import { formatTemplateString, stripObjectToScalars, trimLines } from "../utils";
|
||||
|
||||
const EXPIRY_DAYS = 7;
|
||||
const MESSAGE_FORMAT =
|
||||
"[{timestamp}] [{message.id}] {user.username}#{user.discriminator}: {message.content}{attachments}";
|
||||
|
||||
function cleanExpiredLogs() {
|
||||
knex("spam_logs")
|
||||
.where("expires_at", "<=", knex.raw("NOW()"))
|
||||
.delete();
|
||||
}
|
||||
|
||||
cleanExpiredLogs();
|
||||
setInterval(cleanExpiredLogs, 1000 * 60 * 60); // Clean expired logs every hour
|
||||
|
||||
export class GuildSpamLogs {
|
||||
protected guildId: string;
|
||||
|
||||
constructor(guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
async find(id: string): Promise<SpamLog> {
|
||||
const result = await knex("spam_logs")
|
||||
.where("id", id)
|
||||
.first();
|
||||
|
||||
return result ? new SpamLog(result) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ID of the created spam log entry
|
||||
*/
|
||||
async createFromMessages(messages: Message[], header: string = null) {
|
||||
const lines = messages.map(msg => {
|
||||
return formatTemplateString(MESSAGE_FORMAT, {
|
||||
user: stripObjectToScalars(msg.author),
|
||||
message: stripObjectToScalars(msg),
|
||||
timestamp: moment(msg.timestamp).format("YYYY-MM-DD HH:mm:ss zz"),
|
||||
attachments: msg.attachments.length
|
||||
? ` (message contained ${msg.attachments.length} attachment(s))`
|
||||
: ""
|
||||
});
|
||||
});
|
||||
|
||||
const id = uuid();
|
||||
const now = moment().format("YYYY-MM-DD HH:mm:ss zz");
|
||||
const expiresAt = moment().add(EXPIRY_DAYS, "days");
|
||||
|
||||
const body = trimLines(`
|
||||
Log file generated on ${now}. Expires at ${expiresAt.format("YYYY-MM-DD HH:mm:ss zz")}.${
|
||||
header ? "\n" + header : ""
|
||||
}
|
||||
|
||||
${lines.join("\n")}
|
||||
`);
|
||||
|
||||
await knex("spam_logs").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