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

24
commands/info/botinfo.js Normal file
View file

@ -0,0 +1,24 @@
const Discord = require('discord.js');
const getCreationDate = require('../../util/getCreationDate');
const getGuildCount = require('../../util/getGuildCount');
module.exports = {
name: 'botinfo',
description: 'Shows information about the bot',
execute({message, client, prefix}) {
let guildCount = getGuildCount(client)
const embed = new Discord.MessageEmbed()
.setColor(15780145)
.setTitle("Information about bot")
.setTimestamp()
.setAuthor(client.user.username, client.user.avatarURL({ dynamic: true, size: 4096 }))
.addFields({
name: "General info", value: `Name: ${client.user.username}\nPrefix: ${prefix}\nTotal Servers: ${guildCount}\nCreation Date: ${getCreationDate(client)}\nSource: [Click Here](https://github.com/SileNce5k/discord_bot)`,
},)
message.channel.send(embed)
}
};

12
commands/info/guilds.js Normal file
View file

@ -0,0 +1,12 @@
module.exports = {
name: 'guilds',
description: 'Returns guild names',
admin: true,
execute({message, client}) {
let guildNames = "";
client.guilds.cache.each(guild => {
guildNames = guildNames + guild.name + "\n";
});
message.channel.send(guildNames)
}
};

71
commands/info/help.js Normal file
View file

@ -0,0 +1,71 @@
const fs = require('fs');
const Discord = require('discord.js');
const getCommandFiles = require('../../util/getCommandFiles');
module.exports = {
name: 'help',
description: 'List all available commands.',
moreHelp: ["Examples:","`<prefix>help` will return help with a small description for each command",
"`<prefix>help <another_command>` will return help with a more descriptive description",
"The descriptive description isn't available on all commands",
"`<prefix>help netmodules` to display help for netmodules"
],
execute({ message, args, prefix, client }) {
let commands = ""
let commandFiles = getCommandFiles('../../commands')
let x = 0
if (args[0] == "netmodules") {
commandFiles = fs.readdirSync('../../netload').filter(file => file.endsWith('.js'));
if (commandFiles.length == 0) {
message.channel.send("There are no netmodules currently loaded.")
x = 1;
}
}
if (x == 1) return;
const embed = new Discord.MessageEmbed()
.setColor(15780145)
.setTitle("Commands")
.setTimestamp()
.setAuthor(client.user.username, client.user.avatarURL({ dynamic: true, size: 4096 }))
let noHelp = 0;
for (const file of commandFiles) {
const command = require(`./${file}`);
if(command.disabled) continue;
if (args[0] == "admin") {
if (command.admin)
commands = commands + `${prefix}${command.name} | ${command.description}\n`
}else if(!args[0]){
if (!command.admin)
commands = commands + `${prefix}${command.name} | ${command.description}\n`
}else if(args[0] === command.name){
commands = commands + `${prefix}${command.name}\n`
embed.setTitle(command.name.charAt(0).toUpperCase() + command.name.slice(1))
if(command.moreHelp){
command.moreHelp.forEach(element => {
commands = commands + `${element}\n`
});
} else {
noHelp = 1;
}
break;
}
}
let regex = /<prefix>/g
if(commands === ""){
noHelp = 1;
}
commands = commands.replace(regex, prefix)
embed.addFields(
{ name: "General", value: commands },
)
if(noHelp == 0)
message.channel.send(embed);
else
message.channel.send("Either there is no command with that name, or there is no specific help for it.")
},
};

19
commands/info/pfp.js Normal file
View file

@ -0,0 +1,19 @@
const parseMention = require("../../util/parseMention.js")
module.exports = {
name: 'pfp',
description: 'Returns profile picture',
moreHelp: ["Returns your profile picture if no arguments are provided",
"Argument can be username, nickname, userid, and mention"],
execute({message, args}) {
let info;
if (!args[0]) {
info = message.author.id;
} else {
info = parseMention(args[0], message.guild);
}
let user = message.guild.members.cache.get(info);
message.channel.send(user.user.avatarURL({ format: 'png', dynamic: true, size: 4096 }))
}
};

View file

@ -0,0 +1,23 @@
const Discord = require('discord.js')
module.exports = {
name: 'serverinfo',
description: 'Displays information about the server',
execute({message}) {
console.log(message.guild.emojis.cache)
const embed = new Discord.MessageEmbed()
.setThumbnail(message.guild.iconURL({ format: 'png', dynamic: true, size: 4096 }))
.setColor("#ee7939")
.setTimestamp()
.addField("Server Owner: ", `<@${message.guild.ownerID}>`)
.addField("Server Name: ", message.guild.name)
.addField("Created", message.guild.createdAt.toUTCString())
.addField("Members: ", message.guild.memberCount)
//.addField("Emojis: ", message.guild.emojis.cache.array().length)
message.channel.send(embed);
}
};

31
commands/info/uptime.js Normal file
View file

@ -0,0 +1,31 @@
const parseMS = require('parse-ms')
module.exports = {
name: 'uptime',
description: 'Returns uptime',
execute({message, client}) {
let days = "";
let hours = "";
let minutes = "";
let seconds = "";
let milliseconds = "";
let uptime = parseMS(client.uptime)
if (uptime.days != 0)
days = `${uptime.days} days, `
if (uptime.hours != 0)
hours = `${uptime.hours} hours, `
if (uptime.minutes != 0)
minutes = `${uptime.minutes} minutes, `
if (uptime.seconds != 0)
seconds = `${uptime.seconds} seconds `
if (uptime.milliseconds != 0)
milliseconds = `and ${uptime.milliseconds} milliseconds`
let fullUptime = `This bot has an uptime of ${days}${hours}${minutes}${seconds}${milliseconds}`
message.channel.send(fullUptime)
}
};

62
commands/info/userinfo.js Normal file
View file

@ -0,0 +1,62 @@
const Discord = require('discord.js');
const getCreationDate = require('../../util/getCreationDate.js');
const getJoinDate = require('../../util/getJoinDate.js');
const getNickname = require('../../util/getNickname.js');
const morePresence = require('../../util/morePresence.js');
const parseMention = require("../../util/parseMention.js")
module.exports = {
name: 'userinfo',
description: 'Displays information about the user',
moreHelp: ["Example: <prefix>userinfo <some_username>","It works with username, nickname, userid, and mention"],
execute({message, args}) {
let info;
if (!args[0]) {
info = message.author.id;
} else {
info = parseMention(args[0], message.guild);
}
let user = message.guild.members.cache.get(info);
let nickname = ""
let _nick = getNickname(user, message.guild)
if (_nick != null) {
nickname = ` <:aka:572089580925485058>${nickname}`;
}
let roleColor = 15788778;
if (user.roles.color) {
roleColor = user.roles.color.color;
}
let presenceDetails = 0;
let isPresence = false;
if(user.user.presence.activities.length != 0){
presenceDetails = morePresence(user);
isPresence = true;
}
let roles = "";
user.roles.cache.each(role => {
if (role.name != "@everyone")
roles = roles+"<@&"+role.id+">\n";
});
const embed = new Discord.MessageEmbed()
.setThumbnail(user.user.avatarURL({ format: 'png', dynamic: true, size: 2048 }))
.setColor(roleColor)
.setTimestamp()
.setAuthor(user.user.username, user.user.avatarURL({ format: 'png', dynamic: true, size: 2048 }))
.addField("Username", `**${user.user.username}#${user.user.discriminator}**${nickname}`)
.addField("Status", user.user.presence.status.charAt(0).toUpperCase()+user.user.presence.status.slice(1), true)
if(isPresence)
embed.addField("Presence", user.user.presence.activities[0].name, true)
if(presenceDetails != 0)
embed.addField("Details", presenceDetails, false)
embed.addField("Creation date", getCreationDate(user), true)
embed.addField("Join date", getJoinDate(user, message.guild), true)
if(roles != ""){
embed.addField("Roles", roles)
}
message.channel.send(embed);
}
};