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) { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 5 | const { |
| 6 | getAuditLog, |
| 7 | log, |
| 8 | NucleusColors, |
| 9 | entry, |
| 10 | renderUser, |
| 11 | renderDelta, |
| 12 | renderChannel |
| 13 | } = thread.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 14 | const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE"); |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 15 | const audit = auditLog.entries |
| 16 | .filter((entry) => entry.target.id === thread.id) |
| 17 | .first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 18 | if (audit.executor.id === client.user.id) return; |
| 19 | const data = { |
| 20 | meta: { |
| 21 | type: "channelCreate", |
| 22 | displayName: "Thread Created", |
| 23 | calculateType: "channelUpdate", |
| 24 | color: NucleusColors.green, |
| 25 | emoji: "CHANNEL.TEXT.CREATE", |
| 26 | timestamp: thread.createdTimestamp |
| 27 | }, |
| 28 | list: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 29 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 30 | name: entry(thread.name, renderChannel(thread)), |
| 31 | parentChannel: entry(thread.parentId, renderChannel(thread.parent)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 32 | category: entry( |
| 33 | thread.parent.parent ? thread.parent.parent.name : "None", |
| 34 | thread.parent.parent |
| 35 | ? renderChannel(thread.parent.parent) |
| 36 | : "None" |
| 37 | ), |
| 38 | autoArchiveDuration: entry( |
| 39 | thread.autoArchiveDuration, |
| 40 | humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { |
| 41 | round: true |
| 42 | }) |
| 43 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 44 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 45 | created: entry( |
| 46 | thread.createdTimestamp, |
| 47 | renderDelta(thread.createdTimestamp) |
| 48 | ) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 49 | }, |
| 50 | hidden: { |
| 51 | guild: thread.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 52 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 53 | }; |
| 54 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 55 | } |