Development (#11)
We need this NOW.
---------
Co-authored-by: PineaFan <ash@pinea.dev>
Co-authored-by: pineafan <pineapplefanyt@gmail.com>
Co-authored-by: PineappleFan <PineaFan@users.noreply.github.com>
Co-authored-by: Skyler <skyler3665@gmail.com>
diff --git a/src/events/channelCreate.ts b/src/events/channelCreate.ts
index dda37af..b42ded7 100644
--- a/src/events/channelCreate.ts
+++ b/src/events/channelCreate.ts
@@ -4,7 +4,8 @@
export const event = "channelCreate";
export async function callback(client: NucleusClient, channel: GuildBasedChannel) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(channel.guild.id, "channelUpdate")) return;
const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id)[0];
if (!auditLog) return;
@@ -62,7 +63,7 @@
calculateType: "channelUpdate",
color: NucleusColors.green,
emoji: emoji,
- timestamp: channel.createdTimestamp
+ timestamp: channel.createdTimestamp ?? Date.now()
},
list: {
channelId: entry(channel.id, `\`${channel.id}\``),
diff --git a/src/events/channelDelete.ts b/src/events/channelDelete.ts
index 4780700..890a15f 100644
--- a/src/events/channelDelete.ts
+++ b/src/events/channelDelete.ts
@@ -14,8 +14,8 @@
export const event = "channelDelete";
export async function callback(client: NucleusClient, channel: GuildBasedChannel) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
- // const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
+ const { getAuditLog, log, isLogging, NucleusColors, entry, renderDelta, renderUser } = client.logger;
+ if (!await isLogging(channel.guild.id, "channelUpdate")) return;
const auditLog = (await getAuditLog(channel.guild, AuditLogEvent.ChannelDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildBasedChannel)!.id === channel.id)[0];
if (!auditLog) return;
@@ -82,7 +82,7 @@
),
nsfw: null,
created: entry(channel.createdTimestamp, renderDelta(channel.createdTimestamp!)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ deleted: entry(Date.now(), renderDelta(Date.now())),
deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
};
if ((channel instanceof BaseGuildTextChannel || channel instanceof StageChannel) && channel.topic !== null)
diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts
index 7c80e12..052acc1 100644
--- a/src/events/channelUpdate.ts
+++ b/src/events/channelUpdate.ts
@@ -32,11 +32,11 @@
topic?: ReturnType<typeof entry>;
bitrate?: ReturnType<typeof entry>;
userLimit?: ReturnType<typeof entry>;
- rateLimitPerUser?: ReturnType<typeof entry>;
parent?: ReturnType<typeof entry>;
permissionOverwrites?: ReturnType<typeof entry>;
region?: ReturnType<typeof entry>;
maxUsers?: ReturnType<typeof entry>;
+ autoArchiveDuration?: ReturnType<typeof entry>;
}
@@ -44,8 +44,9 @@
export const event = "channelUpdate";
export async function callback(client: NucleusClient, oldChannel: GuildChannel, newChannel: GuildChannel) {
+ const { getAuditLog, log, isLogging, NucleusColors, renderDelta, renderUser, renderChannel } = client.logger;
+ if (!await isLogging(newChannel.guild.id, "channelUpdate")) return;
const config = await client.memory.readGuildInfo(newChannel.guild.id);
- const { getAuditLog, log, NucleusColors, renderDelta, renderUser, renderChannel } = client.logger;
entry = client.logger.entry;
if (newChannel.parent && newChannel.parent.id === config.tickets.category) return;
@@ -60,7 +61,7 @@
const changes: channelChanges = {
channelId: entry(newChannel.id, `\`${newChannel.id}\``),
channel: entry(newChannel.id, renderChannel(newChannel)),
- edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ edited: entry(Date.now(), renderDelta(Date.now())),
editedBy: entry(auditLog.executor!.id, renderUser((await newChannel.guild.members.fetch(auditLog.executor!.id)).user)),
};
if (oldChannel.name !== newChannel.name) changes.name = entry([oldChannel.name, newChannel.name], `${oldChannel.name} -> ${newChannel.name}`);
@@ -68,12 +69,16 @@
changes.position = entry([oldChannel.position.toString(), newChannel.position.toString()], `${oldChannel.position} -> ${newChannel.position}`);
switch (newChannel.type) {
+ case ChannelType.PrivateThread:
+ case ChannelType.PublicThread: {
+ return;
+ }
case ChannelType.GuildText: {
emoji = "CHANNEL.TEXT.EDIT";
readableType = "Text";
displayName = "Text Channel";
- let oldTopic = (oldChannel as TextChannel).topic,
- newTopic = (newChannel as TextChannel).topic;
+ let oldTopic = (oldChannel as TextChannel).topic ?? "*None*",
+ newTopic = (oldChannel as TextChannel).topic ?? "*None*";
if (oldTopic) {
if (oldTopic.length > 256)
oldTopic = `\`\`\`\n${oldTopic.replace("`", "'").substring(0, 253) + "..."}\n\`\`\``;
@@ -91,14 +96,20 @@
const nsfw = ["", ""];
nsfw[0] = (oldChannel as TextChannel).nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
nsfw[1] = (newChannel as TextChannel).nsfw ? `${getEmojiByName("CONTROL.TICK")} Yes` : `${getEmojiByName("CONTROL.CROSS")} No`;
- if ((oldChannel as TextChannel).topic !== (newChannel as TextChannel).topic)
+ if (oldTopic !== newTopic)
changes.description = entry([(oldChannel as TextChannel).topic ?? "", (newChannel as TextChannel).topic ?? ""], `\nBefore: ${oldTopic}\nAfter: ${newTopic}`);
if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw) changes.nsfw = entry([(oldChannel as TextChannel).nsfw ? "On" : "Off", (newChannel as TextChannel).nsfw ? "On" : "Off"], `${nsfw[0]} -> ${nsfw[1]}`);
- if ((oldChannel as TextChannel).rateLimitPerUser !== (newChannel as TextChannel).rateLimitPerUser && (oldChannel as TextChannel).rateLimitPerUser !== 0)
- changes.rateLimitPerUser = entry(
+ if ((oldChannel as TextChannel).rateLimitPerUser !== (newChannel as TextChannel).rateLimitPerUser)
+ changes.slowmode = entry(
[((oldChannel as TextChannel).rateLimitPerUser).toString(), ((newChannel as TextChannel).rateLimitPerUser).toString()],
`${humanizeDuration((oldChannel as TextChannel).rateLimitPerUser * 1000)} -> ${humanizeDuration((newChannel as TextChannel).rateLimitPerUser * 1000)}`
);
+ if((oldChannel as TextChannel).defaultAutoArchiveDuration !== (newChannel as TextChannel).defaultAutoArchiveDuration) {
+ changes.autoArchiveDuration = entry(
+ [((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString(), ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString()],
+ `${humanizeDuration(((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000)} -> ${humanizeDuration(((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000)}`
+ );
+ }
break;
}
@@ -122,8 +133,15 @@
} else {
newTopic = "None";
}
- if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw)
+ if ((oldChannel as TextChannel).nsfw !== (newChannel as TextChannel).nsfw) {
changes.nsfw = entry([(oldChannel as TextChannel).nsfw ? "On" : "Off", (newChannel as TextChannel).nsfw ? "On" : "Off"], `${(oldChannel as TextChannel).nsfw ? "On" : "Off"} -> ${(newChannel as TextChannel).nsfw ? "On" : "Off"}`);
+ }
+ if((oldChannel as TextChannel).defaultAutoArchiveDuration !== (newChannel as TextChannel).defaultAutoArchiveDuration) {
+ changes.autoArchiveDuration = entry(
+ [((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString(), ((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320).toString()],
+ `${humanizeDuration(((oldChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000)} -> ${humanizeDuration(((newChannel as TextChannel).defaultAutoArchiveDuration ?? 4320) * 60 * 1000)}`
+ );
+ }
break;
}
case ChannelType.GuildVoice: {
@@ -174,7 +192,7 @@
if ((oldChannel as StageChannel).rtcRegion !== (newChannel as StageChannel).rtcRegion)
changes.region = entry(
[(oldChannel as StageChannel).rtcRegion ?? "Automatic", (newChannel as StageChannel).rtcRegion ?? "Automatic"],
- `${(oldChannel as StageChannel).rtcRegion?.toUpperCase() ?? "Automatic"} -> ${(newChannel as StageChannel).rtcRegion?.toUpperCase() ?? "Automatic"}`
+ `${capitalize((oldChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic")} -> ${capitalize((newChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic")}`
);
break;
}
diff --git a/src/events/emojiCreate.ts b/src/events/emojiCreate.ts
index 8023abc..2630295 100644
--- a/src/events/emojiCreate.ts
+++ b/src/events/emojiCreate.ts
@@ -4,9 +4,10 @@
export const event = "emojiCreate";
export async function callback(client: NucleusClient, emoji: GuildEmoji) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ if (!await isLogging(emoji.guild.id, "emojiUpdate")) return;
const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
const data = {
diff --git a/src/events/emojiDelete.ts b/src/events/emojiDelete.ts
index f607cf4..c4b488e 100644
--- a/src/events/emojiDelete.ts
+++ b/src/events/emojiDelete.ts
@@ -4,8 +4,9 @@
export const event = "emojiDelete";
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))
+ const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ if (!await isLogging(emoji.guild.id, "emojiUpdate")) return;
+ const auditLog = (await getAuditLog(emoji.guild, AuditLogEvent.EmojiDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === emoji.id)[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
diff --git a/src/events/emojiUpdate.ts b/src/events/emojiUpdate.ts
index 201dd42..98ff558 100644
--- a/src/events/emojiUpdate.ts
+++ b/src/events/emojiUpdate.ts
@@ -4,9 +4,10 @@
export const event = "emojiUpdate";
export async function callback(client: NucleusClient, oldEmoji: GuildEmoji, newEmoji: GuildEmoji) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderEmoji } = client.logger;
+ const { getAuditLog, log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderEmoji } = client.logger;
+ if (!(await isLogging(newEmoji.guild.id, "emojiUpdate"))) return;
- const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiCreate))
+ const auditLog = (await getAuditLog(newEmoji.guild, AuditLogEvent.EmojiUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
diff --git a/src/events/guildBanAdd.ts b/src/events/guildBanAdd.ts
index 3d96245..cac4b41 100644
--- a/src/events/guildBanAdd.ts
+++ b/src/events/guildBanAdd.ts
@@ -7,10 +7,11 @@
export const event = "guildBanAdd";
export async function callback(client: NucleusClient, ban: GuildBan) {
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
await statsChannelRemove(client, undefined, ban.guild, ban.user);
purgeByUser(ban.user.id, ban.guild.id);
- const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
+ if (!(await isLogging(ban.guild.id, "guildMemberPunish"))) return;
+ const auditLog: GuildAuditLogsEntry | undefined = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanAdd))
.filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
@@ -22,12 +23,12 @@
calculateType: "guildMemberPunish",
color: NucleusColors.red,
emoji: "PUNISH.BAN.RED",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
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())),
+ banned: entry(Date.now(), renderDelta(Date.now())),
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)),
diff --git a/src/events/guildBanRemove.ts b/src/events/guildBanRemove.ts
index bcb70d5..3be4560 100644
--- a/src/events/guildBanRemove.ts
+++ b/src/events/guildBanRemove.ts
@@ -1,14 +1,13 @@
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.id);
- const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.EmojiCreate))
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
+ if (!await isLogging(ban.guild.id, "guildMemberPunish")) return;
+ const auditLog = (await getAuditLog(ban.guild, AuditLogEvent.MemberBanRemove))
.filter((entry: GuildAuditLogsEntry) => ((entry.target! as User).id === ban.user.id))[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
@@ -20,12 +19,12 @@
calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.BAN.GREEN",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
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())),
+ unbanned: entry(Date.now(), renderDelta(Date.now())),
unbannedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
accountCreated: entry(ban.user.createdTimestamp, renderDelta(ban.user.createdTimestamp))
},
diff --git a/src/events/guildMemberUpdate.ts b/src/events/guildMemberUpdate.ts
index 8889f57..721978f 100644
--- a/src/events/guildMemberUpdate.ts
+++ b/src/events/guildMemberUpdate.ts
@@ -1,11 +1,76 @@
import { AuditLogEvent, GuildAuditLogsEntry, GuildMember } from "discord.js";
import type { NucleusClient } from "../utils/client.js";
+import type { LoggerOptions } from "../utils/log.js";
+import { generalException } from "../utils/createTemporaryStorage.js";
export const event = "guildMemberUpdate";
export async function callback(client: NucleusClient, before: GuildMember, after: GuildMember) {
const { log, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
- const auditLog = (await getAuditLog(after.guild, AuditLogEvent.EmojiCreate))
+ if(before.guild.id === "684492926528651336") {
+ await client.database.premium.checkAllPremium(after)
+ }
+
+ if(!before.roles.cache.equals(after.roles.cache)) {
+ const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberRoleUpdate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
+ if (!auditLog) return;
+ if (client.noLog.includes(`${after.guild.id}${after.id}${auditLog.id}`)) return;
+ generalException(`${after.guild.id}${after.id}${auditLog.id}`);
+ if (auditLog.executor!.id !== client.user!.id) {
+ const rolesAdded = after.roles.cache.filter(role => !before.roles.cache.has(role.id));
+ const rolesRemoved = before.roles.cache.filter(role => !after.roles.cache.has(role.id));
+ let displayName = "Roles Removed";
+ let color = NucleusColors.red;
+ let emoji = "GUILD.ROLES.DELETE";
+ if(rolesAdded.size > 0 && rolesRemoved.size > 0) {displayName = "Roles Changed"; color = NucleusColors.yellow; emoji = "GUILD.ROLES.EDIT";}
+ else if(rolesAdded.size > 0) {displayName = "Roles Added"; color = NucleusColors.green; emoji = "GUILD.ROLES.CREATE";}
+ const removedEntry = rolesRemoved.map(role => role.id);
+ const addedEntry = rolesAdded.map(role => role.id);
+
+ let list = {
+ memberId: entry(after.id, `\`${after.id}\``),
+ name: entry(after.user.id, renderUser(after.user)),
+ };
+
+ if (rolesAdded.size > 0) {
+ list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+ if (rolesRemoved.size > 0) {
+ list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+
+ list = Object.assign(list, {
+ changed: entry(Date.now(), renderDelta(Date.now())),
+ changedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
+ });
+
+ let data: LoggerOptions = {
+ meta: {
+ type: "memberUpdate",
+ displayName: displayName,
+ calculateType: "guildMemberUpdate",
+ color: color,
+ emoji: emoji,
+ timestamp: Date.now()
+ },
+ list: {},
+ hidden: {
+ guild: after.guild.id
+ }
+ };
+
+ if(rolesAdded.size > 0) {
+ list = Object.assign(list, {rolesAdded: entry(addedEntry, addedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+ if(rolesRemoved.size > 0) {
+ list = Object.assign(list, {rolesRemoved: entry(removedEntry, removedEntry.map(id => `<@&${id}>`).join(", "))});
+ }
+ data = Object.assign(data, {list: list});
+ log(data);
+ }
+ }
+ const auditLog = (await getAuditLog(after.guild, AuditLogEvent.MemberUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
@@ -26,14 +91,14 @@
calculateType: "guildMemberUpdate",
color: NucleusColors.yellow,
emoji: "PUNISH.NICKNAME.YELLOW",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
memberId: entry(after.id, `\`${after.id}\``),
name: entry(after.user.id, renderUser(after.user)),
before: entry(before.nickname, before.nickname ? before.nickname : "*None*"),
after: entry(after.nickname, after.nickname ? after.nickname : "*None*"),
- changed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ changed: entry(Date.now(), renderDelta(Date.now())),
changedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
},
hidden: {
@@ -41,9 +106,10 @@
}
};
log(data);
- } else if (
- (before.communicationDisabledUntilTimestamp ?? 0) < new Date().getTime() &&
- (after.communicationDisabledUntil ?? 0) > new Date().getTime() // TODO: test this
+ }
+ if (
+ (before.communicationDisabledUntilTimestamp ?? 0) < Date.now() &&
+ new Date(after.communicationDisabledUntil ?? 0).getTime() > Date.now()
) {
await client.database.history.create(
"mute",
@@ -62,7 +128,7 @@
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.MUTE.YELLOW",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
memberId: entry(after.id, `\`${after.id}\``),
@@ -71,7 +137,7 @@
after.communicationDisabledUntilTimestamp,
renderDelta(after.communicationDisabledUntilTimestamp!)
),
- muted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ muted: entry(Date.now(), renderDelta(Date.now())),
mutedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
reason: entry(auditLog.reason, auditLog.reason ? auditLog.reason : "\n> *No reason provided*")
},
@@ -85,10 +151,11 @@
user: after.id,
expires: after.communicationDisabledUntilTimestamp
});
- } else if (
+ }
+ if (
after.communicationDisabledUntil === null &&
before.communicationDisabledUntilTimestamp !== null &&
- new Date().getTime() >= auditLog.createdTimestamp
+ Date.now() >= auditLog.createdTimestamp
) {
await client.database.history.create(
"unmute",
@@ -107,12 +174,12 @@
calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.MUTE.GREEN",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
memberId: entry(after.id, `\`${after.id}\``),
name: entry(after.user.id, renderUser(after.user)),
- unmuted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ unmuted: entry(Date.now(), renderDelta(Date.now())),
unmutedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!))
},
hidden: {
diff --git a/src/events/guildUpdate.ts b/src/events/guildUpdate.ts
index 8690af2..6b25e48 100644
--- a/src/events/guildUpdate.ts
+++ b/src/events/guildUpdate.ts
@@ -6,7 +6,8 @@
export async function callback(client: NucleusClient, before: Guild, after: Guild) {
await statsChannelUpdate(client, after.members.me!);
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(after.id, "guildUpdate")) return;
const auditLog = (await getAuditLog(after, AuditLogEvent.GuildUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Guild)!.id === after.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -74,7 +75,7 @@
);
if (!Object.keys(list).length) return;
- list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()));
+ list["updated"] = entry(Date.now(), renderDelta(Date.now()));
list["updatedBy"] = entry(auditLog.executor!.id, renderUser(auditLog.executor!));
const data = {
meta: {
@@ -83,7 +84,7 @@
calculateType: "guildUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.YELLOW",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: list,
hidden: {
diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts
index a22045b..80c2c1b 100644
--- a/src/events/interactionCreate.ts
+++ b/src/events/interactionCreate.ts
@@ -31,14 +31,14 @@
await message.fetch();
if (message.embeds.length === 0) return;
const embed = message.embeds[0];
- const newColour = accept ? "Success" : "Danger";
+ const newcolor = accept ? "Success" : "Danger";
const footer = {text: `Suggestion ${accept ? "accepted" : "denied"} by ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL()};
const newEmbed = new EmojiEmbed()
.setTitle(embed!.title!)
.setDescription(embed!.description!)
.setFooter(footer)
- .setStatus(newColour);
+ .setStatus(newcolor);
await interaction.update({embeds: [newEmbed], components: []});
}
diff --git a/src/events/inviteCreate.ts b/src/events/inviteCreate.ts
index a267f09..34f66dc 100644
--- a/src/events/inviteCreate.ts
+++ b/src/events/inviteCreate.ts
@@ -7,7 +7,8 @@
export async function callback(client: NucleusClient, invite: Invite) {
if(!invite.guild) return; // This is a DM invite (not a guild invite
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(invite.guild.id, "guildUpdate")) return;
const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -18,7 +19,7 @@
calculateType: "guildUpdate",
color: NucleusColors.green,
emoji: "INVITE.CREATE",
- timestamp: invite.createdTimestamp
+ timestamp: invite.createdTimestamp ?? Date.now()
},
list: {
channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)),
diff --git a/src/events/inviteDelete.ts b/src/events/inviteDelete.ts
index 1ded432..456af90 100644
--- a/src/events/inviteDelete.ts
+++ b/src/events/inviteDelete.ts
@@ -7,7 +7,8 @@
export async function callback(client: NucleusClient, invite: Invite) {
if(!invite.guild) return; // This is a DM invite (not a guild invite
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(invite.guild.id, "guildUpdate")) return;
const auditLog = (await getAuditLog(invite.guild as Guild, AuditLogEvent.InviteDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Invite)!.code === invite.code)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -18,14 +19,14 @@
calculateType: "guildUpdate",
color: NucleusColors.red,
emoji: "INVITE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
channel: entry(invite.channel!.id, renderChannel(invite.channel as GuildChannel)),
link: entry(invite.url, invite.url),
expires: entry(invite.maxAge, invite.maxAge ? humanizeDuration(invite.maxAge * 1000) : "Never"),
deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ deleted: entry(Date.now(), renderDelta(Date.now()))
},
hidden: {
guild: invite.guild!.id
diff --git a/src/events/memberJoin.ts b/src/events/memberJoin.ts
index daf195a..77b111f 100644
--- a/src/events/memberJoin.ts
+++ b/src/events/memberJoin.ts
@@ -8,7 +8,8 @@
export async function callback(client: NucleusClient, member: GuildMember) {
welcome(client, member);
statsChannelAdd(client, member);
- const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(member.guild.id, "guildMemberUpdate")) return;
await client.database.history.create("join", member.guild.id, member.user, null, null);
const data = {
meta: {
@@ -17,7 +18,7 @@
calculateType: "guildMemberUpdate",
color: NucleusColors.green,
emoji: "MEMBER" + (member.user.bot ? ".BOT" : "") + ".JOIN",
- timestamp: member.joinedTimestamp
+ timestamp: member.joinedTimestamp ?? Date.now()
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
diff --git a/src/events/memberLeave.ts b/src/events/memberLeave.ts
index e70fb3c..8b3d1b1 100644
--- a/src/events/memberLeave.ts
+++ b/src/events/memberLeave.ts
@@ -7,22 +7,36 @@
export const event = "guildMemberRemove";
export async function callback(client: NucleusClient, member: GuildMember) {
+ const startTime = Date.now() - 10 * 1000;
purgeByUser(member.id, member.guild.id);
await statsChannelRemove(client, member);
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
- const auditLog = (await getAuditLog(member.guild as Guild, AuditLogEvent.MemberKick))
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(member.guild.id, "guildMemberUpdate")) return;
+ const kickAuditLog = (await getAuditLog(member.guild as Guild, AuditLogEvent.MemberKick))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === member.id)[0];
+ const banAuditLog = (await getAuditLog(member.guild as Guild, AuditLogEvent.MemberBanAdd))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === member.id)[0];
let type = "leave";
- if (auditLog) {
- if (auditLog.executor!.id === client.user!.id) return;
- if (auditLog.createdAt.valueOf() - 100 >= new Date().getTime()) {
+ if (kickAuditLog) {
+ if (kickAuditLog.executor!.id === client.user!.id) return;
+ if (kickAuditLog.createdAt.getTime() >= startTime) {
type = "kick";
}
}
+ if (banAuditLog) {
+ if (banAuditLog.executor!.id === client.user!.id) return;
+ if (banAuditLog.createdAt.getTime() >= startTime) {
+ if (!kickAuditLog) {
+ return
+ } else if (kickAuditLog.createdAt.valueOf() < banAuditLog.createdAt.valueOf()) {
+ return
+ }
+ }
+ }
let data;
if (type === "kick") {
- if (!auditLog) return;
- await client.database.history.create("kick", member.guild.id, member.user, auditLog.executor, auditLog.reason);
+ if (!kickAuditLog) return;
+ await client.database.history.create("kick", member.guild.id, member.user, kickAuditLog.executor, kickAuditLog.reason);
data = {
meta: {
type: "memberKick",
@@ -30,15 +44,15 @@
calculateType: "guildMemberPunish",
color: NucleusColors.red,
emoji: "PUNISH.KICK.RED",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member.user)),
joined: entry(member.joinedTimestamp, renderDelta(member.joinedTimestamp?.valueOf()!)),
- kicked: entry(new Date().getTime(), renderDelta(new Date().getTime())),
- kickedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
- reason: entry(auditLog.reason, auditLog.reason ? `\n> ${auditLog.reason}` : "*No reason provided.*"),
+ kicked: entry(Date.now(), renderDelta(Date.now())),
+ kickedBy: entry(kickAuditLog.executor!.id, renderUser(kickAuditLog.executor!)),
+ reason: entry(kickAuditLog.reason, kickAuditLog.reason ? `\n> ${kickAuditLog.reason}` : "*No reason provided.*"),
accountCreated: entry(member.user.createdTimestamp, renderDelta(member.user.createdTimestamp)),
serverMemberCount: member.guild.memberCount
},
@@ -55,13 +69,13 @@
calculateType: "guildMemberUpdate",
color: NucleusColors.red,
emoji: "MEMBER." + (member.user.bot ? "BOT." : "") + "LEAVE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member.user)),
joined: entry(member.joinedTimestamp, renderDelta(member.joinedTimestamp?.valueOf()!)),
- left: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ left: entry(Date.now(), renderDelta(Date.now())),
accountCreated: entry(member.user.createdTimestamp, renderDelta(member.user.createdTimestamp)),
serverMemberCount: member.guild.memberCount
},
diff --git a/src/events/messageCreate.ts b/src/events/messageCreate.ts
index 69bc542..4f525fc 100644
--- a/src/events/messageCreate.ts
+++ b/src/events/messageCreate.ts
@@ -19,12 +19,23 @@
console.log(e);
}
- const { log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const fileNames = await logAttachment(message);
const content = message.content.toLowerCase() || "";
const config = await client.memory.readGuildInfo(message.guild.id);
+ if(config.filters.clean.channels.includes(message.channel.id)) {
+ const memberRoles = message.member!.roles.cache.map(role => role.id);
+ const roleAllow = config.filters.clean.allowed.roles.some(role => memberRoles.includes(role));
+ const userAllow = config.filters.clean.allowed.users.includes(message.author.id);
+ if(!roleAllow && !userAllow) return await message.delete();
+ }
+
+ if (config.autoPublish.enabled && config.autoPublish.channels.includes(message.channel.id)) {
+ await message.crosspost();
+ }
+
const filter = getEmojiByName("ICONS.FILTER");
let attachmentJump = "";
if (config.logging.attachments.saved[message.channel.id + message.id]) {
@@ -34,7 +45,7 @@
messageId: entry(message.id, `\`${message.id}\``),
sentBy: entry(message.author.id, renderUser(message.author)),
sentIn: entry(message.channel.id, renderChannel(message.channel)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ deleted: entry(Date.now(), renderDelta(Date.now())),
mentions: message.mentions.users.size,
attachments: entry(message.attachments.size, message.attachments.size + attachmentJump),
repliedTo: entry(
@@ -57,7 +68,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -78,7 +89,8 @@
if (fileNames.files.length > 0) {
for (const element of fileNames.files) {
const url = element.url ? element.url : element.local;
- if (/\.(jpg|jpeg|png|gif|gifv|webm|webp|mp4|wav|mp3|ogg)$/.test(url)) {
+ if (/\.(j(pe?g|fif)|a?png|gifv?|w(eb[mp]|av)|mp([34]|eg-\d)|ogg|avi|h\.26(4|5)|cda)$/.test(url.toLowerCase())) {
+ // jpg|jpeg|png|apng|gif|gifv|webm|webp|mp4|wav|mp3|ogg|jfif|MPEG-#|avi|h.264|h.265
if (
config.filters.images.NSFW &&
!(message.channel instanceof ThreadChannel ? message.channel.parent?.nsfw : message.channel.nsfw)
@@ -93,7 +105,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -128,7 +140,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -158,7 +170,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -189,7 +201,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -221,7 +233,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -253,7 +265,7 @@
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start:
@@ -271,6 +283,7 @@
}
if (config.filters.pings.everyone && message.mentions.everyone) {
+ if(!await isLogging(message.guild.id, "messageMassPing")) return;
const data = {
meta: {
type: "everyonePing",
@@ -278,7 +291,7 @@
calculateType: "messageMassPing",
color: NucleusColors.yellow,
emoji: "MESSAGE.PING.EVERYONE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
@@ -295,6 +308,7 @@
if (!config.filters.pings.allowed.roles.includes(roleId)) {
messageException(message.guild.id, message.channel.id, message.id);
await message.delete();
+ if(!await isLogging(message.guild.id, "messageMassPing")) return;
const data = {
meta: {
type: "rolePing",
@@ -302,7 +316,7 @@
calculateType: "messageMassPing",
color: NucleusColors.yellow,
emoji: "MESSAGE.PING.ROLE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start: content
@@ -321,6 +335,7 @@
if (message.mentions.users.size >= config.filters.pings.mass && config.filters.pings.mass) {
messageException(message.guild.id, message.channel.id, message.id);
await message.delete();
+ if(!await isLogging(message.guild.id, "messageMassPing")) return;
const data = {
meta: {
type: "massPing",
@@ -328,7 +343,7 @@
calculateType: "messageMassPing",
color: NucleusColors.yellow,
emoji: "MESSAGE.PING.MASS",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
separate: {
start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
diff --git a/src/events/messageDelete.ts b/src/events/messageDelete.ts
index f8433fc..aac83f4 100644
--- a/src/events/messageDelete.ts
+++ b/src/events/messageDelete.ts
@@ -4,61 +4,59 @@
export const event = "messageDelete";
export async function callback(client: NucleusClient, message: Message) {
- try {
- 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!, 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.content.match(
- /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
- ) ?? []
- ).length;
- let attachmentJump = "";
- const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
- message.channel.id + message.id
- ];
- if (config) { attachmentJump = ` [[View attachments]](${config})`; }
- const data = {
- meta: {
- type: "messageDelete",
- displayName: "Message Deleted",
- calculateType: "messageDelete",
- color: NucleusColors.red,
- emoji: "MESSAGE.DELETE",
- timestamp: new Date().getTime()
- },
- separate: {
- start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
- },
- list: {
- messageId: entry(message.id, `\`${message.id}\``),
- sentBy: entry(message.author.id, renderUser(message.author)),
- 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.messageId! : null,
- replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
- : "None"
- )
- },
- hidden: {
- guild: message.guild!.id
- }
- };
- log(data);
- } catch (e) {
- console.log(e);
+ if (message.author.id === client.user!.id) return;
+ if (message.author.bot) return;
+ if (client.noLog.includes(`${message.guild!.id}/${message.channel.id}/${message.id}`)) return;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(message.guild!.id, "messageDelete")) 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 < Date.now()) 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.content.match(
+ /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&//=]*)/gi
+ ) ?? []
+ ).length;
+ let attachmentJump = "";
+ const config = (await client.database.guilds.read(message.guild!.id)).logging.attachments.saved[
+ message.channel.id + message.id
+ ];
+ if (config) { attachmentJump = ` [[View attachments]](${config})`; }
+ const data = {
+ meta: {
+ type: "messageDelete",
+ displayName: "Message Deleted",
+ calculateType: "messageDelete",
+ color: NucleusColors.red,
+ emoji: "MESSAGE.DELETE",
+ timestamp: Date.now()
+ },
+ separate: {
+ start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
+ },
+ list: {
+ messageId: entry(message.id, `\`${message.id}\``),
+ sentBy: entry(message.author.id, renderUser(message.author)),
+ sentIn: entry(message.channel.id, renderChannel(message.channel as Discord.GuildChannel | Discord.ThreadChannel)),
+ deleted: entry(Date.now(), renderDelta(Date.now())),
+ mentions: message.mentions.users.size,
+ attachments: entry(attachments, attachments + attachmentJump),
+ repliedTo: entry(
+ replyTo ? replyTo.messageId! : null,
+ replyTo ? `[[Jump to message]](https://discord.com/channels/${message.guild!.id}/${message.channel.id}/${replyTo.messageId})`
+ : "None"
+ )
+ },
+ hidden: {
+ guild: message.guild!.id
+ }
+ };
+ log(data);
}
diff --git a/src/events/messageEdit.ts b/src/events/messageEdit.ts
index 20624fe..f5a28a4 100644
--- a/src/events/messageEdit.ts
+++ b/src/events/messageEdit.ts
@@ -6,8 +6,10 @@
export async function callback(client: NucleusClient, oldMessage: Message, newMessage: Message) {
if (newMessage.author.id === client.user!.id) return;
+ if (newMessage.author.bot) return;
if (!newMessage.guild) return;
- const { log, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = client.logger;
+ const { log, isLogging, NucleusColors, entry, renderUser, renderDelta, renderNumberDelta, renderChannel } = client.logger;
+
const replyTo: MessageReference | null = newMessage.reference;
let newContent = newMessage.cleanContent.replaceAll("`", "‘");
let oldContent = oldMessage.cleanContent.replaceAll("`", "‘");
@@ -18,7 +20,8 @@
if (config) {
attachmentJump = ` [[View attachments]](${config})`;
}
- if (newContent === oldContent && newMessage.attachments.size === oldMessage.attachments.size) {
+ if (newMessage.crosspostable !== oldMessage.crosspostable) {
+ if(!await isLogging(newMessage.guild.id, "messageAnnounce")) return;
if (!replyTo) {
const data = {
meta: {
@@ -27,7 +30,7 @@
calculateType: "messageAnnounce",
color: NucleusColors.yellow,
emoji: "MESSAGE.CREATE",
- timestamp: newMessage.editedTimestamp
+ timestamp: newMessage.editedTimestamp ?? Date.now()
},
separate: {
end: `[[Jump to message]](${newMessage.url})`
@@ -57,6 +60,7 @@
return log(data);
}
}
+ if (!await isLogging(newMessage.guild.id, "messageUpdate")) return;
if (!newMessage.editedTimestamp) {
return;
}
diff --git a/src/events/roleCreate.ts b/src/events/roleCreate.ts
index d253ce7..be385f0 100644
--- a/src/events/roleCreate.ts
+++ b/src/events/roleCreate.ts
@@ -4,7 +4,8 @@
export const event = "roleCreate";
export async function callback(client: NucleusClient, role: Role) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderRole } = client.logger;
+ if (!await isLogging(role.guild.id, "guildRoleUpdate")) return;
if (role.managed) return;
const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id)[0]!;
diff --git a/src/events/roleDelete.ts b/src/events/roleDelete.ts
index f41241b..b207f4f 100644
--- a/src/events/roleDelete.ts
+++ b/src/events/roleDelete.ts
@@ -5,7 +5,8 @@
export const event = "roleDelete";
export async function callback(client: NucleusClient, role: Role) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(role.guild.id, "guildRoleUpdate")) return;
if (role.managed) return;
const auditLog = (await getAuditLog(role.guild as Guild, AuditLogEvent.RoleDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === role.id)[0]!;
@@ -34,7 +35,7 @@
members: entry(role.members.size, `${role.members.size}`),
deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
created: entry(role.createdTimestamp, renderDelta(role.createdTimestamp)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ deleted: entry(Date.now(), renderDelta(Date.now()))
},
hidden: {
guild: role.guild.id
diff --git a/src/events/roleUpdate.ts b/src/events/roleUpdate.ts
index 924ec3e..8d9ef10 100644
--- a/src/events/roleUpdate.ts
+++ b/src/events/roleUpdate.ts
@@ -5,16 +5,17 @@
export const event = "roleUpdate";
export async function callback(client: NucleusClient, oldRole: Role, newRole: Role) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger;
-
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderDelta, renderUser, renderRole } = client.logger;
+ if (!await isLogging(newRole.guild.id, "guildRoleUpdate")) return;
const auditLog = (await getAuditLog(newRole.guild as Guild, AuditLogEvent.RoleUpdate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === newRole.id)[0]!;
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Role)!.id === newRole.id)[0];
+ if (!auditLog) return;
if (auditLog.executor!.id === client.user!.id) return;
const changes: Record<string, ReturnType<typeof entry>> = {
roleId: entry(newRole.id, `\`${newRole.id}\``),
role: entry(newRole.id, renderRole(newRole)),
- edited: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ edited: entry(Date.now(), renderDelta(Date.now())),
editedBy: entry(auditLog.executor!.id, renderUser((await newRole.guild.members.fetch(auditLog.executor!.id)).user))
};
const mentionable = ["", ""];
@@ -31,6 +32,12 @@
changes["mentionable"] = entry([oldRole.mentionable, newRole.mentionable], `${mentionable[0]} -> ${mentionable[1]}`);
if (oldRole.hexColor !== newRole.hexColor)
changes["color"] = entry([oldRole.hexColor, newRole.hexColor], `\`${oldRole.hexColor}\` -> \`${newRole.hexColor}\``);
+ if (oldRole.permissions.bitfield !== newRole.permissions.bitfield) {
+ changes["permissions"] = entry(
+ [oldRole.permissions.bitfield.toString(), newRole.permissions.bitfield.toString()],
+ `[[Old]](https://discordapi.com/permissions.html#${oldRole.permissions.bitfield.toString()}) -> [[New]](https://discordapi.com/permissions.html#${newRole.permissions.bitfield.toString()})`
+ );
+ }
if (Object.keys(changes).length === 4) return;
@@ -47,6 +54,6 @@
hidden: {
guild: newRole.guild.id
}
- }; // TODO: show perms changed (webpage)
+ }; // TODO: make our own page for this
log(data);
}
diff --git a/src/events/stickerCreate.ts b/src/events/stickerCreate.ts
index b341ae9..5d2e443 100644
--- a/src/events/stickerCreate.ts
+++ b/src/events/stickerCreate.ts
@@ -1,13 +1,17 @@
import type { NucleusClient } from "../utils/client.js";
import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";
+import { generalException } from "../utils/createTemporaryStorage.js";
-export const event = "stickerDelete";
+export const event = "stickerCreate";
export async function callback(client: NucleusClient, sticker: Sticker) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
- const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.EmojiCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(sticker.guild!.id, "stickerUpdate")) return;
+ const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.StickerCreate))
+ .filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
+ if (client.noLog.includes(`${sticker.guild!.id}${auditLog.id}`)) return;
+ generalException(`${sticker.guild!.id}${auditLog.id}`);
const data = {
meta: {
type: "stickerCreate",
diff --git a/src/events/stickerDelete.ts b/src/events/stickerDelete.ts
index ce26a85..d123f44 100644
--- a/src/events/stickerDelete.ts
+++ b/src/events/stickerDelete.ts
@@ -4,7 +4,8 @@
export const event = "stickerDelete";
export async function callback(client: NucleusClient, sticker: Sticker) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
+ if (!await isLogging(sticker.guild!.id, "stickerUpdate")) return;
const auditLog = (await getAuditLog(sticker.guild!, AuditLogEvent.StickerDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -14,7 +15,7 @@
displayName: "Sticker Deleted",
calculateType: "stickerUpdate",
color: NucleusColors.red,
- sticker: "GUILD.sticker.DELETE",
+ emoji: "GUILD.EMOJI.DELETE",
timestamp: auditLog.createdTimestamp
},
list: {
diff --git a/src/events/stickerUpdate.ts b/src/events/stickerUpdate.ts
index ed01b71..aef28a4 100644
--- a/src/events/stickerUpdate.ts
+++ b/src/events/stickerUpdate.ts
@@ -4,8 +4,8 @@
export const event = "stickerUpdate";
export async function callback(client: NucleusClient, oldSticker: Sticker, newSticker: Sticker) {
- const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
-
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
+ if (!await isLogging(newSticker.guild!.id, "stickerUpdate")) return;
if (oldSticker.name === newSticker.name) return;
const auditLog = (await getAuditLog(newSticker.guild!, AuditLogEvent.StickerUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === newSticker.id)[0]!;
diff --git a/src/events/threadCreate.ts b/src/events/threadCreate.ts
index 6d3225c..f56e1bb 100644
--- a/src/events/threadCreate.ts
+++ b/src/events/threadCreate.ts
@@ -5,7 +5,8 @@
export const event = "threadCreate";
export async function callback(client: NucleusClient, thread: ThreadChannel) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(thread.guild.id, "channelUpdate")) return;
const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -22,7 +23,7 @@
calculateType: "channelUpdate",
color: NucleusColors.green,
emoji: "CHANNEL.TEXT.CREATE",
- timestamp: thread.createdTimestamp
+ timestamp: thread.createdTimestamp ?? Date.now()
},
list: {
threadId: entry(thread.id, `\`${thread.id}\``),
diff --git a/src/events/threadDelete.ts b/src/events/threadDelete.ts
index 429f63a..bfac75e 100644
--- a/src/events/threadDelete.ts
+++ b/src/events/threadDelete.ts
@@ -5,7 +5,8 @@
export const event = "threadDelete";
export async function callback(client: NucleusClient, thread: ThreadChannel) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(thread.guild.id, "channelUpdate")) return;
const auditLog = (await getAuditLog(thread.guild, AuditLogEvent.ThreadDelete))
.filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === thread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -22,7 +23,7 @@
calculateType: "channelUpdate",
color: NucleusColors.red,
emoji: "CHANNEL.TEXT.DELETE",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: {
threadId: entry(thread.id, `\`${thread.id}\``),
@@ -38,7 +39,7 @@
membersInThread: entry(thread.memberCount, thread.memberCount!.toString()),
deletedBy: entry(auditLog.executor!.id, renderUser(auditLog.executor!)),
created: entry(thread.createdTimestamp, renderDelta(thread.createdTimestamp!)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ deleted: entry(Date.now(), renderDelta(Date.now()))
},
hidden: {
guild: thread.guild.id
diff --git a/src/events/threadUpdate.ts b/src/events/threadUpdate.ts
index 555b17f..af792bc 100644
--- a/src/events/threadUpdate.ts
+++ b/src/events/threadUpdate.ts
@@ -6,7 +6,8 @@
export const event = "threadUpdate";
export async function callback(client: NucleusClient, oldThread: ThreadChannel, newThread: ThreadChannel) {
- const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ const { getAuditLog, isLogging, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
+ if (!await isLogging(newThread.guild.id, "channelUpdate")) return;
const auditLog = (await getAuditLog(newThread.guild, AuditLogEvent.ThreadUpdate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as ThreadChannel)!.id === newThread.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;
@@ -37,7 +38,7 @@
);
}
if (!(Object.keys(list).length - 3)) return;
- list["updated"] = entry(new Date().getTime(), renderDelta(new Date().getTime()));
+ list["updated"] = entry(Date.now(), renderDelta(Date.now()));
list["updatedBy"] = entry(auditLog.executor!.id, renderUser(auditLog.executor!));
const data = {
meta: {
@@ -46,7 +47,7 @@
calculateType: "channelUpdate",
color: NucleusColors.yellow,
emoji: "CHANNEL.TEXT.EDIT",
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: list,
hidden: {
diff --git a/src/events/webhookUpdate.ts b/src/events/webhookUpdate.ts
index e5f07dd..004f754 100644
--- a/src/events/webhookUpdate.ts
+++ b/src/events/webhookUpdate.ts
@@ -10,18 +10,18 @@
export async function callback(client: NucleusClient, channel: Discord.GuildChannel) {
try {
- const { getAuditLog, 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;
const auditCreate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookCreate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0]!;
- const auditDelete = (await getAuditLog(channel.guild, AuditLogEvent.WebhookDelete))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0];
- const auditUpdate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookUpdate))
- .filter((entry: GuildAuditLogsEntry) => (entry.target as Webhook)!.id === channel.id)[0];
-
- if (!auditUpdate && !auditDelete) return;
+ .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
+ const auditDelete = (await getAuditLog(channel.guild, AuditLogEvent.WebhookDelete, 0))
+ .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
+ const auditUpdate = (await getAuditLog(channel.guild, AuditLogEvent.WebhookUpdate, 0))
+ .filter((entry: GuildAuditLogsEntry | null) => (entry?.target) ? (entry.target as Webhook)!.channelId === channel.id : false)[0];
+ if (!auditCreate && !auditUpdate && !auditDelete) return;
let action: "Create" | "Update" | "Delete" = "Create";
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 updateTimestamp = auditUpdate ? auditUpdate.createdTimestamp : 0;
if (updateTimestamp > createTimestamp && updateTimestamp > deleteTimestamp && auditUpdate) {
@@ -46,7 +46,7 @@
(auditUpdate.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp,
renderDelta((auditUpdate.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp)
);
- list["edited"] = entry(after["editedTimestamp"]!, renderDelta(new Date().getTime()));
+ list["edited"] = entry(after["editedTimestamp"]!, renderDelta(Date.now()));
list["editedBy"] = entry(auditUpdate.executor!.id, renderUser(auditUpdate.executor!));
action = "Update";
} else if (deleteTimestamp > createTimestamp && deleteTimestamp > updateTimestamp && auditDelete) {
@@ -61,7 +61,7 @@
name: entry(before["name"]!, `${before["name"]}`),
channel: entry(before["channel_id"]!, renderChannel((await client.channels.fetch(before["channel_id"]!)) as GuildChannel)),
created: entry((auditDelete.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp, renderDelta((auditDelete.target! as Extract<GuildAuditLogsEntry, {createdTimestamp: number}>).createdTimestamp)),
- deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
+ deleted: entry(Date.now(), renderDelta(Date.now())),
deletedBy: entry(
auditDelete.executor!.id,
renderUser((await channel.guild.members.fetch(auditDelete.executor!.id)).user)
@@ -80,10 +80,10 @@
name: entry(before["name"]!, `${before["name"]}`),
channel: entry(before["channel_id"]!, renderChannel(await client.channels.fetch(before["channel_id"]!) as GuildChannel)),
createdBy: entry(
- auditCreate.executor!.id,
- renderUser((await channel.guild.members.fetch(auditCreate.executor!.id)).user)
+ auditCreate!.executor!.id,
+ renderUser((await channel.guild.members.fetch(auditCreate!.executor!.id)).user)
),
- created: entry(new Date().getTime(), renderDelta(new Date().getTime()))
+ created: entry(Date.now(), renderDelta(Date.now()))
};
}
const cols = {
@@ -98,7 +98,7 @@
calculateType: "webhookUpdate",
color: NucleusColors[cols[action] as keyof typeof NucleusColors],
emoji: "WEBHOOK." + action.toUpperCase(),
- timestamp: new Date().getTime()
+ timestamp: Date.now()
},
list: list,
hidden: {