Split commands into subdirectories

* Move command files into directories

* Edit relative paths

* Update gitignore

* Finish support for commands in subdir

* Split up getCommandFiles into own function

* Add support for subdirs on help command
This commit is contained in:
SileNce5k 2021-07-18 11:24:46 +02:00 committed by GitHub
parent 8993eeaf7a
commit e7cdd425d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 55 additions and 35 deletions

89
commands/misc/custom.js Normal file
View file

@ -0,0 +1,89 @@
const addCustomCommand = require("../../util/addCustomCommand");
const deleteCustomCommand = require("../../util/deleteCustomCommand");
const getAllCustomCommands = require("../../util/getAllCustomCommands");
const getOwnerOfCustomCommand = require("../../util/getOwnerOfCustomCommand");
const Discord = require('discord.js');
const fs = require('fs');
const editCustomCommand = require("../../util/editCustomCommand");
module.exports = {
name: 'custom',
description: "Manage custom commands, see <prefix>help custom for more",
moreHelp: ["<prefix>custom add - Add new custom commands",
"<prefix>custom edit - Edit an existing command that you own",
"<prefix>custom show - Show custom message unformatted.",
"<prefix>custom remove - Delete your custom commands.",
"<prefix>custom owner - check owner of custom command",
"<prefix>custom list - list all custom commands",
"<prefix>custom variables - list all variables you can use"
],
execute({message, args, client, prefix, owners}) {
const customPath = '../../data/customCommands.json';
if(!fs.existsSync(customPath)){
fs.writeFileSync(customPath,"[]")
}
let sendText;
if (args){
let customName = args[1];
let customMessage = args.slice(2, args.length).join(" ");
switch (args[0].toLowerCase()) {
case "add":
if(!customMessage) {
message.channel.send("Message can't be empty");
return;
}
sendText = addCustomCommand(customName, customMessage, message.author.id);
break;
case "remove":
case "delete":
sendText = deleteCustomCommand(customName, message.author.id, owners);
break;
case "owner":
let author = getOwnerOfCustomCommand(customName);
let user;
if(!author)
sendText = `${customName} does not exist`
else{
client.guilds.cache.each(guild => {
user = guild.members.cache.get(author);
});
sendText = `The owner of ${customName} is ${user.user.username} (id: ${user.user.id}).`
}
break;
case "list":
const embed = new Discord.MessageEmbed();
sendText = getAllCustomCommands();
if(sendText != ""){
embed.setColor(15780145)
embed.addFields(
{ name: "Custom commands", value: sendText },
)
sendText = embed
}else sendText = "NO CUSTOM COMMANDS"
break;
case "variables":
sendText = "The variables you can use are:\n<prefix>\n<globalPrefix>\n<username>\n<nickname>\n<user_id>\n<discriminator>\n<guild_name>\n<guild_id>"
break;
case "edit":
sendText = editCustomCommand(customName, message.author.id, customMessage)
break;
case "show":
let json = fs.readFileSync(customPath, 'utf8');
let customCommands = JSON.parse(json)
sendText = "Command not found."
customCommands.forEach(function (customCommand) {
if (customCommand.customName === customName) {
sendText = `\`\`\`\n${customCommand.customMessage}\n\`\`\``
}
});
break;
default:
sendText = `Argument not recognized.\n"${prefix}help custom" to see all arguments you can use.`
break;
}
}
message.channel.send(sendText);
}
};

27
commands/misc/emoji.js Normal file
View file

@ -0,0 +1,27 @@
module.exports = {
name: 'e',
description: 'Returns emoji url',
moreHelp: ["Works with both animated and static emojis"],
execute({ message, args }) {
let emoji = args.join(` `);
if (!emoji) {
message.channel.send("no emoji");
return;
}
let extension = ".png"
if (args[0].charAt(1) == "a") {
extension = ".gif";
}
let num = emoji.split(":")[2];
try {
num = num.slice(0, -1);
} catch (e) {
message.channel.send("There was an error.");
return;
}
message.channel.send("https://cdn.discordapp.com/emojis/" + num + extension);
}
};

74
commands/misc/netload.js Normal file
View file

@ -0,0 +1,74 @@
const https = require('https');
const fs = require('fs')
const netloadDir = "../../netload"
const validUrl = require('valid-url');
module.exports = {
name: 'netload',
description: 'Load a module from the internet',
moreHelp: ["Examples:",
"Either provide a link to the module, or upload it",
"To get an example of how your module should look like, do:",
"<prefix>netload example",
"You have to be whitelisted to use this command.",
"The bot operator also has to have this enabled in the config."
],
execute({ message, args, prefix, client, owners }) {
let json = fs.readFileSync('../../data/netmoduleWhitelist.json', 'utf8');
let whitelist = JSON.parse(json)
if (json.indexOf(message.author.id.toString()) == -1) {
message.channel.send("You do not have permissions to use this command.");
return;
}
if (args[0] == "whitelist" && owners.indexOf(message.author.id.toString()) >= 0) {
whitelist.push(args[1])
fs.writeFileSync("./data/netmoduleWhitelist.json", JSON.stringify(whitelist, null, 4))
return;
}
if (!args[0] && message.attachments.size == 0) {
message.channel.send(`You have to either specify a url or upload a file via the command.\nTo get an example file, execute \`${prefix}netload example\``)
return;
} if (args[0] == "example") {
let example = fs.readFileSync("../.example")
message.channel.send(`\`\`\`js\n${example}\n\`\`\``)
return;
}
let url, fileName;
if (message.attachments.size > 0) {
url = message.attachments.first().url
fileName = message.attachments.first().name
} else {
url = args[0]
if (!validUrl.isUri(url)) {
message.channel.send("This does not look like a valid url")
return;
}
fileName = args[0].split("/")[args[0].split("/").length - 1]
}
if (fs.existsSync(`${netloadDir}/${fileName}`)) {
message.channel.send(`A module with this filename(${fileName}) already exists.`)
return;
}
https.get(url, (res) => {
res.on('data', (d) => {
fs.writeFileSync(`${netloadDir}/${fileName}`, d);
reloadNetModules(client);
});
}).on('error', (e) => {
message.channel.send("Error download file.");
console.log(e)
});
let reloadNetModules = require('../util/reloadNetModules');
reloadNetModules(client)
}
};

9
commands/misc/owo.js Normal file
View file

@ -0,0 +1,9 @@
const owo = require('@zuzak/owo')
module.exports = {
name: 'owo',
description: 'Translate to furry/weeb language',
execute({message, args}) {
let msg = args.join(" ")
message.channel.send(owo.translate(msg));
}
};

View file

@ -0,0 +1,29 @@
let seedrandom = require('seedrandom');
const parseMention = require('../../util/parseMention')
module.exports = {
name: 'penissize',
description: 'Get penis size',
execute({message, args}) {
let info;
let isSelf = true;
if (!args[0]) {
info = message.author.id;
} else {
info = parseMention(args[0], message.guild);
isSelf = false
}
let rng = seedrandom(info.toString())
let max = 45;
let min = 1;
let rnd = rng() * (max - min + 1) + min;
let penisSize = rnd.toFixed(2)
let penisSizeInches = (penisSize * 0.3937008).toFixed(2);
let name = "Your";
if(!isSelf){
let user = message.guild.members.cache.get(info);
name = user.user.username+"'s"
}
message.channel.send(`${name} penis size is ${penisSize} cm, or ${penisSizeInches} inches`);
}
};

7
commands/misc/ping.js Normal file
View file

@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
description: 'Just ping.',
execute({message, client}) {
message.channel.send(`Pong.\n${client.ws.ping}ms`)
}
};

20
commands/misc/prefix.js Normal file
View file

@ -0,0 +1,20 @@
const parseMention = require("../../util/parseMention");
const setServerPrefix = require("../../util/setServerPrefix");
module.exports = {
name: 'prefix',
description: 'Change the prefix of the bot in this server.',
execute({ message, client, args, prefix }) {
if (!message.member.hasPermission('MANAGE_GUILD')) {
message.channel.send("You do not have sufficient permissions(MANAGE_GUILD) to change the prefix of this server.")
return;
}
if (!args[0]) {
message.channel.send(`To change the prefix, execute \`${prefix}prefix <newPrefix>\``);
return;
}else{
setServerPrefix(client, args[0], message.guild.id)
message.channel.send(`The prefix for this server is now set to ${args[0]}`)
}
}
};

16
commands/misc/random.js Normal file
View file

@ -0,0 +1,16 @@
const randomNumber = require('../../util/randomNumber')
module.exports = {
name: 'random',
description: 'Returns a value between two numbers (default = 1-10)',
execute({ message, args }) {
let min = 1
let max = 10
if (args[0] && args[1]) {
min = parseInt(args[0])
max = parseInt(args[1])
}
let randNumber= randomNumber(min,max)
message.channel.send(randNumber)
}
};

14
commands/misc/say.js Normal file
View file

@ -0,0 +1,14 @@
module.exports = {
name: 'say',
description: 'Repeats arguments',
execute({message, args}) {
if(args.length == 0)
message.channel.send("Can't send empty message");
else{
message.channel.send(args.join(" "))
message.delete()
}
}
};