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