blob: b3cba33aff62c2f19b2a4119d7575812387417cf [file] [log] [blame]
pineafan4e425942022-08-08 22:01:47 +01001import type { GuildAuditLogsEntry } from "discord.js";
2import type { GuildBasedChannel } from "discord.js";
PineaFan752af462022-12-31 21:59:38 +00003import type { NucleusClient } from "../utils/client.js";
pineafan63fc5e22022-08-04 22:04:10 +01004export const event = "channelCreate";
pineafan32767212022-03-14 21:27:39 +00005
PineaFan64486c42022-12-28 09:21:04 +00006export async function callback(client: NucleusClient, channel: GuildBasedChannel) {
pineafan4e425942022-08-08 22:01:47 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01008 const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
pineafan4e425942022-08-08 22:01:47 +01009 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010010 if (audit.executor.id === client.user.id) return;
11 let emoji;
12 let readableType;
13 let displayName;
14 switch (channel.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010015 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 }
pineafan4e425942022-08-08 22:01:47 +010033 case "GUILD_STAGE_VOICE": {
Skyler Grey75ea9172022-08-06 10:22:23 +010034 emoji = "CHANNEL.VOICE.CREATE";
35 readableType = "Stage";
36 displayName = "Stage Channel";
37 break;
38 }
39 case "GUILD_CATEGORY": {
40 emoji = "CHANNEL.CATEGORY.CREATE";
41 readableType = "Category";
42 displayName = "Category";
43 break;
44 }
45 default: {
46 emoji = "CHANNEL.TEXT.CREATE";
47 readableType = "Channel";
48 displayName = "Channel";
49 }
pineafan63fc5e22022-08-04 22:04:10 +010050 }
51 const data = {
52 meta: {
53 type: "channelCreate",
54 displayName: displayName + " Created",
55 calculateType: "channelUpdate",
56 color: NucleusColors.green,
57 emoji: emoji,
58 timestamp: channel.createdTimestamp
59 },
60 list: {
61 channelId: entry(channel.id, `\`${channel.id}\``),
62 name: entry(channel.name, renderChannel(channel)),
63 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010064 category: entry(
65 channel.parent ? channel.parent.id : null,
66 channel.parent ? channel.parent.name : "Uncategorised"
67 ),
pineafan63fc5e22022-08-04 22:04:10 +010068 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010069 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010070 },
71 hidden: {
72 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000073 }
pineafan63fc5e22022-08-04 22:04:10 +010074 };
75 log(data);
pineafan32767212022-03-14 21:27:39 +000076}