All commands and some events finished
diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index df212a2..67577f8 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -1,39 +1,40 @@
+import { GuildChannel, AuditLogEvent } from 'discord.js';
import humanizeDuration from "humanize-duration";
+import type { NucleusClient } from "../utils/client.js";
import getEmojiByName from "../utils/getEmojiByName.js";
export const event = "channelUpdate";
-export async function callback(client, oc, nc) {
- const config = await client.memory.readGuildInfo(nc.guild.id);
- return;
+export async function callback(client: NucleusClient, oldChannel: GuildChannel, newChannel: GuildChannel) {
+ const config = await client.memory.readGuildInfo(newChannel.guild.id);
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger;
- if (nc.parent && nc.parent.id === config.tickets.category) return;
+ if (newChannel.parent && newChannel.parent.id === config.tickets.category) return;
- const auditLog = await getAuditLog(nc.guild, "CHANNEL_UPDATE");
- const audit = auditLog.entries.filter((entry) => entry.target.id === nc.id).first();
+ const auditLog = await getAuditLog(newChannel.guild, "CHANNEL_UPDATE");
+ const audit = auditLog.entries.filter((entry) => entry.target.id === newChannel.id).first();
if (audit.executor.id === client.user.id) return;
let emoji: string;
let readableType: string;
let displayName: string;
const changes = {
- channelId: entry(nc.id, `\`${nc.id}\``),
- channel: entry(nc.id, renderChannel(nc)),
+ channelId: entry(newChannel.id, `\`${newChannel.id}\``),
+ channel: entry(newChannel.id, renderChannel(newChannel)),
edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- editedBy: entry(audit.executor.id, renderUser((await nc.guild.members.fetch(audit.executor.id)).user))
+ editedBy: entry(audit.executor.id, renderUser((await newChannel.guild.members.fetch(audit.executor.id)).user))
};
- if (oc.name !== nc.name) changes.name = entry([oc.name, nc.name], `${oc.name} -> ${nc.name}`);
- if (oc.position !== nc.position)
- changes.position = entry([oc.position, nc.position], `${oc.position} -> ${nc.position}`);
+ if (oldChannel.name !== newChannel.name) changes.name = entry([oldChannel.name, newChannel.name], `${oldChannel.name} -> ${newChannel.name}`);
+ if (oldChannel.position !== newChannel.position)
+ changes.position = entry([oldChannel.position, newChannel.position], `${oldChannel.position} -> ${newChannel.position}`);
- switch (nc.type) {
+ switch (newChannel.type) {
case "GUILD_TEXT": {
emoji = "CHANNEL.TEXT.EDIT";
readableType = "Text";
displayName = "Text Channel";
- let oldTopic = oc.topic,
- newTopic = nc.topic;
+ let oldTopic = oldChannel.topic,
+ newTopic = newChannel.topic;
if (oldTopic) {
if (oldTopic.length > 256)
oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
@@ -49,15 +50,15 @@
newTopic = "None";
}
const nsfw = ["", ""];
- nsfw[0] = oc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- nsfw[1] = nc.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- if (oc.topic !== nc.topic)
- changes.description = entry([oc.topic, nc.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
- if (oc.nsfw !== nc.nsfw) changes.nsfw = entry([oc.nsfw, nc.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
- if (oc.rateLimitPerUser !== nc.rateLimitPerUser)
+ nsfw[0] = oldChannel.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ nsfw[1] = newChannel.nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
+ if (oldChannel.topic !== newChannel.topic)
+ changes.description = entry([oldChannel.topic, newChannel.topic], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
+ if (oldChannel.nsfw !== newChannel.nsfw) changes.nsfw = entry([oldChannel.nsfw, newChannel.nsfw], `${nsfw[0]} -> ${nsfw[1]}`);
+ if (oldChannel.rateLimitPerUser !== newChannel.rateLimitPerUser)
changes.rateLimitPerUser = entry(
- [oc.rateLimitPerUser, nc.rateLimitPerUser],
- `${humanizeDuration(oc.rateLimitPerUser * 1000)} -> ${humanizeDuration(nc.rateLimitPerUser * 1000)}`
+ [oldChannel.rateLimitPerUser, newChannel.rateLimitPerUser],
+ `${humanizeDuration(oldChannel.rateLimitPerUser * 1000)} -> ${humanizeDuration(newChannel.rateLimitPerUser * 1000)}`
);
break;
@@ -66,8 +67,8 @@
emoji = "CHANNEL.TEXT.EDIT";
readableType = "News";
displayName = "News Channel";
- let oldTopic = oc.topic,
- newTopic = nc.topic;
+ let oldTopic = oldChannel.topic,
+ newTopic = newChannel.topic;
if (oldTopic) {
if (oldTopic.length > 256)
oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
@@ -82,25 +83,25 @@
} else {
newTopic = "None";
}
- if (oc.nsfw !== nc.nsfw)
- changes.nsfw = entry([oc.nsfw, nc.nsfw], `${oc.nsfw ? "On" : "Off"} -> ${nc.nsfw ? "On" : "Off"}`);
+ if (oldChannel.nsfw !== newChannel.nsfw)
+ changes.nsfw = entry([oldChannel.nsfw, newChannel.nsfw], `${oldChannel.nsfw ? "On" : "Off"} -> ${newChannel.nsfw ? "On" : "Off"}`);
break;
}
case "GUILD_VOICE": {
emoji = "CHANNEL.VOICE.EDIT";
readableType = "Voice";
displayName = "Voice Channel";
- if (oc.bitrate !== nc.bitrate)
- changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
- if (oc.userLimit !== nc.userLimit)
+ if (oldChannel.bitrate !== newChannel.bitrate)
+ changes.bitrate = entry([oldChannel.bitrate, newChannel.bitrate], `${oldChannel.bitrate} -> ${newChannel.bitrate}`);
+ if (oldChannel.userLimit !== newChannel.userLimit)
changes.maxUsers = entry(
- [oc.userLimit, nc.userLimit],
- `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
+ [oldChannel.userLimit, newChannel.userLimit],
+ `${oldChannel.userLimit ? oldChannel.userLimit : "Unlimited"} -> ${newChannel.userLimit}`
);
- if (oc.rtcRegion !== nc.rtcRegion)
+ if (oldChannel.rtcRegion !== newChannel.rtcRegion)
changes.region = entry(
- [oc.rtcRegion, nc.rtcRegion],
- `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
+ [oldChannel.rtcRegion, newChannel.rtcRegion],
+ `${oldChannel.rtcRegion || "Automatic"} -> ${newChannel.rtcRegion || "Automatic"}`
);
break;
}
@@ -108,8 +109,8 @@
emoji = "CHANNEL.VOICE.EDIT";
readableType = "Stage";
displayName = "Stage Channel";
- let oldTopic = oc.topic,
- newTopic = nc.topic;
+ let oldTopic = oldChannel.topic,
+ newTopic = newChannel.topic;
if (oldTopic) {
if (oldTopic.length > 256)
oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
@@ -124,17 +125,17 @@
} else {
newTopic = "None";
}
- if (oc.bitrate !== nc.bitrate)
- changes.bitrate = entry([oc.bitrate, nc.bitrate], `${oc.bitrate} -> ${nc.bitrate}`);
- if (oc.userLimit !== nc.userLimit)
+ if (oldChannel.bitrate !== newChannel.bitrate)
+ changes.bitrate = entry([oldChannel.bitrate, newChannel.bitrate], `${oldChannel.bitrate} -> ${newChannel.bitrate}`);
+ if (oldChannel.userLimit !== newChannel.userLimit)
changes.maxUsers = entry(
- [oc.userLimit, nc.userLimit],
- `${oc.userLimit ? oc.userLimit : "Unlimited"} -> ${nc.userLimit}`
+ [oldChannel.userLimit, newChannel.userLimit],
+ `${oldChannel.userLimit ? oldChannel.userLimit : "Unlimited"} -> ${newChannel.userLimit}`
);
- if (oc.rtcRegion !== nc.rtcRegion)
+ if (oldChannel.rtcRegion !== newChannel.rtcRegion)
changes.region = entry(
- [oc.rtcRegion, nc.rtcRegion],
- `${oc.rtcRegion || "Automatic"} -> ${nc.rtcRegion || "Automatic"}`
+ [oldChannel.rtcRegion, newChannel.rtcRegion],
+ `${oldChannel.rtcRegion || "Automatic"} -> ${newChannel.rtcRegion || "Automatic"}`
);
break;
}
@@ -150,9 +151,9 @@
displayName = "Channel";
}
}
- const t = oc.type.split("_")[1];
- if (oc.type !== nc.type)
- changes.type = entry([oc.type, nc.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
+ const t = oldChannel.type.split("_")[1];
+ if (oldChannel.type !== newChannel.type)
+ changes.type = entry([oldChannel.type, newChannel.type], `${t[0] + t.splice(1).toLowerCase()} -> ${readableType}`);
if (!(Object.values(changes).length - 4)) return;
const data = {
meta: {
@@ -165,7 +166,7 @@
},
list: changes,
hidden: {
- guild: nc.guild.id
+ guild: newChannel.guild.id
}
};
log(data);
diff --git a/src/events/emojiCreate.ts b/src/events/emojiCreate.ts
index b4e9dfa..8023abc 100644
--- a/src/events/emojiCreate.ts
+++ b/src/events/emojiCreate.ts
@@ -1,10 +1,14 @@
+import { AuditLogEvent } from 'discord.js';
+import type { NucleusClient } from "../utils/client.js";
+import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
export const event = "emojiCreate";
-export async function callback(client, emoji) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = emoji.client.logger;
- const auditLog = await getAuditLog(emoji.guild, "EMOJI_CREATE");
- const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
- if (audit.executor.id === client.user.id) return;
+export async function callback(client: NucleusClient, emoji: GuildEmoji) {
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
const data = {
meta: {
type: "emojiCreate",
@@ -17,7 +21,7 @@
list: {
emojiId: entry(emoji.id, `\`${emoji.id}\``),
emoji: entry(emoji.name, renderEmoji(emoji)),
- createdBy: entry(audit.executor.id, renderUser(audit.executor)),
+ createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp))
},
hidden: {
@@ -26,3 +30,4 @@
};
log(data);
}
+
diff --git a/src/events/emojiDelete.ts b/src/events/emojiDelete.ts
index c4b1535..f607cf4 100644
--- a/src/events/emojiDelete.ts
+++ b/src/events/emojiDelete.ts
@@ -1,10 +1,14 @@
+import { AuditLogEvent } from 'discord.js';
+import type { NucleusClient } from "../utils/client.js";
+import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
export const event = "emojiDelete";
-export async function callback(client, emoji) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = emoji.client.logger;
- const auditLog = await getAuditLog(emoji.guild, "EMOJI_DELETE");
- const audit = auditLog.entries.filter((entry) => entry.target.id === emoji.id).first();
- if (audit.executor.id === client.user.id) return;
+export async function callback(client: NucleusClient, emoji: GuildEmoji) {
+ const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
const data = {
meta: {
type: "emojiDelete",
@@ -12,14 +16,14 @@
calculateType: "emojiUpdate",
color: NucleusColors.red,
emoji: "GUILD.EMOJI.DELETE",
- timestamp: audit.createdTimestamp
+ timestamp: auditLog.createdTimestamp
},
list: {
emojiId: entry(emoji.id, `\`${emoji.id}\``),
emoji: entry(emoji.name, renderEmoji(emoji)),
- deletedBy: entry(audit.executor.id, renderUser(audit.executor)),
+ deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
created: entry(emoji.createdTimestamp, renderDelta(emoji.createdTimestamp)),
- deleted: entry(audit.createdTimestamp, renderDelta(audit.createdTimestamp))
+ deleted: entry(auditLog.createdTimestamp, renderDelta(auditLog.createdTimestamp))
},
hidden: {
guild: emoji.guild.id
diff --git a/src/events/emojiUpdate.ts b/src/events/emojiUpdate.ts
index 66227d4..201dd42 100644
--- a/src/events/emojiUpdate.ts
+++ b/src/events/emojiUpdate.ts
@@ -1,19 +1,22 @@
+import { AuditLogEvent } from 'discord.js';
+import type { NucleusClient } from "../utils/client.js";
+import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
export const event = "emojiUpdate";
-export async function callback(client, oe, ne) {
+export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) {
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;
- if (oe.name === ne.name) return;
- const auditLog = await getAuditLog(ne.guild, "EMOJI_UPDATE");
- const audit = auditLog.entries.first();
- if (audit.executor.id === client.user.id) return;
+ const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiCreate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
const changes = {
- emojiId: entry(ne.id, `\`${ne.id}\``),
- emoji: entry(ne.id, renderEmoji(ne)),
- edited: entry(ne.createdTimestamp, renderDelta(ne.createdTimestamp)),
- editedBy: entry(audit.executor.id, renderUser((await ne.guild.members.fetch(audit.executor.id)).user)),
- name: entry([oe.name, ne.name], `\`:${oe.name}:\` -> \`:${ne.name}:\``)
+ emojiId: entry(newEmoji.id, `\`${newEmoji.id}\``),
+ emoji: entry(newEmoji.id, renderEmoji(newEmoji)),
+ edited: entry(newEmoji.createdTimestamp, renderDelta(newEmoji.createdTimestamp)),
+ editedBy: entry(auditLog.executor!.id, renderUser((await newEmoji.guild.members.fetch(auditLog.executor!.id)).user)),
+ name: entry([oldEmoji.name!, newEmoji.name!], `\`:${oldEmoji.name}:\` -> \`:${newEmoji.name}:\``)
};
const data = {
meta: {
@@ -22,11 +25,11 @@
calculateType: "emojiUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.EMOJI.EDIT",
- timestamp: audit.createdTimestamp
+ timestamp: auditLog.createdTimestamp
},
list: changes,
hidden: {
- guild: ne.guild.id
+ guild: newEmoji.guild.id
}
};
log(data);
diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts
index 5fd0b49..3d96245 100644
--- a/src/events/guildBanAdd.ts
+++ b/src/events/guildBanAdd.ts
@@ -1,4 +1,5 @@
-import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
+import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
+import { AuditLogEvent } from 'discord.js';
import { purgeByUser } from "../actions/tickets/delete.js";
import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js";
import type { NucleusClient } from "../utils/client.js";
@@ -7,12 +8,13 @@
export async function callback(client: NucleusClient, ban: GuildBan) {
await statsChannelRemove(client, undefined, ban.guild, ban.user);
- purgeByUser(ban.user.id, ban.guild);
+ purgeByUser(ban.user.id, ban.guild.id);
const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_ADD");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
- if (audit.executor.id === client.user.id) return;
- await client.database.history.create("ban", ban.guild.id, ban.user, audit.executor, audit.reason);
+ const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
+ .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
+ await client.database.history.create("ban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason);
const data = {
meta: {
type: "memberBan",
@@ -26,9 +28,9 @@
memberId: entry(ban.user.id, `\`${ban.user.id}\``),
name: entry(ban.user.id, renderUser(ban.user)),
banned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- bannedBy: entry(audit.executor.id, renderUser(audit.executor)),
- reason: entry(audit.reason, audit.reason ? `\n> ${audit.reason}` : "*No reason provided.*"),
- accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt)),
+ bannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
+ reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"),
+ accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp)),
serverMemberCount: ban.guild.memberCount
},
hidden: {
diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts
index f9b427a..bcb70d5 100644
--- a/src/events/guildBanRemove.ts
+++ b/src/events/guildBanRemove.ts
@@ -1,16 +1,18 @@
-import type { GuildAuditLogsEntry, GuildBan } from "discord.js";
+import type { GuildAuditLogsEntry, GuildBan, User } from "discord.js";
+import { AuditLogEvent } from "discord.js";
import { purgeByUser } from "../actions/tickets/delete.js";
import type { NucleusClient } from "../utils/client.js";
export const event = "guildBanRemove";
export async function callback(client: NucleusClient, ban: GuildBan) {
- purgeByUser(ban.user.id, ban.guild);
+ purgeByUser(ban.user.id, ban.guild.id);
const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- const auditLog = await getAuditLog(ban.guild, "MEMBER_BAN_REMOVE");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === ban.user.id).first();
- if (audit.executor.id === client.user.id) return;
- await client.database.history.create("unban", ban.guild.id, ban.user, audit.executor, audit.reason);
+ const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
+ .filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
+ await client.database.history.create("unban", ban.guild.id, ban.user, auditLog.executor, auditLog.reason);
const data = {
meta: {
type: "memberUnban",
@@ -24,8 +26,8 @@
memberId: entry(ban.user.id, `\`${ban.user.id}\``),
name: entry(ban.user.id, renderUser(ban.user)),
unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- unbannedBy: entry(audit.executor.id, renderUser(audit.executor)),
- accountCreated: entry(ban.user.createdAt, renderDelta(ban.user.createdAt))
+ unbannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
+ accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp))
},
hidden: {
guild: ban.guild.id