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"; |
| 3 | // @ts-expect-error |
| 4 | import { HaikuClient } from "jshaiku"; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | export const event = "channelCreate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 6 | |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 7 | export async function callback(client: HaikuClient, channel: GuildBasedChannel) { |
| 8 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 9 | const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE"); |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 10 | const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 11 | if (audit.executor.id === client.user.id) return; |
| 12 | let emoji; |
| 13 | let readableType; |
| 14 | let displayName; |
| 15 | switch (channel.type) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 16 | 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 | } |
pineafan | 4e42594 | 2022-08-08 22:01:47 +0100 | [diff] [blame] | 34 | case "GUILD_STAGE_VOICE": { |
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 | } |
| 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 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 51 | } |
| 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 Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 65 | category: entry( |
| 66 | channel.parent ? channel.parent.id : null, |
| 67 | channel.parent ? channel.parent.name : "Uncategorised" |
| 68 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 69 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 70 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 71 | }, |
| 72 | hidden: { |
| 73 | guild: channel.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 74 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 75 | }; |
| 76 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 77 | } |