blob: 19f5c9b8de87115599b2e4b177dd0adec700429c [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) {
Skyler Grey11236ba2022-08-08 21:13:33 +01004 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01005 const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
Skyler Grey11236ba2022-08-08 21:13:33 +01006 const audit = auditLog.entries.filter((entry) => entry.target.id === channel.id).first();
pineafan63fc5e22022-08-04 22:04:10 +01007 if (audit.executor.id === client.user.id) return;
8 let emoji;
9 let readableType;
10 let displayName;
11 switch (channel.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010012 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 }
pineafan63fc5e22022-08-04 22:04:10 +010047 }
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),
Skyler Grey75ea9172022-08-06 10:22:23 +010061 category: entry(
62 channel.parent ? channel.parent.id : null,
63 channel.parent ? channel.parent.name : "Uncategorised"
64 ),
pineafan63fc5e22022-08-04 22:04:10 +010065 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010066 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010067 },
68 hidden: {
69 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000070 }
pineafan63fc5e22022-08-04 22:04:10 +010071 };
72 log(data);
pineafan32767212022-03-14 21:27:39 +000073}