Skip to content

Commit

Permalink
Merge pull request #43 from codeblitz97/main
Browse files Browse the repository at this point in the history
Add NSFW Only command and developers command in message
  • Loading branch information
TFAGaming authored Aug 30, 2023
2 parents e819bbe + 76cd91c commit 31cc270
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 125 deletions.
23 changes: 23 additions & 0 deletions src/commands/prefix/Developers/eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { Message } = require("discord.js");
const ExtendedClient = require("../../../class/ExtendedClient");

module.exports = {
structure: {
name: "eval",
description: "Execute some codes!",
aliases: ["e"],
cooldown: 0,
},
/**
* @param {ExtendedClient} client
* @param {Message} message
* @param {[String]} args
*/
run: async (client, message, args) => {
const evaled = eval(args.join(" "));

await message.reply({
content: String(evaled),
});
},
};
2 changes: 1 addition & 1 deletion src/commands/slash/Developers/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ module.exports = {
.setTitle("Code executed")
.setDescription(`The return output was:\n${executedEvalValue}`);

await interaction.reply({ embeds: [embed] });
await interaction.editReply({ embeds: [embed] });
},
};
25 changes: 25 additions & 0 deletions src/commands/slash/Nsfw/nsfw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const {
ChatInputCommandInteraction,
SlashCommandBuilder,
EmbedBuilder,
} = require("discord.js");
const ExtendedClient = require("../../../class/ExtendedClient");
const config = require("../../../config");
const GuildSchema = require("../../../schemas/GuildSchema");

module.exports = {
structure: new SlashCommandBuilder()
.setName("nsfw")
.setDescription("Nsfw command."),
/**
* @param {ExtendedClient} client
* @param {ChatInputCommandInteraction} interaction
* @param {[]} args
*/
options: {
nsfw: true,
},
run: async (client, interaction, args) => {
await interaction.reply({ content: "NSFW Command!" });
},
};
10 changes: 10 additions & 0 deletions src/events/Guild/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ module.exports = {
});
}
}

if (command.options?.nsfw) {
if (!interaction.channel.nsfw) {
return interaction.reply({
content: "NSFW Command. Execute this command on a NSFW Channel.",
ephemeral: true,
});
}
}

if (command.options?.cooldown) {
const cooldownFunction = () => {
let data = cooldown.get(interaction.user.id);
Expand Down
182 changes: 101 additions & 81 deletions src/events/Guild/messageCreate.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,119 @@
const { ChannelType, Message } = require('discord.js');
const config = require('../../config');
const { log } = require('../../functions');
const GuildSchema = require('../../schemas/GuildSchema');
const ExtendedClient = require('../../class/ExtendedClient');
const { ChannelType, Message } = require("discord.js");
const config = require("../../config");
const { log } = require("../../functions");
const GuildSchema = require("../../schemas/GuildSchema");
const ExtendedClient = require("../../class/ExtendedClient");

const cooldown = new Map();

module.exports = {
event: 'messageCreate',
/**
*
* @param {ExtendedClient} client
* @param {Message} message
* @returns
*/
run: async (client, message) => {
if (message.author.bot || message.channel.type === ChannelType.DM) return;

if (!config.handler.commands.prefix) return;

let prefix = config.handler.prefix;

if (config.handler?.mongodb?.toggle) {
try {
const guildData = await GuildSchema.findOne({ guild: message.guildId });

if (guildData && guildData?.prefix) prefix = guildData.prefix;
} catch {
prefix = config.handler.prefix;
};
};

if (!message.content.startsWith(prefix)) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const commandInput = args.shift().toLowerCase();

if (!commandInput.length) return;

let command = client.collection.prefixcommands.get(commandInput) || client.collection.prefixcommands.get(client.collection.aliases.get(commandInput));

if (command) {
try {
if (command.structure?.permissions && !message.member.permissions.has(command.structure?.permissions)) {
await message.reply({
content: 'You do not have the permission to use this command.'
});

return;
};
event: "messageCreate",
/**
*
* @param {ExtendedClient} client
* @param {Message} message
* @returns
*/
run: async (client, message) => {
if (message.author.bot || message.channel.type === ChannelType.DM) return;

if (!config.handler.commands.prefix) return;

let prefix = config.handler.prefix;

if (config.handler?.mongodb?.toggle) {
try {
const guildData = await GuildSchema.findOne({ guild: message.guildId });

if (guildData && guildData?.prefix) prefix = guildData.prefix;
} catch {
prefix = config.handler.prefix;
}
}

if (!message.content.startsWith(prefix)) return;

const args = message.content.slice(prefix.length).trim().split(/ +/g);
const commandInput = args.shift().toLowerCase();

if (!commandInput.length) return;

let command =
client.collection.prefixcommands.get(commandInput) ||
client.collection.prefixcommands.get(
client.collection.aliases.get(commandInput)
);

if (command) {
try {
if (
command.structure?.permissions &&
!message.member.permissions.has(command.structure?.permissions)
) {
await message.reply({
content: "You do not have the permission to use this command.",
});

return;
}

if (command.structure?.cooldown) {
const cooldownFunction = () => {
let data = cooldown.get(message.author.id);
if (command.structure?.developers) {
if (!config.users.developers.includes(message.author.id)) {
setTimeout(async () => {
await message.reply({
content: "You are not authorized to use this command.",
});
}, 5 * 1000);
}

data.push(commandInput);
return;
}

cooldown.set(message.author.id, data);
if (command.structure?.cooldown) {
const cooldownFunction = () => {
let data = cooldown.get(message.author.id);

setTimeout(() => {
let data = cooldown.get(message.author.id);
data.push(commandInput);

data = data.filter((v) => v !== commandInput);
cooldown.set(message.author.id, data);

if (data.length <= 0) {
cooldown.delete(message.author.id);
} else {
cooldown.set(message.author.id, data);
};
}, command.structure?.cooldown);
};
setTimeout(() => {
let data = cooldown.get(message.author.id);

if (cooldown.has(message.author.id)) {
let data = cooldown.get(message.author.id);
data = data.filter((v) => v !== commandInput);

if (data.some((v) => v === commandInput)) {
await message.reply({
content: 'Slow down buddy! You\'re too fast to use this command.'
});
if (data.length <= 0) {
cooldown.delete(message.author.id);
} else {
cooldown.set(message.author.id, data);
}
}, command.structure?.cooldown);
};

return;
} else {
cooldownFunction();
};
} else {
cooldown.set(message.author.id, [commandInput]);
if (cooldown.has(message.author.id)) {
let data = cooldown.get(message.author.id);

cooldownFunction();
};
};
if (data.some((v) => v === commandInput)) {
await message.reply({
content:
"Slow down buddy! You're too fast to use this command.",
});

command.run(client, message, args);
} catch (error) {
log(error, 'err');
return;
} else {
cooldownFunction();
}
} else {
cooldown.set(message.author.id, [commandInput]);

cooldownFunction();
}
}
},

command.run(client, message, args);
} catch (error) {
log(error, "err");
}
}
},
};
66 changes: 23 additions & 43 deletions src/functions/index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
const chalk = require('chalk');
const chalk = require("chalk");

/**
*
* @param {string} string
* @param {'info' | 'err' | 'warn' | 'done' | undefined} style
* Logs a message with optional styling.
*
* @param {string} string - The message to log.
* @param {'info' | 'err' | 'warn' | 'done' | undefined} style - The style of the log.
*/
const log = (string, style) => {
switch (style) {
case 'info': {
console.log(chalk.blue('[INFO] ' + string));

break;
};

case 'err': {
console.error(chalk.red('[ERROR] ' + string));

break;
};

case 'warn': {
console.warn(chalk.yellow('[WARNING] ' + string));

break;
};

case 'done': {
console.log(chalk.green('[SUCCESS] ' + string));

break;
};

default: {
console.log(string);

break;
};
};
const styles = {
info: { prefix: chalk.blue("[INFO]"), logFunction: console.log },
err: { prefix: chalk.red("[ERROR]"), logFunction: console.error },
warn: { prefix: chalk.yellow("[WARNING]"), logFunction: console.warn },
done: { prefix: chalk.green("[SUCCESS]"), logFunction: console.log },
};

const selectedStyle = styles[style] || { logFunction: console.log };
selectedStyle.logFunction(`${selectedStyle.prefix || ""} ${string}`);
};

/**
*
* @param {number} time
* @param {import('discord.js').TimestampStylesString} style
* @returns {`<t:${string}>`}
* Formats a timestamp.
*
* @param {number} time - The timestamp in milliseconds.
* @param {import('discord.js').TimestampStylesString} style - The timestamp style.
* @returns {string} - The formatted timestamp.
*/
const time = (time, style) => {
return `<t:${Math.floor(time / 1000)}${style ? `:${style}` : ''}>`;
return `<t:${Math.floor(time / 1000)}${style ? `:${style}` : ""}>`;
};

module.exports = {
log,
time
};
log,
time,
};

0 comments on commit 31cc270

Please sign in to comment.