blob: 3bde0f226dbbf5c8dd0fca89f181645563a2f6bc [file] [log] [blame]
pineafan32767212022-03-14 21:27:39 +00001export const event = 'channelCreate'
2
3export async function callback(client, channel) {
pineafane625d782022-05-09 18:04:32 +01004 try {
5 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger
6 let auditLog = await getAuditLog(channel.guild, 'CHANNEL_CREATE');
7 let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first();
8 if (audit.executor.id == client.user.id) return;
9 let emoji;
10 let readableType;
11 let displayName;
12 switch (channel.type) {
13 case 'GUILD_TEXT': {
14 emoji = "CHANNEL.TEXT.CREATE";
15 readableType = "Text";
16 displayName = "Text Channel"
17 break;
18 }
19 case 'GUILD_NEWS': {
20 emoji = "CHANNEL.TEXT.CREATE";
21 readableType = "Announcement";
22 displayName = "Announcement Channel"
23 break;
24 }
25 case 'GUILD_VOICE': {
26 emoji = "CHANNEL.VOICE.CREATE";
27 readableType = "Voice";
28 displayName = "Voice Channel"
29 break;
30 }
31 case 'GUILD_STAGE': {
32 emoji = "CHANNEL.VOICE.CREATE";
33 readableType = "Stage";
34 displayName = "Stage Channel"
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 }
pineafan32767212022-03-14 21:27:39 +000047 }
pineafane625d782022-05-09 18:04:32 +010048 let 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 id: 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
67 }
pineafan32767212022-03-14 21:27:39 +000068 }
pineafan4edb7762022-06-26 19:21:04 +010069 log(data);
pineafane625d782022-05-09 18:04:32 +010070 } catch {}
pineafan32767212022-03-14 21:27:39 +000071}