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) { |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 7 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 8 | 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; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 12 | let emoji; |
| 13 | let readableType; |
| 14 | let displayName; |
| 15 | switch (channel.type) { |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 16 | case ChannelType.GuildText: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 17 | emoji = "CHANNEL.TEXT.CREATE"; |
| 18 | readableType = "Text"; |
| 19 | displayName = "Text Channel"; |
| 20 | break; |
| 21 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 22 | case ChannelType.GuildAnnouncement: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 23 | emoji = "CHANNEL.TEXT.CREATE"; |
| 24 | readableType = "Announcement"; |
| 25 | displayName = "Announcement Channel"; |
| 26 | break; |
| 27 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 28 | case ChannelType.GuildVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 29 | emoji = "CHANNEL.VOICE.CREATE"; |
| 30 | readableType = "Voice"; |
| 31 | displayName = "Voice Channel"; |
| 32 | break; |
| 33 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 34 | case ChannelType.GuildStageVoice: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 35 | emoji = "CHANNEL.VOICE.CREATE"; |
| 36 | readableType = "Stage"; |
| 37 | displayName = "Stage Channel"; |
| 38 | break; |
| 39 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 40 | case ChannelType.GuildCategory: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 41 | emoji = "CHANNEL.CATEGORY.CREATE"; |
| 42 | readableType = "Category"; |
| 43 | displayName = "Category"; |
| 44 | break; |
| 45 | } |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 46 | case ChannelType.GuildForum: { |
| 47 | emoji = "CHANNEL.TEXT.CREATE"; |
| 48 | readableType = "Forum"; |
| 49 | displayName = "Forum Channel"; |
| 50 | break; |
| 51 | } |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 52 | default: { |
| 53 | emoji = "CHANNEL.TEXT.CREATE"; |
| 54 | readableType = "Channel"; |
| 55 | displayName = "Channel"; |
| 56 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 57 | } |
| 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 71 | category: entry( |
| 72 | channel.parent ? channel.parent.id : null, |
| 73 | channel.parent ? channel.parent.name : "Uncategorised" |
| 74 | ), |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 75 | createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)), |
| 76 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 77 | }, |
| 78 | hidden: { |
| 79 | guild: channel.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 80 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 81 | }; |
| 82 | log(data); |
PineaFan | 538d375 | 2023-01-12 21:48:23 +0000 | [diff] [blame^] | 83 | }; |