Webhooks work

pull/11/head
TheCodedProf 3 years ago
parent 47fcd94c75
commit 686829f2b6

Binary file not shown.

@ -13,16 +13,15 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger; const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderChannel, renderDelta } = client.logger;
if (!await isLogging(channel.guild.id, "webhookUpdate")) return; if (!await isLogging(channel.guild.id, "webhookUpdate")) return;
const auditCreate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookCreate)) const auditCreate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0]!; .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
const auditDelete = (await getAuditLog(channel.guild, AuditLogEvent.WebhookDelete)) const auditDelete = (await getAuditLog(channel.guild, AuditLogEvent.WebhookDelete, 0))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0]; .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
const auditUpdate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookUpdate)) const auditUpdate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookUpdate, 0))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0]; .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
if (!auditCreate && !auditUpdate && !auditDelete) return;
if (!auditUpdate && !auditDelete) return;
let action: "Create" | "Update" | "Delete" = "Create"; let action: "Create" | "Update" | "Delete" = "Create";
let list: Record<string, ReturnType<typeof entry> | string> = {}; let list: Record<string, ReturnType<typeof entry> | string> = {};
const createTimestamp = auditCreate.createdTimestamp; const createTimestamp = auditCreate ? auditCreate.createdTimestamp : 0;
const deleteTimestamp = auditDelete ? auditDelete.createdTimestamp : 0; const deleteTimestamp = auditDelete ? auditDelete.createdTimestamp : 0;
const updateTimestamp = auditUpdate ? auditUpdate.createdTimestamp : 0; const updateTimestamp = auditUpdate ? auditUpdate.createdTimestamp : 0;
if (updateTimestamp > createTimestamp && updateTimestamp > deleteTimestamp && auditUpdate) { if (updateTimestamp > createTimestamp && updateTimestamp > deleteTimestamp && auditUpdate) {
@ -81,8 +80,8 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
name: entry(before["name"]!, `${before["name"]}`), name: entry(before["name"]!, `${before["name"]}`),
channel: entry(before["channel_id"]!, renderChannel(await client.channels.fetch(before["channel_id"]!) as GuildChannel)), channel: entry(before["channel_id"]!, renderChannel(await client.channels.fetch(before["channel_id"]!) as GuildChannel)),
createdBy: entry( createdBy: entry(
auditCreate.executor!.id, auditCreate!.executor!.id,
renderUser((await channel.guild.members.fetch(auditCreate.executor!.id)).user) renderUser((await channel.guild.members.fetch(auditCreate!.executor!.id)).user)
), ),
created: entry(Date.now(), renderDelta(Date.now())) created: entry(Date.now(), renderDelta(Date.now()))
}; };

@ -72,8 +72,8 @@ export const Logger = {
yellow: 0xf2d478, yellow: 0xf2d478,
green: 0x68d49e green: 0x68d49e
}, },
async getAuditLog(guild: Discord.Guild, event: Discord.GuildAuditLogsResolvable): Promise<Discord.GuildAuditLogsEntry[]> { async getAuditLog(guild: Discord.Guild, event: Discord.GuildAuditLogsResolvable, delay?: number): Promise<Discord.GuildAuditLogsEntry[]> {
await wait(250); await wait(delay ?? 250);
const auditLog = (await guild.fetchAuditLogs({ type: event })).entries.map(m => m) const auditLog = (await guild.fetchAuditLogs({ type: event })).entries.map(m => m)
return auditLog as Discord.GuildAuditLogsEntry[]; return auditLog as Discord.GuildAuditLogsEntry[];
}, },

Loading…
Cancel
Save