-
Notifications
You must be signed in to change notification settings - Fork 13
/
logging.js
30 lines (28 loc) · 987 Bytes
/
logging.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import CONSTANTS from "../CONSTANTS.js";
export const LOG_GROUPS = /** @type {const} */ ([
"server",
"messages",
"channels",
"members",
"voice",
]);
/**
* @param {string} content
* @param {typeof LOG_GROUPS[number]} group
* @param {Pick<import("discord.js").BaseMessageOptions, "embeds" | "files" | "components">} [extra]
*/
export default async function log(content, group, extra = {}) {
const thread = await getLoggingThread(group);
return await thread.send({ ...extra, content, allowedMentions: { users: [] } });
}
/** @param {typeof LOG_GROUPS[number] | typeof import("../database").DATABASE_THREAD} group */
export async function getLoggingThread(group) {
if (!CONSTANTS.channels.modlogs) throw new ReferenceError("Cannot find logs channel");
const threads = await CONSTANTS.channels.modlogs.threads.fetchActive();
return (
threads.threads.find((thread) => thread.name === group) ||
(await CONSTANTS.channels.modlogs.threads.create({
name: group,
}))
);
}