pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | export const event = "channelCreate"; |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 2 | |
| 3 | export async function callback(client, channel) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 4 | const { |
| 5 | getAuditLog, |
| 6 | log, |
| 7 | NucleusColors, |
| 8 | entry, |
| 9 | renderUser, |
| 10 | renderDelta, |
| 11 | renderChannel |
| 12 | } = channel.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 13 | const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 14 | const audit = auditLog.entries |
| 15 | .filter((entry) => entry.target.id === channel.id) |
| 16 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 17 | if (audit.executor.id === client.user.id) return; |
| 18 | let emoji; |
| 19 | let readableType; |
| 20 | let displayName; |
| 21 | switch (channel.type) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | case "GUILD_TEXT": { |
| 23 | emoji = "CHANNEL.TEXT.CREATE"; |
| 24 | readableType = "Text"; |
| 25 | displayName = "Text Channel"; |
| 26 | break; |
| 27 | } |
| 28 | case "GUILD_NEWS": { |
| 29 | emoji = "CHANNEL.TEXT.CREATE"; |
| 30 | readableType = "Announcement"; |
| 31 | displayName = "Announcement Channel"; |
| 32 | break; |
| 33 | } |
| 34 | case "GUILD_VOICE": { |
| 35 | emoji = "CHANNEL.VOICE.CREATE"; |
| 36 | readableType = "Voice"; |
| 37 | displayName = "Voice Channel"; |
| 38 | break; |
| 39 | } |
| 40 | case "GUILD_STAGE": { |
| 41 | emoji = "CHANNEL.VOICE.CREATE"; |
| 42 | readableType = "Stage"; |
| 43 | displayName = "Stage Channel"; |
| 44 | break; |
| 45 | } |
| 46 | case "GUILD_CATEGORY": { |
| 47 | emoji = "CHANNEL.CATEGORY.CREATE"; |
| 48 | readableType = "Category"; |
| 49 | displayName = "Category"; |
| 50 | break; |
| 51 | } |
| 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 | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 75 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 76 | created: entry( |
| 77 | channel.createdTimestamp, |
| 78 | renderDelta(channel.createdTimestamp) |
| 79 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 80 | }, |
| 81 | hidden: { |
| 82 | guild: channel.guild.id |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 83 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 84 | }; |
| 85 | log(data); |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 86 | } |