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 | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 5 | const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger; |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 6 | const auditLog = await getAuditLog(thread.guild, "THREAD_CREATE"); |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 7 | const audit = auditLog.entries.filter((entry) => entry.target.id === thread.id).first(); |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 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: { |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 19 | threadId: entry(thread.id, `\`${thread.id}\``), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 20 | name: entry(thread.name, renderChannel(thread)), |
| 21 | parentChannel: entry(thread.parentId, renderChannel(thread.parent)), |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 22 | category: entry( |
| 23 | thread.parent.parent ? thread.parent.parent.name : "None", |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 24 | thread.parent.parent ? renderChannel(thread.parent.parent) : "None" |
Skyler Grey | 75ea917 | 2022-08-06 10:22:23 +0100 | [diff] [blame] | 25 | ), |
| 26 | autoArchiveDuration: entry( |
| 27 | thread.autoArchiveDuration, |
| 28 | humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { |
| 29 | round: true |
| 30 | }) |
| 31 | ), |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 32 | createdBy: entry(audit.executor.id, renderUser(audit.executor)), |
Skyler Grey | 11236ba | 2022-08-08 21:13:33 +0100 | [diff] [blame] | 33 | created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)) |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 34 | }, |
| 35 | hidden: { |
| 36 | guild: thread.guild.id |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 37 | } |
pineafan | 63fc5e2 | 2022-08-04 22:04:10 +0100 | [diff] [blame] | 38 | }; |
| 39 | log(data); |
pineafan | e625d78 | 2022-05-09 18:04:32 +0100 | [diff] [blame] | 40 | } |