Skip to content

Commit

Permalink
Merge pull request TFAGaming#48 from codeblitz97/main
Browse files Browse the repository at this point in the history
  • Loading branch information
TFAGaming authored Oct 4, 2023
2 parents 8c795d2 + 5be8bac commit 77bd916
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 249 deletions.
23 changes: 23 additions & 0 deletions src/commands/prefix/Nsfw/nsfw.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: "nsfw",
description: "Nsfw Command",
aliases: ["ns"],
permissions: "SendMessages",
cooldown: 5000,
nsfw: true,
},
/**
* @param {ExtendedClient} client
* @param {Message<true>} message
* @param {string[]} args
*/
run: async (client, message, args) => {
await message.reply({
content: "NSFW Command",
});
},
};
225 changes: 125 additions & 100 deletions src/events/Guild/interactionCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,109 +5,134 @@ const ExtendedClient = require("../../class/ExtendedClient");
const cooldown = new Map();

module.exports = {
event: "interactionCreate",
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
run: async (client, interaction) => {
if (!interaction.isCommand()) return;

if (
config.handler.commands.slash === false &&
interaction.isChatInputCommand()
)
return;
if (
config.handler.commands.user === false &&
interaction.isUserContextMenuCommand()
)
return;
event: "interactionCreate",
/**
*
* @param {ExtendedClient} client
* @param {import('discord.js').Interaction} interaction
* @returns
*/
run: async (client, interaction) => {
if (!interaction.isCommand()) return;

if (
config.handler.commands.slash === false &&
interaction.isChatInputCommand()
)
return;
if (
config.handler.commands.user === false &&
interaction.isUserContextMenuCommand()
)
return;
if (
config.handler.commands.message === false &&
interaction.isMessageContextMenuCommand()
)
return;

const command = client.collection.interactioncommands.get(
interaction.commandName
);

if (!command) return;

try {
if (command.options?.developers) {
if (
config.handler.commands.message === false &&
interaction.isMessageContextMenuCommand()
)
config.users?.developers?.length > 0 &&
!config.users?.developers?.includes(interaction.user.id)
) {
await interaction.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;
} else if (config.users?.developers?.length <= 0) {
await interaction.reply({
content:
config.messageSettings.missingDevIDsMessage !== undefined &&
config.messageSettings.missingDevIDsMessage !== null &&
config.messageSettings.missingDevIDsMessage !== ""
? config.messageSettings.missingDevIDsMessage
: "This is a developer only command, but unable to execute due to missing user IDs in configuration file.",

ephemeral: true,
});

return;
}
}

if (command.options?.nsfw && !interaction.channel.nsfw) {
await interaction.reply({
content:
config.messageSettings.nsfwMessage !== undefined &&
config.messageSettings.nsfwMessage !== null &&
config.messageSettings.nsfwMessage !== ""
? config.messageSettings.nsfwMessage
: "The current channel is not a NSFW channel",

ephemeral: true,
});

return;
}

if (command.options?.cooldown) {
const cooldownFunction = () => {
let data = cooldown.get(interaction.user.id);

data.push(interaction.commandName);

cooldown.set(interaction.user.id, data);

setTimeout(() => {
let data = cooldown.get(interaction.user.id);

data = data.filter((v) => v !== interaction.commandName);

if (data.length <= 0) {
cooldown.delete(interaction.user.id);
} else {
cooldown.set(interaction.user.id, data);
}
}, command.options?.cooldown);
};

if (cooldown.has(interaction.user.id)) {
let data = cooldown.get(interaction.user.id);

if (data.some((v) => v === interaction.commandName)) {
await interaction.reply({
content:
config.messageSettings.cooldownMessage !== undefined &&
config.messageSettings.cooldownMessage !== null &&
config.messageSettings.cooldownMessage !== ""
? config.messageSettings.cooldownMessage
: "Slow down buddy! You're too fast to use this command",
});

return;
} else {
cooldownFunction();
}
} else {
cooldown.set(interaction.user.id, [interaction.commandName]);

const command = client.collection.interactioncommands.get(
interaction.commandName
);

if (!command) return;

try {
if (command.options?.developers) {
if (config.users?.developers?.length > 0 && !config.users?.developers?.includes(interaction.user.id)) {
await interaction.reply({
content: `This is a developer only command.`,
ephemeral: true,
});

return;
} else if (config.users?.developers?.length <= 0) {
await interaction.reply({
content: `This is a developer only command, but unable to execute due to missing user IDs in configuration file.`,
ephemeral: true,
});

return;
};
};

if (command.options?.nsfw && !interaction.channel.nsfw) {
await interaction.reply({
content: "The current channel is not an NSFW channel.",
ephemeral: true,
});

return;
};

if (command.options?.cooldown) {
const cooldownFunction = () => {
let data = cooldown.get(interaction.user.id);

data.push(interaction.commandName);

cooldown.set(interaction.user.id, data);

setTimeout(() => {
let data = cooldown.get(interaction.user.id);

data = data.filter((v) => v !== interaction.commandName);

if (data.length <= 0) {
cooldown.delete(interaction.user.id);
} else {
cooldown.set(interaction.user.id, data);
};
}, command.options?.cooldown);
};

if (cooldown.has(interaction.user.id)) {
let data = cooldown.get(interaction.user.id);

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

return;
} else {
cooldownFunction();
};
} else {
cooldown.set(interaction.user.id, [interaction.commandName]);

cooldownFunction();
};
};

command.run(client, interaction);
} catch (error) {
log(error, "err");
cooldownFunction();
}
}

command.run(client, interaction);
} catch (error) {
log(error, "err");
}
},
};
Loading

0 comments on commit 77bd916

Please sign in to comment.