PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 1 | import { AuditLogEvent, ChannelType, GuildAuditLogsEntry } from "discord.js"; |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 2 | import type { GuildBasedChannel } from "discord.js"; |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame] | 3 | import type { NucleusClient } from "../utils/client.js"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 4 | export const event = "channelCreate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 5 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 6 | export async function callback(client: NucleusClient, channel: GuildBasedChannel) { |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 7 | const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
| 8 | if (!await isLogging(channel.guild.id, "channelUpdate")) return; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 9 | 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; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | let emoji; |
| 14 | let readableType; |
| 15 | let displayName; |
| 16 | switch (channel.type) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 17 | case ChannelType.GuildText: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 18 | emoji = "CHANNEL.TEXT.CREATE"; |
| 19 | readableType = "Text"; |
| 20 | displayName = "Text Channel"; |
| 21 | break; |
| 22 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 23 | case ChannelType.GuildAnnouncement: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 24 | emoji = "CHANNEL.TEXT.CREATE"; |
| 25 | readableType = "Announcement"; |
| 26 | displayName = "Announcement Channel"; |
| 27 | break; |
| 28 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 29 | case ChannelType.GuildVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 30 | emoji = "CHANNEL.VOICE.CREATE"; |
| 31 | readableType = "Voice"; |
| 32 | displayName = "Voice Channel"; |
| 33 | break; |
| 34 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 35 | case ChannelType.GuildStageVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 36 | emoji = "CHANNEL.VOICE.CREATE"; |
| 37 | readableType = "Stage"; |
| 38 | displayName = "Stage Channel"; |
| 39 | break; |
| 40 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 41 | case ChannelType.GuildCategory: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 42 | emoji = "CHANNEL.CATEGORY.CREATE"; |
| 43 | readableType = "Category"; |
| 44 | displayName = "Category"; |
| 45 | break; |
| 46 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 47 | case ChannelType.GuildForum: { |
| 48 | emoji = "CHANNEL.TEXT.CREATE"; |
| 49 | readableType = "Forum"; |
| 50 | displayName = "Forum Channel"; |
| 51 | break; |
| 52 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 53 | default: { |
| 54 | emoji = "CHANNEL.TEXT.CREATE"; |
| 55 | readableType = "Channel"; |
| 56 | displayName = "Channel"; |
| 57 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 58 | } |
| 59 | const data = { |
| 60 | meta: { |
| 61 | type: "channelCreate", |
| 62 | displayName: displayName + " Created", |
| 63 | calculateType: "channelUpdate", |
| 64 | color: NucleusColors.green, |
| 65 | emoji: emoji, |
Samuel Shuert | 27bf3cd | 2023-03-03 15:51:25 -0500 | [diff] [blame] | 66 | timestamp: channel.createdTimestamp ?? Date.now() |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 67 | }, |
| 68 | list: { |
| 69 | channelId: entry(channel.id, `\`${channel.id}\``), |
| 70 | name: entry(channel.name, renderChannel(channel)), |
| 71 | type: entry(channel.type, readableType), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 72 | category: entry( |
| 73 | channel.parent ? channel.parent.id : null, |
| 74 | channel.parent ? channel.parent.name : "Uncategorised" |
| 75 | ), |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 76 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 77 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 78 | }, |
| 79 | hidden: { |
| 80 | guild: channel.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 81 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 82 | }; |
| 83 | log(data); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame] | 84 | }; |