blob: b42ded729b302ff64e872e995b62b76ac6c8e889 [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) {
Samuel Shuert27bf3cd2023-03-03 15:51:25 -05007 const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
8 if (!await isLogging(channel.guild.id, "channelUpdate")) return;
PineaFan538d3752023-01-12 21:48:23 +00009 const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelCreate))
10 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id)[0];
11 if (!auditLog) return;
12 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010013 let emoji;
14 let readableType;
15 let displayName;
16 switch (channel.type) {
PineaFan538d3752023-01-12 21:48:23 +000017 case ChannelType.GuildText: {
Skyler Grey75ea9172022-08-06 10:22:23 +010018 emoji = "CHANNEL.TEXT.CREATE";
19 readableType = "Text";
20 displayName = "Text Channel";
21 break;
22 }
PineaFan538d3752023-01-12 21:48:23 +000023 case ChannelType.GuildAnnouncement: {
Skyler Grey75ea9172022-08-06 10:22:23 +010024 emoji = "CHANNEL.TEXT.CREATE";
25 readableType = "Announcement";
26 displayName = "Announcement Channel";
27 break;
28 }
PineaFan538d3752023-01-12 21:48:23 +000029 case ChannelType.GuildVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010030 emoji = "CHANNEL.VOICE.CREATE";
31 readableType = "Voice";
32 displayName = "Voice Channel";
33 break;
34 }
PineaFan538d3752023-01-12 21:48:23 +000035 case ChannelType.GuildStageVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010036 emoji = "CHANNEL.VOICE.CREATE";
37 readableType = "Stage";
38 displayName = "Stage Channel";
39 break;
40 }
PineaFan538d3752023-01-12 21:48:23 +000041 case ChannelType.GuildCategory: {
Skyler Grey75ea9172022-08-06 10:22:23 +010042 emoji = "CHANNEL.CATEGORY.CREATE";
43 readableType = "Category";
44 displayName = "Category";
45 break;
46 }
PineaFan538d3752023-01-12 21:48:23 +000047 case ChannelType.GuildForum: {
48 emoji = "CHANNEL.TEXT.CREATE";
49 readableType = "Forum";
50 displayName = "Forum Channel";
51 break;
52 }
Skyler Grey75ea9172022-08-06 10:22:23 +010053 default: {
54 emoji = "CHANNEL.TEXT.CREATE";
55 readableType = "Channel";
56 displayName = "Channel";
57 }
pineafan63fc5e22022-08-04 22:04:10 +010058 }
59 const data = {
60 meta: {
61 type: "channelCreate",
62 displayName: displayName + " Created",
63 calculateType: "channelUpdate",
64 color: NucleusColors.green,
65 emoji: emoji,
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050066 timestamp: channel.createdTimestamp ?? Date.now()
pineafan63fc5e22022-08-04 22:04:10 +010067 },
68 list: {
69 channelId: entry(channel.id, `\`${channel.id}\``),
70 name: entry(channel.name, renderChannel(channel)),
71 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010072 category: entry(
73 channel.parent ? channel.parent.id : null,
74 channel.parent ? channel.parent.name : "Uncategorised"
75 ),
PineaFan538d3752023-01-12 21:48:23 +000076 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
77 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!))
pineafan63fc5e22022-08-04 22:04:10 +010078 },
79 hidden: {
80 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000081 }
pineafan63fc5e22022-08-04 22:04:10 +010082 };
83 log(data);
PineaFan538d3752023-01-12 21:48:23 +000084};