-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from codeblitz97/main
Add NSFW Only command and developers command in message
- Loading branch information
Showing
6 changed files
with
183 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!" }); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |