blob: c4c13479e65a1f828b135650eddc4cc161cb10d7 [file] [log] [blame]
pineafan63fc5e22022-08-04 22:04:10 +01001export const event = "channelCreate";
pineafan32767212022-03-14 21:27:39 +00002
3export async function callback(client, channel) {
pineafan63fc5e22022-08-04 22:04:10 +01004 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger;
5 const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
6 const audit = auditLog.entries.filter(entry => entry.target.id === channel.id).first();
7 if (audit.executor.id === client.user.id) return;
8 let emoji;
9 let readableType;
10 let displayName;
11 switch (channel.type) {
12 case "GUILD_TEXT": {
13 emoji = "CHANNEL.TEXT.CREATE";
14 readableType = "Text";
15 displayName = "Text Channel";
16 break;
17 }
18 case "GUILD_NEWS": {
19 emoji = "CHANNEL.TEXT.CREATE";
20 readableType = "Announcement";
21 displayName = "Announcement Channel";
22 break;
23 }
24 case "GUILD_VOICE": {
25 emoji = "CHANNEL.VOICE.CREATE";
26 readableType = "Voice";
27 displayName = "Voice Channel";
28 break;
29 }
30 case "GUILD_STAGE": {
31 emoji = "CHANNEL.VOICE.CREATE";
32 readableType = "Stage";
33 displayName = "Stage Channel";
34 break;
35 }
36 case "GUILD_CATEGORY": {
37 emoji = "CHANNEL.CATEGORY.CREATE";
38 readableType = "Category";
39 displayName = "Category";
40 break;
41 }
42 default: {
43 emoji = "CHANNEL.TEXT.CREATE";
44 readableType = "Channel";
45 displayName = "Channel";
46 }
47 }
48 const data = {
49 meta: {
50 type: "channelCreate",
51 displayName: displayName + " Created",
52 calculateType: "channelUpdate",
53 color: NucleusColors.green,
54 emoji: emoji,
55 timestamp: channel.createdTimestamp
56 },
57 list: {
58 channelId: entry(channel.id, `\`${channel.id}\``),
59 name: entry(channel.name, renderChannel(channel)),
60 type: entry(channel.type, readableType),
61 category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"),
62 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
63 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
64 },
65 hidden: {
66 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000067 }
pineafan63fc5e22022-08-04 22:04:10 +010068 };
69 log(data);
pineafan32767212022-03-14 21:27:39 +000070}