blob: 2aa8ec73587903108bf39d640007aceab5212625 [file] [log] [blame]
pineafan4e425942022-08-08 22:01:47 +01001import type { GuildAuditLogsEntry } from "discord.js";
2import type { GuildBasedChannel } from "discord.js";
3// @ts-expect-error
4import { HaikuClient } from "jshaiku";
pineafan63fc5e22022-08-04 22:04:10 +01005export const event = "channelCreate";
pineafan32767212022-03-14 21:27:39 +00006
pineafan4e425942022-08-08 22:01:47 +01007export async function callback(client: HaikuClient, channel: GuildBasedChannel) {
8 const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
pineafan63fc5e22022-08-04 22:04:10 +01009 const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
pineafan4e425942022-08-08 22:01:47 +010010 const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
pineafan63fc5e22022-08-04 22:04:10 +010011 if (audit.executor.id === client.user.id) return;
12 let emoji;
13 let readableType;
14 let displayName;
15 switch (channel.type) {
Skyler Grey75ea9172022-08-06 10:22:23 +010016 case "GUILD_TEXT": {
17 emoji = "CHANNEL.TEXT.CREATE";
18 readableType = "Text";
19 displayName = "Text Channel";
20 break;
21 }
22 case "GUILD_NEWS": {
23 emoji = "CHANNEL.TEXT.CREATE";
24 readableType = "Announcement";
25 displayName = "Announcement Channel";
26 break;
27 }
28 case "GUILD_VOICE": {
29 emoji = "CHANNEL.VOICE.CREATE";
30 readableType = "Voice";
31 displayName = "Voice Channel";
32 break;
33 }
pineafan4e425942022-08-08 22:01:47 +010034 case "GUILD_STAGE_VOICE": {
Skyler Grey75ea9172022-08-06 10:22:23 +010035 emoji = "CHANNEL.VOICE.CREATE";
36 readableType = "Stage";
37 displayName = "Stage Channel";
38 break;
39 }
40 case "GUILD_CATEGORY": {
41 emoji = "CHANNEL.CATEGORY.CREATE";
42 readableType = "Category";
43 displayName = "Category";
44 break;
45 }
46 default: {
47 emoji = "CHANNEL.TEXT.CREATE";
48 readableType = "Channel";
49 displayName = "Channel";
50 }
pineafan63fc5e22022-08-04 22:04:10 +010051 }
52 const data = {
53 meta: {
54 type: "channelCreate",
55 displayName: displayName + " Created",
56 calculateType: "channelUpdate",
57 color: NucleusColors.green,
58 emoji: emoji,
59 timestamp: channel.createdTimestamp
60 },
61 list: {
62 channelId: entry(channel.id, `\`${channel.id}\``),
63 name: entry(channel.name, renderChannel(channel)),
64 type: entry(channel.type, readableType),
Skyler Grey75ea9172022-08-06 10:22:23 +010065 category: entry(
66 channel.parent ? channel.parent.id : null,
67 channel.parent ? channel.parent.name : "Uncategorised"
68 ),
pineafan63fc5e22022-08-04 22:04:10 +010069 createdBy: entry(audit.executor.id, renderUser(audit.executor)),
Skyler Grey11236ba2022-08-08 21:13:33 +010070 created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
pineafan63fc5e22022-08-04 22:04:10 +010071 },
72 hidden: {
73 guild: channel.guild.id
pineafan32767212022-03-14 21:27:39 +000074 }
pineafan63fc5e22022-08-04 22:04:10 +010075 };
76 log(data);
pineafan32767212022-03-14 21:27:39 +000077}