blob: 7350ebdf83bfac283e368bcd460a469a6e736bd6 [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 Grey75ea9172022-08-06 10:22:23 +01004 const {
5 getAuditLog,
6 log,
7 NucleusColors,
8 entry,
9 renderUser,
10 renderDelta,
11 renderChannel
12 } = channel.client.logger;
pineafan63fc5e22022-08-04 22:04:10 +010013 const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
Skyler Grey75ea9172022-08-06 10:22:23 +010014 const audit = auditLog.entries
15 .filter((entry) => entry.target.id === channel.id)
16 .first();
pineafan63fc5e22022-08-04 22:04:10 +010017 if (audit.executor.id === client.user.id) return;
18 let emoji;
19 let readableType;
20 let displayName;
21 switch (channel.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010022 case "GUILD_TEXT": {
23 emoji = "CHANNEL.TEXT.CREATE";
24 readableType = "Text";
25 displayName = "Text Channel";
26 break;
27 }
28 case "GUILD_NEWS": {
29 emoji = "CHANNEL.TEXT.CREATE";
30 readableType = "Announcement";
31 displayName = "Announcement Channel";
32 break;
33 }
34 case "GUILD_VOICE": {
35 emoji = "CHANNEL.VOICE.CREATE";
36 readableType = "Voice";
37 displayName = "Voice Channel";
38 break;
39 }
40 case "GUILD_STAGE": {
41 emoji = "CHANNEL.VOICE.CREATE";
42 readableType = "Stage";
43 displayName = "Stage Channel";
44 break;
45 }
46 case "GUILD_CATEGORY": {
47 emoji = "CHANNEL.CATEGORY.CREATE";
48 readableType = "Category";
49 displayName = "Category";
50 break;
51 }
52 default: {
53 emoji = "CHANNEL.TEXT.CREATE";
54 readableType = "Channel";
55 displayName = "Channel";
56 }
pineafan63fc5e22022-08-04 22:04:10 +010057 }
58 const data = {
59 meta: {
60 type: "channelCreate",
61 displayName: displayName + " Created",
62 calculateType: "channelUpdate",
63 color: NucleusColors.green,
64 emoji: emoji,
65 timestamp: channel.createdTimestamp
66 },
67 list: {
68 channelId: entry(channel.id, `\`${channel.id}\``),
69 name: entry(channel.name, renderChannel(channel)),
70 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010071 category: entry(
72 channel.parent ? channel.parent.id : null,
73 channel.parent ? channel.parent.name : "Uncategorised"
74 ),
pineafan63fc5e22022-08-04 22:04:10 +010075 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey75ea9172022-08-06 10:22:23 +010076 created: entry(
77 channel.createdTimestamp,
78 renderDelta(channel.createdTimestamp)
79 )
pineafan63fc5e22022-08-04 22:04:10 +010080 },
81 hidden: {
82 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000083 }
pineafan63fc5e22022-08-04 22:04:10 +010084 };
85 log(data);
pineafan32767212022-03-14 21:27:39 +000086}