You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Nucleus/src/events/messageDelete.ts

70 lines
2.9 KiB

3 years ago
// @ts-expect-error
import type { HaikuClient } from "jshaiku";
import type { GuildAuditLogsEntry, Message } from "discord.js";
export const event = "messageDelete";
4 years ago
3 years ago
export async function callback(client: HaikuClient, message: Message) {
4 years ago
try {
if (message.author.id === client.user.id) return;
3 years ago
if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
3 years ago
const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === message.author.id).first();
4 years ago
if (audit) {
if (audit.createdAt - 100 < new Date().getTime()) return;
4 years ago
}
3 years ago
const replyTo = message.reference;
let content = message.cleanContent;
content.replace("`", "\\`");
if (content.length > 256) content = content.substring(0, 253) + "...";
const attachments =
message.attachments.size +
(
message.content.match(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
) ?? []
).length;
let attachmentJump = "";
3 years ago
const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
message.channel.id + message.id
];
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
const data = {
4 years ago
meta: {
type: "messageDelete",
displayName: "Message Deleted",
calculateType: "messageDelete",
4 years ago
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
4 years ago
timestamp: new Date().getTime()
},
separate: {
start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
4 years ago
},
list: {
messageId: entry(message.id, `\`${message.id}\``),
4 years ago
sentBy: entry(message.author.id, renderUser(message.author)),
sentIn: entry(message.channel.id, renderChannel(message.channel)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
4 years ago
mentions: message.mentions.users.size,
3 years ago
attachments: entry(attachments, attachments + attachmentJump),
4 years ago
repliedTo: entry(
3 years ago
replyTo,
replyTo
? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
: "None"
4 years ago
)
},
hidden: {
3 years ago
guild: message.guild!.id
4 years ago
}
};
log(data);
} catch (e) {
console.log(e);
}
4 years ago
}