fixing event logs

pull/11/head
TheCodedProf 3 years ago
parent cfe6308065
commit 6ec331b337

@ -11,7 +11,7 @@ for (let i = 0; i < 100; i++) {
Math.floor(Math.random() * 9)
];
// Select a random date in the last year
let date = new Date(new Date().getTime() - Math.floor(Math.random() * 31536000000));
let date = new Date(Date.now() - Math.floor(Math.random() * 31536000000));
// Add to database
await collection.insertOne({
type: type,

@ -157,12 +157,12 @@ export async function create(
calculateType: "ticketUpdate",
color: NucleusColors.green,
emoji: "GUILD.TICKET.OPEN",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: entry(user.id, renderUser(user)),
createdBy: entry(createdBy.id, renderUser(createdBy)),
created: entry((new Date().getTime()).toString(), renderDelta(new Date().getTime())),
created: entry((Date.now()).toString(), renderDelta(Date.now())),
ticketChannel: entry(c.id, renderChannel(c))
},
hidden: {

@ -323,11 +323,11 @@ export default async function (interaction: CommandInteraction | ButtonInteracti
calculateType: "ticketUpdate",
color: NucleusColors.green,
emoji: "GUILD.TICKET.OPEN",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: entry(interaction.member!.user.id, renderUser(interaction.member!.user! as Discord.User)),
created: entry(new Date().getTime(), renderDelta(new Date().getTime())),
created: entry(Date.now(), renderDelta(Date.now())),
ticketChannel: entry(c.id, renderChannel(c))
},
hidden: {

@ -50,7 +50,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
calculateType: "ticketUpdate",
color: NucleusColors.red,
emoji: "GUILD.TICKET.CLOSE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: entry(
@ -58,7 +58,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
renderUser((await interaction.guild.members.fetch(uID!)).user)
),
closedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
closed: entry(new Date().getTime(), renderDelta(new Date().getTime())),
closed: entry(Date.now(), renderDelta(Date.now())),
ticketChannel: entry(channel.id, channel.name)
},
hidden: {
@ -120,7 +120,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
calculateType: "ticketUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.TICKET.ARCHIVED",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: entry(
@ -128,7 +128,7 @@ export default async function (interaction: Discord.CommandInteraction | ButtonI
renderUser((await interaction.guild.members.fetch(uID!)).user)
),
archivedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
archived: entry(new Date().getTime(), renderDelta(new Date().getTime())),
archived: entry(Date.now(), renderDelta(Date.now())),
ticketChannel: entry(channel.id, renderChannel(channel))
},
hidden: {
@ -183,12 +183,12 @@ async function purgeByUser(member: string, guild: string) {
calculateType: "ticketUpdate",
color: NucleusColors.red,
emoji: "GUILD.TICKET.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: entry(member, renderUser(member)),
deletedBy: entry(null, "Member left server"),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())),
deleted: entry(Date.now(), renderDelta(Date.now())),
ticketsDeleted: deleted
},
hidden: {

@ -57,7 +57,7 @@ const runServer = (client: NucleusClient) => {
calculateType: "guildMemberVerify",
color: NucleusColors.green,
emoji: "CONTROL.BLOCKTICK",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
member: entry(member.id, renderUser(member.user)),

@ -122,12 +122,12 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
calculateType: "guildMemberPunish",
color: NucleusColors.red,
emoji: "PUNISH.BAN.RED",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
banned: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
banned: entry(Date.now().toString(), renderDelta(Date.now())),
bannedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
accountCreated: entry(member.user.createdTimestamp, renderDelta(member.user.createdTimestamp)),

@ -101,8 +101,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
await client.database.history.create("kick", interaction.guild.id, member.user, interaction.user, reason);
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
const timeInServer = member.joinedTimestamp ? entry(
(new Date().getTime() - member.joinedTimestamp).toString(),
humanizeDuration(new Date().getTime() - member.joinedTimestamp, {
(Date.now() - member.joinedTimestamp).toString(),
humanizeDuration(Date.now() - member.joinedTimestamp, {
round: true
})
) : entry(null, "*Unknown*")
@ -113,13 +113,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
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: undefined as (unknown | typeof entry),
kicked: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
kicked: entry(Date.now().toString(), renderDelta(Date.now())),
kickedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
timeInServer: timeInServer,

@ -235,8 +235,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
.setDescription(
`You have been muted in ${interaction.guild.name}` +
(reason ? ` for:\n${reason}` : ".\n*No reason was provided*") + "\n\n" +
`You will be unmuted at: <t:${Math.round(new Date().getTime() / 1000) + muteTime}:D> at ` +
`<t:${Math.round(new Date().getTime() / 1000) + muteTime}:T> (<t:${Math.round(new Date().getTime() / 1000) + muteTime
`You will be unmuted at: <t:${Math.round(Date.now() / 1000) + muteTime}:D> at ` +
`<t:${Math.round(Date.now() / 1000) + muteTime}:T> (<t:${Math.round(Date.now() / 1000) + muteTime
}:R>)` + "\n\n" +
(createAppealTicket
? `You can appeal this in the ticket created in <#${confirmation.components!["appeal"]!.response}>`
@ -267,10 +267,10 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
await member.timeout(muteTime * 1000, reason || "*No reason provided*");
if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role);
await client.database.eventScheduler.schedule("naturalUnmute", (new Date().getTime() + muteTime * 1000).toString(), {
await client.database.eventScheduler.schedule("naturalUnmute", (Date.now() + muteTime * 1000).toString(), {
guild: interaction.guild.id,
user: member.id,
expires: new Date().getTime() + muteTime * 1000
expires: Date.now() + muteTime * 1000
});
}
} else {
@ -282,7 +282,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
try {
if (config.moderation.mute.role !== null) {
await member.roles.add(config.moderation.mute.role);
await client.database.eventScheduler.schedule("unmuteRole", (new Date().getTime() + muteTime * 1000).toString(), {
await client.database.eventScheduler.schedule("unmuteRole", (Date.now() + muteTime * 1000).toString(), {
guild: interaction.guild.id,
user: member.id,
role: config.moderation.mute.role
@ -325,16 +325,16 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.WARN.YELLOW",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
mutedUntil: entry(
(new Date().getTime() + muteTime * 1000).toString(),
renderDelta(new Date().getTime() + muteTime * 1000)
(Date.now() + muteTime * 1000).toString(),
renderDelta(Date.now() + muteTime * 1000)
),
muted: entry(new Date().getTime.toString(), renderDelta(new Date().getTime() - 1000)),
muted: entry(new Date().getTime.toString(), renderDelta(Date.now() - 1000)),
mutedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as Discord.User)),
reason: entry(reason, reason ? reason : "*No reason provided*")
},

@ -156,13 +156,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "guildMemberUpdate",
color: NucleusColors.yellow,
emoji: "PUNISH.NICKNAME.YELLOW",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
before: entry(before, before ?? "*No nickname set*"),
after: entry(nickname ?? null, nickname ?? "*No nickname set*"),
updated: entry(new Date().getTime(), renderDelta(new Date().getTime())),
updated: entry(Date.now(), renderDelta(Date.now())),
updatedBy: entry(interaction.user.id, renderUser(interaction.user))
},
hidden: {

@ -148,7 +148,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "messageDelete",
color: NucleusColors.red,
emoji: "CHANNEL.PURGE.RED",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
@ -296,7 +296,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "messageDelete",
color: NucleusColors.red,
emoji: "CHANNEL.PURGE.RED",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),

@ -124,12 +124,12 @@ const callback = async (interaction: CommandInteraction): Promise<void> => {
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.BAN.YELLOW",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
softbanned: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
softbanned: entry(Date.now().toString(), renderDelta(Date.now())),
softbannedBy: entry(interaction.user.id, renderUser(interaction.user)),
reason: entry(reason, reason ? `\n> ${reason}` : "*No reason provided.*"),
accountCreated: entry(member.user.createdTimestamp, renderDelta(member.user.createdTimestamp)),

@ -57,12 +57,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.BAN.GREEN",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.id, `\`${member.id}\``),
name: entry(member.id, renderUser(member)),
unbanned: entry(new Date().getTime(), renderDelta(new Date().getTime())),
unbanned: entry(Date.now(), renderDelta(Date.now())),
unbannedBy: entry(interaction.user.id, renderUser(interaction.user)),
accountCreated: entry(member.createdTimestamp, renderDelta(member.createdTimestamp))
},

@ -105,12 +105,12 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.MUTE.GREEN",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(member.user.id, `\`${member.user.id}\``),
name: entry(member.user.id, renderUser(member.user)),
unmuted: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
unmuted: entry(Date.now().toString(), renderDelta(Date.now())),
unmutedBy: entry(interaction.user.id, renderUser(interaction.user))
},
hidden: {

@ -116,7 +116,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
calculateType: "guildMemberPunish",
color: NucleusColors.yellow,
emoji: "PUNISH.WARN.YELLOW",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
user: entry(

@ -10,9 +10,9 @@ const command = (builder: SlashCommandSubcommandBuilder) =>
const callback = async (interaction: CommandInteraction): Promise<void> => {
// WEBSOCKET | Nucleus -> Discord
// EDITING | Nucleus -> discord -> nucleus | edit time / 2
const initial = new Date().getTime();
const initial = Date.now();
await interaction.reply({ embeds: LoadingEmbed, ephemeral: true });
const ping = new Date().getTime() - initial;
const ping = Date.now() - initial;
interaction.editReply({
embeds: [
new EmojiEmbed()

@ -107,7 +107,7 @@
"text": null,
"link": null
},
"nickname": {
"nick": {
"text": null,
"link": null
}

@ -171,7 +171,7 @@ const callback = async (interaction: MessageContextMenuCommandInteraction) => {
calculateType: "messageDelete",
color: NucleusColors.red,
emoji: "PUNISH.BAN.RED",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),

@ -4,7 +4,8 @@ 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 { 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 @@ export async function callback(client: NucleusClient, channel: GuildBasedChannel
calculateType: "channelUpdate",
color: NucleusColors.green,
emoji: emoji,
timestamp: channel.createdTimestamp
timestamp: channel.createdTimestamp ?? Date.now()
},
list: {
channelId: entry(channel.id, `\`${channel.id}\``),

@ -14,7 +14,8 @@ import getEmojiByName from "../utils/getEmojiByName.js";
export const event = "channelDelete";
export async function callback(client: NucleusClient, channel: GuildBasedChannel) {
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
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;
@ -81,7 +82,7 @@ export async function callback(client: NucleusClient, channel: GuildBasedChannel
),
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)

@ -32,11 +32,11 @@ interface channelChanges {
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 @@ interface channelChanges {
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 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
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 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
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 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
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 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
} 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 @@ export async function callback(client: NucleusClient, oldChannel: GuildChannel,
if ((oldChannel as StageChannel).rtcRegion !== (newChannel as StageChannel).rtcRegion)
changes.region = entry(
[(oldChannel as StageChannel).rtcRegion ?? "Automatic", (newChannel as StageChannel).rtcRegion ?? "Automatic"],
`${capitalize((oldChannel as StageChannel).rtcRegion?.toUpperCase() ?? "automatic")} -> ${capitalize((newChannel as StageChannel).rtcRegion?.toUpperCase() ?? "automatic")}`
`${capitalize((oldChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic")} -> ${capitalize((newChannel as StageChannel).rtcRegion?.toLowerCase() ?? "automatic")}`
);
break;
}

@ -4,9 +4,10 @@ import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
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 = {

@ -4,7 +4,8 @@ import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
export const event = "emojiDelete";
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];
if (!auditLog) return;

@ -4,7 +4,8 @@ import type { GuildEmoji, GuildAuditLogsEntry } from 'discord.js'
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))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildEmoji)!.id === newEmoji.id)[0];

@ -7,10 +7,11 @@ import type { NucleusClient } from "../utils/client.js";
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 @@ export async function callback(client: NucleusClient, ban: GuildBan) {
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)),

@ -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 @@ export async function callback(client: NucleusClient, ban: GuildBan) {
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))
},

@ -4,7 +4,8 @@ import type { NucleusClient } from "../utils/client.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 { log, isLogging, NucleusColors, entry, renderUser, renderDelta, getAuditLog } = client.logger;
if (!await isLogging(after.guild.id, "memberUpdate")) return;
const auditLog = (await getAuditLog(after.guild, AuditLogEvent.EmojiCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as GuildMember)!.id === after.id)[0];
if (!auditLog) return;
@ -26,14 +27,14 @@ export async function callback(client: NucleusClient, before: GuildMember, after
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: {
@ -42,8 +43,8 @@ export async function callback(client: NucleusClient, before: GuildMember, after
};
log(data);
} else if (
(before.communicationDisabledUntilTimestamp ?? 0) < new Date().getTime() &&
(after.communicationDisabledUntil ?? 0) > new Date().getTime()
(before.communicationDisabledUntilTimestamp ?? 0) < Date.now() &&
(after.communicationDisabledUntil ?? 0) > Date.now()
) {
await client.database.history.create(
"mute",
@ -62,7 +63,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
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 +72,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
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*")
},
@ -88,7 +89,7 @@ export async function callback(client: NucleusClient, before: GuildMember, after
} else if (
after.communicationDisabledUntil === null &&
before.communicationDisabledUntilTimestamp !== null &&
new Date().getTime() >= auditLog.createdTimestamp
Date.now() >= auditLog.createdTimestamp
) {
await client.database.history.create(
"unmute",
@ -107,12 +108,12 @@ export async function callback(client: NucleusClient, before: GuildMember, after
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: {

@ -6,7 +6,8 @@ export const event = "guildUpdate";
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 @@ export async function callback(client: NucleusClient, before: Guild, after: Guil
);
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 @@ export async function callback(client: NucleusClient, before: Guild, after: Guil
calculateType: "guildUpdate",
color: NucleusColors.yellow,
emoji: "GUILD.YELLOW",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: list,
hidden: {

@ -7,7 +7,8 @@ export const event = "inviteCreate";
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 @@ export async function callback(client: NucleusClient, invite: Invite) {
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)),

@ -7,7 +7,8 @@ export const event = "inviteDelete";
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 @@ export async function callback(client: NucleusClient, invite: Invite) {
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

@ -8,7 +8,8 @@ export const event = "guildMemberAdd";
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 @@ export async function callback(client: NucleusClient, member: GuildMember) {
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}\``),

@ -7,22 +7,36 @@ import { callback as statsChannelRemove } from "../reflex/statsChannelUpdate.js"
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 @@ export async function callback(client: NucleusClient, member: GuildMember) {
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 @@ export async function callback(client: NucleusClient, member: GuildMember) {
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
},

@ -19,7 +19,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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);
@ -45,7 +45,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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(
@ -68,7 +68,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -105,7 +105,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -140,7 +140,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -170,7 +170,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -201,7 +201,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -233,7 +233,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -265,7 +265,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "autoModeratorDeleted",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start:
@ -283,6 +283,7 @@ export async function callback(_client: NucleusClient, message: Message) {
}
if (config.filters.pings.everyone && message.mentions.everyone) {
if(!await isLogging(message.guild.id, "messageMassPing")) return;
const data = {
meta: {
type: "everyonePing",
@ -290,7 +291,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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*"
@ -307,6 +308,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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",
@ -314,7 +316,7 @@ export async function callback(_client: NucleusClient, message: Message) {
calculateType: "messageMassPing",
color: NucleusColors.yellow,
emoji: "MESSAGE.PING.ROLE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start: content
@ -333,6 +335,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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",
@ -340,7 +343,7 @@ export async function callback(_client: NucleusClient, message: Message) {
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*"

@ -7,11 +7,12 @@ export async function callback(client: NucleusClient, message: Message) {
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, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
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 < new Date().getTime()) return;
if (auditLog.createdTimestamp - 1000 < Date.now()) return;
}
const replyTo = message.reference;
let content = message.cleanContent;
@ -35,7 +36,7 @@ export async function callback(client: NucleusClient, message: Message) {
calculateType: "messageDelete",
color: NucleusColors.red,
emoji: "MESSAGE.DELETE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
separate: {
start: content ? `**Message:**\n\`\`\`${content}\`\`\`` : "**Message:** *Message had no content*"
@ -44,7 +45,7 @@ export async function callback(client: NucleusClient, message: Message) {
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())),
deleted: entry(Date.now(), renderDelta(Date.now())),
mentions: message.mentions.users.size,
attachments: entry(attachments, attachments + attachmentJump),
repliedTo: entry(

@ -8,7 +8,8 @@ export async function callback(client: NucleusClient, oldMessage: Message, newMe
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("`", "");
@ -20,6 +21,7 @@ export async function callback(client: NucleusClient, oldMessage: Message, newMe
attachmentJump = ` [[View attachments]](${config})`;
}
if (newMessage.crosspostable !== oldMessage.crosspostable) {
if(!await isLogging(newMessage.guild.id, "messageAnnounce")) return;
if (!replyTo) {
const data = {
meta: {
@ -28,7 +30,7 @@ export async function callback(client: NucleusClient, oldMessage: Message, newMe
calculateType: "messageAnnounce",
color: NucleusColors.yellow,
emoji: "MESSAGE.CREATE",
timestamp: newMessage.editedTimestamp
timestamp: newMessage.editedTimestamp ?? Date.now()
},
separate: {
end: `[[Jump to message]](${newMessage.url})`
@ -58,6 +60,7 @@ export async function callback(client: NucleusClient, oldMessage: Message, newMe
return log(data);
}
}
if (!await isLogging(newMessage.guild.id, "messageUpdate")) return;
if (!newMessage.editedTimestamp) {
return;
}

@ -4,7 +4,8 @@ import { AuditLogEvent, Guild, GuildAuditLogsEntry, Role } from "discord.js";
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]!;

@ -5,7 +5,8 @@ import { AuditLogEvent, Guild, GuildAuditLogsEntry, Role } from "discord.js";
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 @@ export async function callback(client: NucleusClient, role: Role) {
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

@ -5,8 +5,8 @@ import getEmojiByName from "../utils/getEmojiByName.js";
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];
if (!auditLog) return;
@ -15,7 +15,7 @@ export async function callback(client: NucleusClient, oldRole: Role, newRole: Ro
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 = ["", ""];

@ -4,7 +4,8 @@ import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";
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.EmojiCreate))
.filter((entry: GuildAuditLogsEntry) => (entry.target as Sticker)!.id === sticker.id)[0]!;
if (auditLog.executor!.id === client.user!.id) return;

@ -4,7 +4,8 @@ import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";
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,8 +15,8 @@ export async function callback(client: NucleusClient, sticker: Sticker) {
displayName: "Sticker Deleted",
calculateType: "stickerUpdate",
color: NucleusColors.red,
sticker: "GUILD.sticker.DELETE",
timestamp: auditLog.createdTimestamp
emoji: "GUILD.STICKER.DELETE",
timestamp: auditLog.createdTimestamp ?? Date.now()
},
list: {
stickerId: entry(sticker.id, `\`${sticker.id}\``),

@ -4,8 +4,8 @@ import { AuditLogEvent, GuildAuditLogsEntry, Sticker } from "discord.js";
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]!;

@ -5,7 +5,8 @@ import type { NucleusClient } from "../utils/client.js";
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 @@ export async function callback(client: NucleusClient, thread: ThreadChannel) {
calculateType: "channelUpdate",
color: NucleusColors.green,
emoji: "CHANNEL.TEXT.CREATE",
timestamp: thread.createdTimestamp
timestamp: thread.createdTimestamp ?? Date.now()
},
list: {
threadId: entry(thread.id, `\`${thread.id}\``),

@ -5,7 +5,8 @@ import type { NucleusClient } from "../utils/client.js";
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 @@ export async function callback(client: NucleusClient, thread: ThreadChannel) {
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 @@ export async function callback(client: NucleusClient, thread: ThreadChannel) {
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

@ -6,7 +6,8 @@ import type { NucleusClient } from "../utils/client.js";
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 @@ export async function callback(client: NucleusClient, oldThread: ThreadChannel,
);
}
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 @@ export async function callback(client: NucleusClient, oldThread: ThreadChannel,
calculateType: "channelUpdate",
color: NucleusColors.yellow,
emoji: "CHANNEL.TEXT.EDIT",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: list,
hidden: {

@ -10,7 +10,8 @@ interface accType {
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))
@ -46,7 +47,7 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
(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 +62,7 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
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)
@ -83,7 +84,7 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
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 +99,7 @@ export async function callback(client: NucleusClient, channel: Discord.GuildChan
calculateType: "webhookUpdate",
color: NucleusColors[cols[action] as keyof typeof NucleusColors],
emoji: "WEBHOOK." + action.toUpperCase(),
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: list,
hidden: {

@ -265,12 +265,12 @@ export default async function (interaction: CommandInteraction | MessageComponen
calculateType: "ticketUpdate",
color: NucleusColors.red,
emoji: "GUILD.TICKET.CLOSE",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
ticketFor: member ? entry(member.id, renderUser(member.user)) : entry(null, "*Unknown*"),
deletedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user as User)),
deleted: entry(new Date().getTime().toString(), renderDelta(new Date().getTime()))
deleted: entry(Date.now().toString(), renderDelta(Date.now()))
},
hidden: {
guild: interaction.guild!.id

@ -1,4 +1,4 @@
import Discord, { Client, Interaction, AutocompleteInteraction, GatewayIntentBits, Collection } from 'discord.js';
import Discord, { Client, Interaction, AutocompleteInteraction, Collection } from 'discord.js';
import { Logger } from "../utils/log.js";
import Memory from "../utils/memory.js";
import type { VerifySchema } from "../reflex/verify.js";
@ -35,13 +35,7 @@ class NucleusClient extends Client {
} | undefined,{name: string, description: string}]> = {};
fetchedCommands = new Collection<string, Discord.ApplicationCommand>();
constructor(database: typeof NucleusClient.prototype.database) {
super({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMembers
]});
super({ intents: 0b1100011011011111111111});
this.database = database;
}
}

@ -215,7 +215,7 @@ export default async function register() {
} else {
console.log(`${colors.blue}Registering commands in production mode${colors.none}`)
const guild = await client.guilds.fetch(config.developmentGuildID);
await guild.commands.set([]); // TODO: Why isn't this removing guild commands?
await guild.commands.set([]);
await client.application?.commands.set(commandList);
}
}

@ -261,7 +261,7 @@ export class Premium {
async checkAllPremium() {
const entries = await this.premium.find({}).toArray();
for(const {user, expiresAt} of entries) {
if(expiresAt) expiresAt < new Date().getTime() ? await this.premium.deleteOne({user: user}) : null;
if(expiresAt) expiresAt < Date.now() ? await this.premium.deleteOne({user: user}) : null;
const member = await (await client.guilds.fetch("684492926528651336")).members.fetch(user)
let level: number = 0;
if (member.roles.cache.has("1066468879309750313")) {
@ -277,7 +277,7 @@ export class Premium {
if (level > 0) {
await this.updateUser(user, level);
} else {
await this.premium.updateOne({ user: user }, { expiresAt: (new Date().getTime() + (1000*60*60*24*3)) })
await this.premium.updateOne({ user: user }, { expiresAt: (Date.now() + (1000*60*60*24*3)) })
}
}
}

@ -43,12 +43,12 @@ class EventScheduler {
calculateType: "guildMemberPunish",
color: NucleusColors.green,
emoji: "PUNISH.MUTE.GREEN",
timestamp: new Date().getTime()
timestamp: Date.now()
},
list: {
memberId: entry(user.user.id, `\`${user.user.id}\``),
name: entry(user.user.id, renderUser(user.user)),
unmuted: entry(new Date().getTime().toString(), renderDelta(new Date().getTime())),
unmuted: entry(Date.now().toString(), renderDelta(Date.now())),
unmutedBy: entry(null, "*Time out ended*")
},
hidden: {

@ -7,6 +7,33 @@ import client from "./client.js";
const wait = promisify(setTimeout);
export interface LoggerOptions {
meta: {
type: string;
displayName: string;
calculateType: string;
color: number;
emoji: string;
timestamp: number;
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
list: any;
hidden: {
guild: string;
},
separate?: {
start?: string;
end?: string;
}
}
async function isLogging(guild: string, type: string): Promise<boolean> {
const config = await client.database.guilds.read(guild);
if (!config.logging.logs.enabled) return false;
if (!config.logging.logs.channel) return false;
if (!toHexArray(config.logging.logs.toLog).includes(type)) { return false; }
return true;
}
export const Logger = {
renderUser(user: Discord.User | string) {
@ -50,13 +77,9 @@ export const Logger = {
const auditLog = (await guild.fetchAuditLogs({ type: event })).entries.map(m => m)
return auditLog as Discord.GuildAuditLogsEntry[];
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async log(log: any): Promise<void> {
async log(log: LoggerOptions): Promise<void> {
if (!await isLogging(log.hidden.guild, log.meta.calculateType)) return;
const config = await client.database.guilds.read(log.hidden.guild);
if (!config.logging.logs.enabled) return;
if (!toHexArray(config.logging.logs.toLog).includes(log.meta.calculateType)) {
return;
}
if (config.logging.logs.channel) {
const channel = (await client.channels.fetch(config.logging.logs.channel)) as Discord.TextChannel | null;
const description: Record<string, string> = {};
@ -84,8 +107,8 @@ export const Logger = {
channel.send({ embeds: [embed] });
}
}
}
},
isLogging
};
export default {};

@ -12,7 +12,7 @@ export default function generateFileName(ending: string): string {
if (fs.existsSync(`./${fileName}`)) {
fileName = generateFileName(ending);
}
client.database.eventScheduler.schedule("deleteFile", (new Date().getTime() + 60 * 1000).toString(), {
client.database.eventScheduler.schedule("deleteFile", (Date.now() + 60 * 1000).toString(), {
fileName: `${fileName}.${ending}`
});
return path.join(__dirname, fileName + "." + ending);

Loading…
Cancel
Save