pineafan | 3276721 | 2022-03-14 21:27:39 +0000 | [diff] [blame^] | 1 | export const event = 'channelDelete' |
| 2 | |
| 3 | export async function callback(client, channel) { |
| 4 | const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = channel.client.logger |
| 5 | |
| 6 | let auditLog = await getAuditLog(channel.guild, 'CHANNEL_DELETE'); |
| 7 | let audit = auditLog.entries.filter(entry => entry.target.id == channel.id).first(); |
| 8 | if (audit.executor.id == client.user.id) return; |
| 9 | |
| 10 | let emoji; |
| 11 | let readableType; |
| 12 | let displayName; |
| 13 | switch (channel.type) { |
| 14 | case 'GUILD_TEXT': { |
| 15 | emoji = "CHANNEL.TEXT.DELETE"; |
| 16 | readableType = "Text"; |
| 17 | displayName = "Text Channel" |
| 18 | break; |
| 19 | } |
| 20 | case 'GUILD_VOICE': { |
| 21 | emoji = "CHANNEL.VOICE.DELETE"; |
| 22 | readableType = "Voice"; |
| 23 | displayName = "Voice Channel" |
| 24 | break; |
| 25 | } |
| 26 | case 'GUILD_CATEGORY': { |
| 27 | emoji = "CHANNEL.CATEGORY.DELETE"; |
| 28 | readableType = "Category"; |
| 29 | displayName = "Category" |
| 30 | break; |
| 31 | } |
| 32 | default: { |
| 33 | emoji = "CHANNEL.TEXT.DELETE"; |
| 34 | readableType = "Channel"; |
| 35 | displayName = "Channel" |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | let data = { |
| 40 | meta:{ |
| 41 | type: 'channelDelete', |
| 42 | displayName: displayName + ' Deleted', |
| 43 | calculateType: 'channelUpdate', |
| 44 | color: NucleusColors.red, |
| 45 | emoji: emoji, |
| 46 | timestamp: audit.createdTimestamp |
| 47 | }, |
| 48 | list: { // TODO: Add stuff like nsfw, theres loads missing here |
| 49 | id: entry(channel.id, `\`${channel.id}\``), |
| 50 | name: entry(channel.id, `${channel.name}`), |
| 51 | type: entry(channel.type, readableType), |
| 52 | category: entry(channel.parent ? channel.parent.id : null, channel.parent ? channel.parent.name : "Uncategorised"), |
| 53 | created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp)), |
| 54 | deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())), |
| 55 | deletedBy: entry(audit.executor.id, renderUser(audit.executor)) |
| 56 | }, |
| 57 | hidden: { |
| 58 | guild: channel.guild.id |
| 59 | } |
| 60 | } |
| 61 | log(data, channel.client); |
| 62 | } |