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