blob: 95748267f04d173a39b9b94eb9b3ebda43593e7d [file] [log] [blame]
import humanizeDuration from 'humanize-duration';
export const event = 'threadDelete'
export async function callback(client, thread) {
try {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = thread.client.logger
let auditLog = await getAuditLog(thread.guild, 'THREAD_UPDATE');
let audit = auditLog.entries.filter(entry => entry.target.id === thread.id).first();
if (audit.executor.id === client.user.id) return;
let data = {
meta: {
type: 'channelDelete',
displayName: 'Thread Deleted',
calculateType: 'channelUpdate',
color: NucleusColors.red,
emoji: "CHANNEL.TEXT.DELETE",
timestamp: new Date().getTime()
},
list: {
threadId:entry(thread.id, `\`${thread.id}\``),
name: entry(thread.name, thread.name),
parentChannel: entry(thread.parentId, renderChannel(thread.parent)),
category: entry(thread.parent.parent ? thread.parent.parent.name : 'None', thread.parent.parent ? renderChannel(thread.parent.parent) : 'None'),
autoArchiveDuration: entry(thread.autoArchiveDuration, humanizeDuration(thread.autoArchiveDuration * 60 * 1000, { round: true })),
membersInThread: entry(thread.memberCount, thread.memberCount),
deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
},
hidden: {
guild: thread.guild.id
}
}
log(data);
} catch {}
}