pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 1 | import humanizeDuration from "humanize-duration"; |
| 2 | export const event = "threadCreate"; |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 3 | |
| 4 | export async function callback(client, thread) { |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger; |
| 6 | const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE"); |
| 7 | const audit = auditLog.entries.filter(entry => entry.target.id === thread.id).first(); |
| 8 | if (audit.executor.id === client.user.id) return; |
| 9 | const data = { |
| 10 | meta: { |
| 11 | type: "channelCreate", |
| 12 | displayName: "Thread Created", |
| 13 | calculateType: "channelUpdate", |
| 14 | color: NucleusColors.green, |
| 15 | emoji: "CHANNEL.TEXT.CREATE", |
| 16 | timestamp: thread.createdTimestamp |
| 17 | }, |
| 18 | list: { |
| 19 | threadId:entry(thread.id, `\`${thread.id}\``), |
| 20 | name: entry(thread.name, renderChannel(thread)), |
| 21 | parentChannel: entry(thread.parentId, renderChannel(thread.parent)), |
| 22 | category: entry(thread.parent.parent ? thread.parent.parent.name : "None", thread.parent.parent ? renderChannel(thread.parent.parent) : "None"), |
| 23 | autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })), |
| 24 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
| 25 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)) |
| 26 | }, |
| 27 | hidden: { |
| 28 | guild: thread.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 29 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | }; |
| 31 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 32 | } |