blob: 883efd9ebe92fe3a167c49139735a88ecb43a66d [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) {
pineafane625d782022-05-09 18:04:32 +01006 try {
7 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger
8 let auditLog = await getAuditLog(channel.guild, 'CHANNEL_CREATE');
9 let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first();
10 if (audit.executor.id == client.user.id) return;
11 let emoji;
12 let readableType;
13 let displayName;
14 switch (channel.type) {
15 case 'GUILD_TEXT': {
16 emoji = "CHANNEL.TEXT.CREATE";
17 readableType = "Text";
18 displayName = "Text Channel"
19 break;
20 }
21 case 'GUILD_NEWS': {
22 emoji = "CHANNEL.TEXT.CREATE";
23 readableType = "Announcement";
24 displayName = "Announcement Channel"
25 break;
26 }
27 case 'GUILD_VOICE': {
28 emoji = "CHANNEL.VOICE.CREATE";
29 readableType = "Voice";
30 displayName = "Voice Channel"
31 break;
32 }
33 case 'GUILD_STAGE': {
34 emoji = "CHANNEL.VOICE.CREATE";
35 readableType = "Stage";
36 displayName = "Stage Channel"
37 }
38 case 'GUILD_CATEGORY': {
39 emoji = "CHANNEL.CATEGORY.CREATE";
40 readableType = "Category";
41 displayName = "Category"
42 break;
43 }
44 default: {
45 emoji = "CHANNEL.TEXT.CREATE";
46 readableType = "Channel";
47 displayName = "Channel"
48 }
pineafan32767212022-03-14 21:27:39 +000049 }
pineafane625d782022-05-09 18:04:32 +010050 let data = {
51 meta: {
52 type: 'channelCreate',
53 displayName: displayName + ' Created',
54 calculateType: 'channelUpdate',
55 color: NucleusColors.green,
56 emoji: emoji,
57 timestamp: channel.createdTimestamp
58 },
59 list: {
60 id: entry(channel.id, `\`${channel.id}\``),
61 name: entry(channel.name, renderChannel(channel)),
62 type: entry(channel.type, readableType),
63 category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"),
64 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
65 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
66 },
67 hidden: {
68 guild: channel.guild.id
69 }
pineafan32767212022-03-14 21:27:39 +000070 }
pineafane625d782022-05-09 18:04:32 +010071 log(data, channel.client);
72 } catch {}
pineafan32767212022-03-14 21:27:39 +000073}