Performance testing
diff --git a/src/events/channelCreate.ts b/src/events/channelCreate.ts
index b3cba33..dda37af 100644
--- a/src/events/channelCreate.ts
+++ b/src/events/channelCreate.ts
@@ -1,47 +1,54 @@
-import type { GuildAuditLogsEntry } from "discord.js";
+import { AuditLogEvent, ChannelType, GuildAuditLogsEntry } from "discord.js";
import type { GuildBasedChannel } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
export const event = "channelCreate";
export async function callback(client: NucleusClient, channel: GuildBasedChannel) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
- const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
- const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
- if (audit.executor.id === client.user.id) return;
+ const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelCreate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id)[0];
+ if (!auditLog) return;
+ if (auditLog.executor!.id === client.user!.id) return;
let emoji;
let readableType;
let displayName;
switch (channel.type) {
- case "GUILD_TEXT": {
+ case ChannelType.GuildText: {
emoji = "CHANNEL.TEXT.CREATE";
readableType = "Text";
displayName = "Text Channel";
break;
}
- case "GUILD_NEWS": {
+ case ChannelType.GuildAnnouncement: {
emoji = "CHANNEL.TEXT.CREATE";
readableType = "Announcement";
displayName = "Announcement Channel";
break;
}
- case "GUILD_VOICE": {
+ case ChannelType.GuildVoice: {
emoji = "CHANNEL.VOICE.CREATE";
readableType = "Voice";
displayName = "Voice Channel";
break;
}
- case "GUILD_STAGE_VOICE": {
+ case ChannelType.GuildStageVoice: {
emoji = "CHANNEL.VOICE.CREATE";
readableType = "Stage";
displayName = "Stage Channel";
break;
}
- case "GUILD_CATEGORY": {
+ case ChannelType.GuildCategory: {
emoji = "CHANNEL.CATEGORY.CREATE";
readableType = "Category";
displayName = "Category";
break;
}
+ case ChannelType.GuildForum: {
+ emoji = "CHANNEL.TEXT.CREATE";
+ readableType = "Forum";
+ displayName = "Forum Channel";
+ break;
+ }
default: {
emoji = "CHANNEL.TEXT.CREATE";
readableType = "Channel";
@@ -65,12 +72,12 @@
channel.parent ? channel.parent.id : null,
channel.parent ? channel.parent.name : "Uncategorised"
),
- createdBy: entry(audit.executor.id, renderUser(audit.executor)),
- created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp))
+ createdBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
+ created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!))
},
hidden: {
guild: channel.guild.id
}
};
log(data);
-}
+};
diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index a7af453..df212a2 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -5,6 +5,7 @@
export async function callback(client, oc, nc) {
const config = await client.memory.readGuildInfo(nc.guild.id);
+ return;
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderChannel } = client.logger;
if (nc.parent && nc.parent.id === config.tickets.category) return;
diff --git a/src/events/guildUpdate.ts b/src/events/guildUpdate.ts
index e463007..eefab4b 100644
--- a/src/events/guildUpdate.ts
+++ b/src/events/guildUpdate.ts
@@ -78,7 +78,7 @@
const data = {
meta: {
type: "guildUpdate",
- displayName: "Guild Edited",
+ displayName: "Server Edited",
calculateType: "guildUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.YELLOW",
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index 1796146..62e9609 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -4,7 +4,7 @@
import close from "../actions/tickets/delete.js";
import createTranscript from "../premium/createTranscript.js";
-import type { Interaction, MessageComponentInteraction } from "discord.js";
+import type { Interaction } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
export const event = "interactionCreate";
@@ -12,30 +12,16 @@
async function interactionCreate(interaction: Interaction) {
if (interaction.isButton()) {
- const int = interaction as MessageComponentInteraction;
- switch (int.customId) {
- case "rolemenu": {
- return await roleMenu(interaction);
- }
- case "verifybutton": {
- return verify(int);
- }
- case "createticket": {
- return create(interaction);
- }
- case "closeticket": {
- return close(interaction);
- }
- case "createtranscript": {
- return createTranscript(int);
- }
+ switch (interaction.customId) {
+ case "rolemenu": { return await roleMenu(interaction); }
+ case "verifybutton": { return await verify(interaction); }
+ case "createticket": { return await create(interaction); }
+ case "closeticket": { return await close(interaction); }
+ case "createtranscript": { return await createTranscript(interaction); }
}
// } else if (interaction.type === "APPLICATION_COMMAND_AUTOCOMPLETE") {
// const int = interaction as AutocompleteInteraction;
// switch (`${int.commandName} ${int.options.getSubcommandGroup(false)} ${int.options.getSubcommand(false)}`) {
- // case "tag null null": {
- // return int.respond(getAutocomplete(int.options.getString("tag") ?? "", await tagAutocomplete(int)));
- // }
// case "settings null stats": {
// return int.respond(generateStatsChannelAutocomplete(int.options.getString("name") ?? ""));
// }
diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts
index 3f85de6..2f3a077 100644
--- a/src/events/messageCreate.ts
+++ b/src/events/messageCreate.ts
@@ -12,7 +12,7 @@
export async function callback(_client: NucleusClient, message: Message) {
if (!message.guild) return;
if (message.author.bot) return;
- if (message.channel.type === "DM") return;
+ if (message.channel.isDMBased()) return;
try {
await statsChannelUpdate(client, await message.guild.members.fetch(message.author.id));
} catch (e) {
@@ -38,7 +38,7 @@
mentions: message.mentions.users.size,
attachments: entry(message.attachments.size, message.attachments.size + attachmentJump),
repliedTo: entry(
- message.reference ? message.reference.messageId : null,
+ (message.reference ? message.reference.messageId : null) ?? null,
message.reference
? `[[Jump to message]](https://discord.com/channels/${message.guild.id}/${message.channel.id}/${message.reference.messageId})`
: "None"
diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index ddeff96..f8433fc 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -1,27 +1,24 @@
import type { NucleusClient } from "../utils/client.js";
-import type { GuildAuditLogsEntry, Message } from "discord.js";
+import Discord, { AuditLogEvent, GuildAuditLogsEntry, Message, User } from "discord.js";
export const event = "messageDelete";
export async function callback(client: NucleusClient, message: Message) {
try {
- if (message.author.id === client.user.id) return;
+ if (message.author.id === client.user!.id) return;
if (client.noLog.includes(`${message.id}/${message.channel.id}/${message.id}`)) return;
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
- const auditLog = await getAuditLog(message.guild, "MEMBER_BAN_ADD");
- const audit = auditLog.entries
- .filter((entry: GuildAuditLogsEntry) => entry.target!.id === message.author.id)
- .first();
- if (audit) {
- if (audit.createdAt - 100 < new Date().getTime()) return;
+ const auditLog = (await getAuditLog(message.guild!, AuditLogEvent.MemberBanAdd))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target! as User).id === message.author.id)[0];
+ if (auditLog) {
+ if (auditLog.createdTimestamp - 1000 < new Date().getTime()) return;
}
const replyTo = message.reference;
let content = message.cleanContent;
content.replace("`", "\\`");
if (content.length > 256) content = content.substring(0, 253) + "...";
const attachments =
- message.attachments.size +
- (
+ message.attachments.size + (
message.content.match(
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
) ?? []
@@ -30,9 +27,7 @@
const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
message.channel.id + message.id
];
- if (config) {
- attachmentJump = ` [[View attachments]](${config})`;
- }
+ if (config) { attachmentJump = ` [[View attachments]](${config})`; }
const data = {
meta: {
type: "messageDelete",
@@ -48,17 +43,14 @@
list: {
messageId: entry(message.id, `\`${message.id}\``),
sentBy: entry(message.author.id, renderUser(message.author)),
- sentIn: entry(message.channel.id, renderChannel(message.channel)),
+ sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
mentions: message.mentions.users.size,
attachments: entry(attachments, attachments + attachmentJump),
repliedTo: entry(
- replyTo,
- replyTo
- ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${
- message.channel.id
- }/${replyTo.messageId})`
- : "None"
+ replyTo ? replyTo.messageId! : null,
+ replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
+ : "None"
)
},
hidden: {
diff --git a/src/events/messageEdit.ts b/src/events/messageEdit.ts
index 37178a7..20624fe 100644
--- a/src/events/messageEdit.ts
+++ b/src/events/messageEdit.ts
@@ -1,10 +1,11 @@
import type { NucleusClient } from "../utils/client.js";
import type { Message, MessageReference } from "discord.js";
+import type Discord from "discord.js";
export const event = "messageUpdate";
export async function callback(client: NucleusClient, oldMessage: Message, newMessage: Message) {
- if (newMessage.author.id === client.user.id) return;
+ if (newMessage.author.id === client.user!.id) return;
if (!newMessage.guild) return;
const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = client.logger;
const replyTo: MessageReference | null = newMessage.reference;
@@ -17,8 +18,8 @@
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
- if (newContent === oldContent) {
- if (!oldMessage.flags.has("CROSSPOSTED") && newMessage.flags.has("CROSSPOSTED")) {
+ if (newContent === oldContent && newMessage.attachments.size === oldMessage.attachments.size) {
+ if (!replyTo) {
const data = {
meta: {
type: "messageAnnounce",
@@ -34,14 +35,14 @@
list: {
messageId: entry(newMessage.id, `\`${newMessage.id}\``),
sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
- sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
+ sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel as Discord.GuildBasedChannel)),
sent: entry(
- new Date(newMessage.createdTimestamp),
- renderDelta(new Date(newMessage.createdTimestamp))
+ newMessage.createdTimestamp,
+ renderDelta(newMessage.createdTimestamp)
),
published: entry(
- new Date(newMessage.editedTimestamp!),
- renderDelta(new Date(newMessage.editedTimestamp!))
+ newMessage.editedTimestamp!,
+ renderDelta(newMessage.editedTimestamp!)
),
mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
attachments: entry(
@@ -81,16 +82,16 @@
list: {
messageId: entry(newMessage.id, `\`${newMessage.id}\``),
sentBy: entry(newMessage.author.id, renderUser(newMessage.author)),
- sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel)),
- sent: entry(new Date(newMessage.createdTimestamp), renderDelta(new Date(newMessage.createdTimestamp))),
- edited: entry(new Date(newMessage.editedTimestamp), renderDelta(new Date(newMessage.editedTimestamp))),
+ sentIn: entry(newMessage.channel.id, renderChannel(newMessage.channel as Discord.GuildBasedChannel)),
+ sent: entry(newMessage.createdTimestamp, renderDelta(newMessage.createdTimestamp)),
+ edited: entry(newMessage.editedTimestamp, renderDelta(newMessage.editedTimestamp)),
mentions: renderNumberDelta(oldMessage.mentions.users.size, newMessage.mentions.users.size),
attachments: entry(
renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size),
renderNumberDelta(oldMessage.attachments.size, newMessage.attachments.size) + attachmentJump
),
repliedTo: entry(
- replyTo,
+ replyTo ? replyTo.messageId! : null,
replyTo
? `[[Jump to message]](https://discord.com/channels/${newMessage.guild.id}/${newMessage.channel.id}/${replyTo.messageId})`
: "None"