blob: dda37aff0b0580cf2a56c481514d764ab6a6d57a [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) {
pineafan4e425942022-08-08 22:01:47 +01007 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
PineaFan538d3752023-01-12 21:48:23 +00008 const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelCreate))
9 .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id)[0];
10 if (!auditLog) return;
11 if (auditLog.executor!.id === client.user!.id) return;
pineafan63fc5e22022-08-04 22:04:10 +010012 let emoji;
13 let readableType;
14 let displayName;
15 switch (channel.type) {
PineaFan538d3752023-01-12 21:48:23 +000016 case ChannelType.GuildText: {
Skyler Grey75ea9172022-08-06 10:22:23 +010017 emoji = "CHANNEL.TEXT.CREATE";
18 readableType = "Text";
19 displayName = "Text Channel";
20 break;
21 }
PineaFan538d3752023-01-12 21:48:23 +000022 case ChannelType.GuildAnnouncement: {
Skyler Grey75ea9172022-08-06 10:22:23 +010023 emoji = "CHANNEL.TEXT.CREATE";
24 readableType = "Announcement";
25 displayName = "Announcement Channel";
26 break;
27 }
PineaFan538d3752023-01-12 21:48:23 +000028 case ChannelType.GuildVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010029 emoji = "CHANNEL.VOICE.CREATE";
30 readableType = "Voice";
31 displayName = "Voice Channel";
32 break;
33 }
PineaFan538d3752023-01-12 21:48:23 +000034 case ChannelType.GuildStageVoice: {
Skyler Grey75ea9172022-08-06 10:22:23 +010035 emoji = "CHANNEL.VOICE.CREATE";
36 readableType = "Stage";
37 displayName = "Stage Channel";
38 break;
39 }
PineaFan538d3752023-01-12 21:48:23 +000040 case ChannelType.GuildCategory: {
Skyler Grey75ea9172022-08-06 10:22:23 +010041 emoji = "CHANNEL.CATEGORY.CREATE";
42 readableType = "Category";
43 displayName = "Category";
44 break;
45 }
PineaFan538d3752023-01-12 21:48:23 +000046 case ChannelType.GuildForum: {
47 emoji = "CHANNEL.TEXT.CREATE";
48 readableType = "Forum";
49 displayName = "Forum Channel";
50 break;
51 }
Skyler Grey75ea9172022-08-06 10:22:23 +010052 default: {
53 emoji = "CHANNEL.TEXT.CREATE";
54 readableType = "Channel";
55 displayName = "Channel";
56 }
pineafan63fc5e22022-08-04 22:04:10 +010057 }
58 const data = {
59 meta: {
60 type: "channelCreate",
61 displayName: displayName + " Created",
62 calculateType: "channelUpdate",
63 color: NucleusColors.green,
64 emoji: emoji,
65 timestamp: channel.createdTimestamp
66 },
67 list: {
68 channelId: entry(channel.id, `\`${channel.id}\``),
69 name: entry(channel.name, renderChannel(channel)),
70 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010071 category: entry(
72 channel.parent ? channel.parent.id : null,
73 channel.parent ? channel.parent.name : "Uncategorised"
74 ),
PineaFan538d3752023-01-12 21:48:23 +000075 createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
76 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!))
pineafan63fc5e22022-08-04 22:04:10 +010077 },
78 hidden: {
79 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000080 }
pineafan63fc5e22022-08-04 22:04:10 +010081 };
82 log(data);
PineaFan538d3752023-01-12 21:48:23 +000083};