pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 1 | import type { GuildAuditLogsEntry } from "discord.js"; |
| 2 | import type { GuildBasedChannel } from "discord.js"; |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame^] | 3 | import type { HaikuClient } from "../utils/haiku/index.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 | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 8 | const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE"); |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 9 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 10 | if (audit.executor.id === client.user.id) return; |
| 11 | let emoji; |
| 12 | let readableType; |
| 13 | let displayName; |
| 14 | switch (channel.type) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | case "GUILD_TEXT": { |
| 16 | emoji = "CHANNEL.TEXT.CREATE"; |
| 17 | readableType = "Text"; |
| 18 | displayName = "Text Channel"; |
| 19 | break; |
| 20 | } |
| 21 | case "GUILD_NEWS": { |
| 22 | emoji = "CHANNEL.TEXT.CREATE"; |
| 23 | readableType = "Announcement"; |
| 24 | displayName = "Announcement Channel"; |
| 25 | break; |
| 26 | } |
| 27 | case "GUILD_VOICE": { |
| 28 | emoji = "CHANNEL.VOICE.CREATE"; |
| 29 | readableType = "Voice"; |
| 30 | displayName = "Voice Channel"; |
| 31 | break; |
| 32 | } |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 33 | case "GUILD_STAGE_VOICE": { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 34 | emoji = "CHANNEL.VOICE.CREATE"; |
| 35 | readableType = "Stage"; |
| 36 | displayName = "Stage Channel"; |
| 37 | break; |
| 38 | } |
| 39 | case "GUILD_CATEGORY": { |
| 40 | emoji = "CHANNEL.CATEGORY.CREATE"; |
| 41 | readableType = "Category"; |
| 42 | displayName = "Category"; |
| 43 | break; |
| 44 | } |
| 45 | default: { |
| 46 | emoji = "CHANNEL.TEXT.CREATE"; |
| 47 | readableType = "Channel"; |
| 48 | displayName = "Channel"; |
| 49 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 50 | } |
| 51 | const data = { |
| 52 | meta: { |
| 53 | type: "channelCreate", |
| 54 | displayName: displayName + " Created", |
| 55 | calculateType: "channelUpdate", |
| 56 | color: NucleusColors.green, |
| 57 | emoji: emoji, |
| 58 | timestamp: channel.createdTimestamp |
| 59 | }, |
| 60 | list: { |
| 61 | channelId: entry(channel.id, `\`${channel.id}\``), |
| 62 | name: entry(channel.name, renderChannel(channel)), |
| 63 | type: entry(channel.type, readableType), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 64 | category: entry( |
| 65 | channel.parent ? channel.parent.id : null, |
| 66 | channel.parent ? channel.parent.name : "Uncategorised" |
| 67 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 68 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 69 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 70 | }, |
| 71 | hidden: { |
| 72 | guild: channel.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 73 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 74 | }; |
| 75 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 76 | } |