Skip to content

Commit

Permalink
Mod-logs feature, Bug fixes, and small updates
Browse files Browse the repository at this point in the history
  • Loading branch information
TFAGaming committed Mar 17, 2024
1 parent 30e30f2 commit 0072799
Show file tree
Hide file tree
Showing 11 changed files with 208 additions and 20 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module.exports = {
permissions?: PermissionResolvable,
cooldown?: number,
globalCooldown?: boolean,
ownerOnly?: boolean,
developers?: boolean,
nsfw?: boolean
},
Expand All @@ -51,6 +52,7 @@ module.exports = {
options?: {
cooldown?: number,
globalCooldown?: boolean,
ownerOnly?: boolean,
developers?: boolean,
nsfw?: boolean
},
Expand Down
11 changes: 9 additions & 2 deletions src/class/ExtendedClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,15 @@ module.exports = class extends Client {

constructor() {
super({
intents: [Object.keys(GatewayIntentBits)],
partials: [Object.keys(Partials)],
intents: 3276799, // Every intent
partials: [
Partials.Channel,
Partials.GuildMember,
Partials.Message,
Partials.Reaction,
Partials.User,
Partials.ThreadMember
],
presence: {
activities: [{
name: 'something goes here',
Expand Down
6 changes: 5 additions & 1 deletion src/commands/slash/Developers/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = {
.setRequired(true)
),
options: {
developers: true,
ownerOnly: true
},
/**
* @param {ExtendedClient} client
Expand All @@ -33,6 +33,10 @@ module.exports = {

if (typeof executedEvalValue !== 'string') executedEvalValue = require('util').inspect(executedEvalValue);

executedEvalValue = `${executedEvalValue}` // Making sure it's string

executedEvalValue = executedEvalValue.replace(new RegExp(client.token, 'gi'), '?');

await interaction.editReply({
embeds: [
new EmbedBuilder()
Expand Down
2 changes: 0 additions & 2 deletions src/commands/slash/Developers/set-animated-pfp.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ module.exports = {
return;
};

console.log(attachment)

await client.user.setAvatar(attachment.proxyURL)
.then(async () => {
await interaction.editReply({
Expand Down
43 changes: 43 additions & 0 deletions src/events/GuildEvents/guildBanAdd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const config = require('../../config');
const ExtendedClient = require('../../class/ExtendedClient');
const { EmbedBuilder } = require('discord.js');
const { time } = require('../../functions');

module.exports = {
event: 'guildBanAdd',
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').GuildBan} ban
* @returns
*/
run: async (client, ban) => {

if (!(config.channels.modLogs.enabled && config.channels.modLogs.channel)) return;

const modLogsChannel = client.channels.cache.get(config.channels.modLogs.channel);

if (!modLogsChannel || modLogsChannel.guildId !== ban.guild.id) return;

try {
const data = [
`**User**: ${ban.user.toString()}`,
`**Reason**: ${ban.reason}`,
`**Date**: ${time(Date.now(), 'D')} (${time(Date.now(), 'R')})`,
];

await modLogsChannel.send({
embeds: [
new EmbedBuilder()
.setTitle('Guild Ban Add')
.setThumbnail(message.author.displayAvatarURL())
.setDescription(data.join('\n'))
.setColor('Red')
]
});
} catch (err) {
console.error(err);
};

}
};
45 changes: 45 additions & 0 deletions src/events/GuildEvents/messageDelete.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const config = require('../../config');
const ExtendedClient = require('../../class/ExtendedClient');
const { EmbedBuilder } = require('discord.js');
const { time } = require('../../functions');

module.exports = {
event: 'messageDelete',
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Message} message
* @returns
*/
run: async (client, message) => {

if (!(config.channels.modLogs.enabled && config.channels.modLogs.channel)) return;

const modLogsChannel = client.channels.cache.get(config.channels.modLogs.channel);

if (!modLogsChannel || modLogsChannel.guildId !== message.guild.id) return;

if (message.author.bot) return;

try {
const data = [
`**Content**: ${message.content}`,
`**Author**: ${message.author.toString()}`,
`**Date**: ${time(Date.now(), 'D')} (${time(Date.now(), 'R')})`,
];

await modLogsChannel.send({
embeds: [
new EmbedBuilder()
.setTitle('Message Delete')
.setThumbnail(message.author.displayAvatarURL())
.setDescription(data.join('\n'))
.setColor('Yellow')
]
});
} catch (err) {
console.error(err);
};

}
};
47 changes: 47 additions & 0 deletions src/events/GuildEvents/messageUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const config = require('../../config');
const ExtendedClient = require('../../class/ExtendedClient');
const { EmbedBuilder } = require('discord.js');
const { time, log } = require('../../functions');

module.exports = {
event: 'messageUpdate',
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Message} oldMessage
* @param {import('discord.js').Message} newMessage
* @returns
*/
run: async (client, oldMessage, newMessage) => {

if (!(config.channels.modLogs.enabled && config.channels.modLogs.channel)) return;

const modLogsChannel = client.channels.cache.get(config.channels.modLogs.channel);

if (!modLogsChannel || modLogsChannel.guildId !== newMessage.guildId) return;

if (oldMessage.author.bot || newMessage.author.bot) return;

try {
const data = [
`**Old**: ${oldMessage.content}`,
`**Updated**: ${newMessage.content}`,
`**Author**: ${newMessage.author.toString()}`,
`**Date**: ${time(Date.now(), 'D')} (${time(Date.now(), 'R')})`,
];

await modLogsChannel.send({
embeds: [
new EmbedBuilder()
.setTitle('Message Update')
.setThumbnail(newMessage.author.displayAvatarURL())
.setDescription(data.join('\n'))
.setColor('Yellow')
]
});
} catch (err) {
console.error(err);
};

}
};
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ module.exports = {
if (!command) return;

try {
if (command.options?.ownerOnly) {
if (interaction.user.id !== config.users.ownerId) {
await interaction.reply({
content:
config.messageSettings.ownerMessage !== undefined &&
config.messageSettings.ownerMessage !== null &&
config.messageSettings.ownerMessage !== ""
? config.messageSettings.ownerMessage
: "The bot developer has the only permissions to use this command.",
ephemeral: true
});

return;
}
}

if (command.options?.developers) {
if (
config.users?.developers?.length > 0 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ module.exports = {

if (command) {
try {
if (command.structure?.ownerOnly) {
if (message.author.id !== config.users.ownerId) {
await message.reply({
content:
config.messageSettings.ownerMessage !== undefined &&
config.messageSettings.ownerMessage !== null &&
config.messageSettings.ownerMessage !== ""
? config.messageSettings.ownerMessage
: "The bot developer has the only permissions to use this command.",
ephemeral: true
});

return;
}
}

if (
command.structure?.permissions &&
!message.member.permissions.has(command.structure?.permissions)
Expand All @@ -57,26 +73,26 @@ module.exports = {
config.messageSettings.notHasPermissionMessage !== ""
? config.messageSettings.notHasPermissionMessage
: "You do not have the permission to use this command.",
ephemeral: true
});

return;
}

if (command.structure?.developers) {
if (!config.users.developers.includes(message.author.id)) {
setTimeout(async () => {
await message.reply({
content:
config.messageSettings.developerMessage !== undefined &&
config.messageSettings.developerMessage !== null &&
config.messageSettings.developerMessage !== ""
? config.messageSettings.developerMessage
: "You are not authorized to use this command",
});
}, 5 * 1000);
await message.reply({
content:
config.messageSettings.developerMessage !== undefined &&
config.messageSettings.developerMessage !== null &&
config.messageSettings.developerMessage !== ""
? config.messageSettings.developerMessage
: "You are not authorized to use this command",
ephemeral: true
});

return;
}

return;
}

if (command.structure?.nsfw && !message.channel.nsfw) {
Expand All @@ -87,6 +103,7 @@ module.exports = {
config.messageSettings.nsfwMessage !== ""
? config.messageSettings.nsfwMessage
: "The current channel is not a NSFW channel.",
ephemeral: true
});

return;
Expand Down Expand Up @@ -124,6 +141,7 @@ module.exports = {
config.messageSettings.cooldownMessage !== ""
? config.messageSettings.cooldownMessage
: "Slow down buddy! You're too fast to use this command ({cooldown}s).").replace(/{cooldown}/g, command.structure.cooldown / 1000),
ephemeral: true
});

return;
Expand Down
14 changes: 11 additions & 3 deletions src/example.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,25 @@ module.exports = {
},
},
users: {
developers: ["Your account ID"],
developers: ["Your account ID", "Another account ID"],
ownerId: "Your account ID"
},
channels: {
modLogs: {
enabled: true,
channel: "The moderation-logs channel"
}
},
development: {
enabled: false,
guild: "Enter your guild ID here or you can use .env",
},
messageSettings: {
nsfwMessage: "The current channel is not a NSFW channel.",
ownerMessage: "The bot developer has the only permissions to use this command.",
developerMessage: "You are not authorized to use this command.",
cooldownMessage: "Slow down buddy! You're too fast to use this command ({cooldown}s).",
globalCooldownMessage: "Slow down buddy! This command is on a global cooldown ({cooldown}s).",
cooldownMessage: "Slow down buddy! You're too fast to use this command ({cooldown}s).", // '{cooldown}' is a variable that shows the time to use the command again (in seconds)
globalCooldownMessage: "Slow down buddy! This command is on a global cooldown ({cooldown}s).", // '{cooldown}' is a variable that shows the time to use the command again (in seconds)
notHasPermissionMessage: "You do not have the permission to use this command.",
notHasPermissionComponent: "You do not have the permission to use this component.",
missingDevIDsMessage: "This is a developer only command, but unable to execute due to missing user IDs in configuration file."
Expand Down

0 comments on commit 0072799

Please sign in to comment.