pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 1 | import { Interaction } from "discord.js"; |
| 2 | |
| 3 | export const event = 'channelCreate' |
| 4 | |
| 5 | export async function callback(client, channel) { |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 6 | try { |
| 7 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger |
| 8 | let auditLog = await getAuditLog(channel.guild, 'CHANNEL_CREATE'); |
| 9 | let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first(); |
| 10 | if (audit.executor.id == client.user.id) return; |
| 11 | let emoji; |
| 12 | let readableType; |
| 13 | let displayName; |
| 14 | switch (channel.type) { |
| 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 | } |
| 33 | case 'GUILD_STAGE': { |
| 34 | emoji = "CHANNEL.VOICE.CREATE"; |
| 35 | readableType = "Stage"; |
| 36 | displayName = "Stage Channel" |
| 37 | } |
| 38 | case 'GUILD_CATEGORY': { |
| 39 | emoji = "CHANNEL.CATEGORY.CREATE"; |
| 40 | readableType = "Category"; |
| 41 | displayName = "Category" |
| 42 | break; |
| 43 | } |
| 44 | default: { |
| 45 | emoji = "CHANNEL.TEXT.CREATE"; |
| 46 | readableType = "Channel"; |
| 47 | displayName = "Channel" |
| 48 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 49 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 50 | let data = { |
| 51 | meta: { |
| 52 | type: 'channelCreate', |
| 53 | displayName: displayName + ' Created', |
| 54 | calculateType: 'channelUpdate', |
| 55 | color: NucleusColors.green, |
| 56 | emoji: emoji, |
| 57 | timestamp: channel.createdTimestamp |
| 58 | }, |
| 59 | list: { |
| 60 | id: entry(channel.id, `\`${channel.id}\``), |
| 61 | name: entry(channel.name, renderChannel(channel)), |
| 62 | type: entry(channel.type, readableType), |
| 63 | category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"), |
| 64 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 65 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)) |
| 66 | }, |
| 67 | hidden: { |
| 68 | guild: channel.guild.id |
| 69 | } |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 70 | } |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 71 | log(data, channel.client); |
| 72 | } catch {} |
pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame] | 73 | } |