blob: 8fd6b35d8cd1506210b7ba1024920bd0673fba2e [file] [log] [blame]
PineaFan538d3752023-01-12 21:48:23 +00001import { AuditLogEvent, ChannelType, GuildAuditLogsEntry } from "discord.js";
pineafan4e425942022-08-08 22:01:47 +01002import 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) {
TheCodedProf6ec331b2023-02-20 12:13:06 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
Skyler Greyda16adf2023-03-05 10:22:12 +00008 if (!(await isLogging(channel.guild.id, "channelUpdate"))) return;
9 const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelCreate)).filter(
10 (entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id
11 )[0];
PineaFan538d3752023-01-12 21:48:23 +000012 if (!auditLog) return;
13 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010014 let emoji;
15 let readableType;
16 let displayName;
17 switch (channel.type) {
PineaFan538d3752023-01-12 21:48:23 +000018 case ChannelType.GuildText: {
Skyler Grey75ea9172022-08-06 10:22:23 +010019 emoji = "CHANNEL.TEXT.CREATE";
20 readableType = "Text";
21 displayName = "Text Channel";
22 break;
23 }
PineaFan538d3752023-01-12 21:48:23 +000024 case ChannelType.GuildAnnouncement: {
Skyler Grey75ea9172022-08-06 10:22:23 +010025 emoji = "CHANNEL.TEXT.CREATE";
26 readableType = "Announcement";
27 displayName = "Announcement Channel";
28 break;
29 }
PineaFan538d3752023-01-12 21:48:23 +000030 case ChannelType.GuildVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010031 emoji = "CHANNEL.VOICE.CREATE";
32 readableType = "Voice";
33 displayName = "Voice Channel";
34 break;
35 }
PineaFan538d3752023-01-12 21:48:23 +000036 case ChannelType.GuildStageVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010037 emoji = "CHANNEL.VOICE.CREATE";
38 readableType = "Stage";
39 displayName = "Stage Channel";
40 break;
41 }
PineaFan538d3752023-01-12 21:48:23 +000042 case ChannelType.GuildCategory: {
Skyler Grey75ea9172022-08-06 10:22:23 +010043 emoji = "CHANNEL.CATEGORY.CREATE";
44 readableType = "Category";
45 displayName = "Category";
46 break;
47 }
PineaFan538d3752023-01-12 21:48:23 +000048 case ChannelType.GuildForum: {
49 emoji = "CHANNEL.TEXT.CREATE";
50 readableType = "Forum";
51 displayName = "Forum Channel";
52 break;
53 }
Skyler Grey75ea9172022-08-06 10:22:23 +010054 default: {
55 emoji = "CHANNEL.TEXT.CREATE";
56 readableType = "Channel";
57 displayName = "Channel";
58 }
pineafan63fc5e22022-08-04 22:04:10 +010059 }
60 const data = {
61 meta: {
62 type: "channelCreate",
63 displayName: displayName + " Created",
64 calculateType: "channelUpdate",
65 color: NucleusColors.green,
66 emoji: emoji,
TheCodedProf6ec331b2023-02-20 12:13:06 -050067 timestamp: channel.createdTimestamp ?? Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010068 },
69 list: {
70 channelId: entry(channel.id, `\`${channel.id}\``),
71 name: entry(channel.name, renderChannel(channel)),
72 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010073 category: entry(
74 channel.parent ? channel.parent.id : null,
75 channel.parent ? channel.parent.name : "Uncategorised"
76 ),
PineaFan538d3752023-01-12 21:48:23 +000077 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
78 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!))
pineafan63fc5e22022-08-04 22:04:10 +010079 },
80 hidden: {
81 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000082 }
pineafan63fc5e22022-08-04 22:04:10 +010083 };
Skyler Greyf4f21c42023-03-08 14:36:29 +000084 await log(data);
Skyler Greyda16adf2023-03-05 10:22:12 +000085}