pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | export const event = 'channelCreate' |
| 2 | |
| 3 | export async function callback(client, channel) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 4 | try { |
| 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger |
| 6 | let auditLog = await getAuditLog(channel.guild, 'CHANNEL_CREATE'); |
| 7 | let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first(); |
| 8 | if (audit.executor.id == client.user.id) return; |
| 9 | let emoji; |
| 10 | let readableType; |
| 11 | let displayName; |
| 12 | switch (channel.type) { |
| 13 | case 'GUILD_TEXT': { |
| 14 | emoji = "CHANNEL.TEXT.CREATE"; |
| 15 | readableType = "Text"; |
| 16 | displayName = "Text Channel" |
| 17 | break; |
| 18 | } |
| 19 | case 'GUILD_NEWS': { |
| 20 | emoji = "CHANNEL.TEXT.CREATE"; |
| 21 | readableType = "Announcement"; |
| 22 | displayName = "Announcement Channel" |
| 23 | break; |
| 24 | } |
| 25 | case 'GUILD_VOICE': { |
| 26 | emoji = "CHANNEL.VOICE.CREATE"; |
| 27 | readableType = "Voice"; |
| 28 | displayName = "Voice Channel" |
| 29 | break; |
| 30 | } |
| 31 | case 'GUILD_STAGE': { |
| 32 | emoji = "CHANNEL.VOICE.CREATE"; |
| 33 | readableType = "Stage"; |
| 34 | displayName = "Stage Channel" |
| 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 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 47 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 48 | let 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 | id: 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 |
| 67 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 68 | } |
pineafan | 4edb776 | 2022-06-26 19:21:04 +0100 | [diff] [blame^] | 69 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 70 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 71 | } |