VylBot App 21.0.0

This commit is contained in:
Vylpes 2021-02-17 18:12:45 +00:00
parent 88dca40dd6
commit 3ddad6972a
27 changed files with 2667 additions and 307 deletions

45
commands/about.js Normal file
View file

@ -0,0 +1,45 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class about extends command {
constructor() {
// Set execute method, description, and category
super("about");
super.description = "About the bot";
super.category = "General";
// Set required configs in the config.about json string.
// description: The bot description
// version: The bot version
// author: Bot author
// date: Date of build
super.requiredConfigs = "description";
super.requiredConfigs = "version";
super.requiredConfigs = "core-ver";
super.requiredConfigs = "author";
super.requiredConfigs = "date";
}
// The execution method
about(context) {
// Create an embed containing data about the bot
const embed = new MessageEmbed()
.setTitle("About")
.setColor(embedColor)
.setDescription(context.client.config.about.description)
.addField("Version", context.client.config.about.version, true)
.addField("VylBot Core", context.client.config.about['core-ver'], true)
.addField("Author", context.client.config.about.author)
.addField("Date", context.client.config.about.date);
// Send embed to the channel the command was sent in
context.message.channel.send(embed);
}
}
// Set the about class to be exported
module.exports = about;

93
commands/ban.js Normal file
View file

@ -0,0 +1,93 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class ban extends command {
constructor() {
// Set execution method, description, category, and usage
super("ban");
super.description = "Bans the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set required configs in the config.ban json string
super.requiredConfigs = "modrole";
super.requiredCofigs = "logchannel";
}
// Command execution method
ban(context) {
// If the user has the modrole (set in config.ban.modrole)
if (context.message.guild.roles.cache.find(role => role.name == context.client.config.ban.modrole)) {
// Gets the user pinged in the command
const user = context.message.mentions.users.first();
// If the user pinged is a valid user
if (user) {
// Get the guild member object from the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if they are in the server
if (member) {
// Get the arguments and remove what isn't the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the guild is available to work with
if (context.message.guild.available) {
// If the bot client is able to ban the member
if (member.bannable) {
// The Message Embed which goes into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Banned")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The Message Embed which goes into the public channel the message was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been banned`);
// Ban the member and send the embeds into the appropriate channel, then delete the initial message
member.ban({ reason: reason }).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.ban.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => { // If the bot couldn't ban the member, say so and log the error to the console
errorEmbed(context, "An error occurred");
console.log(err);
});
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "User is not in this server");
}
} else { // If the user object doesn't exist
errorEmbed(context, "User does not exist");
}
} else { // If the user doesn't have the mod role
errorEmbed(context, `You require the \`${context.client.config.ban.modrole}\` role to run this command`);
}
}
}
// Post an error embed
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = ban;

View file

@ -1,7 +1,7 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const randomPuppy = require('random-puppy');
const randomBunny = require('random-bunny');
// Command variables
const embedColor = "0x3050ba";
@ -18,11 +18,13 @@ class bunny extends command {
// Run method
bunny(context) {
// Get a random post from r/Rabbits
randomPuppy('Rabbits').then(image => {
randomBunny('rabbits', 'hot', (image, title) => {
// Create an embed containing the random image
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setImage(image);
.setTitle(title)
.setImage(image)
.setFooter('r/Rabbits');
// Send the embed
context.message.channel.send(embed);

58
commands/clear.js Normal file
View file

@ -0,0 +1,58 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class clear extends command {
constructor() {
// Set execute method, description, category, and usage
super("clear");
super.description = "Bulk deletes the chat for up to 100 messages";
super.category = "Moderation";
super.usage = "<amount>";
// Set required configs in the config.clear json string
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// Execute method
clear(context) {
// If the user has the config.clear.modrole role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.clear.modrole)) {
// If the command specifies a number between 1 and 100
if (context.arguments.length > 0 && context.arguments[0] > 0 && context.arguments[0] < 101) {
// Attempt to bulk delete the amount of messages specified as an argument
context.message.channel.bulkDelete(context.arguments[0]).then(() => {
// Public embed
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${context.arguments[0]} messages were removed`);
// Send the embed into the channel the command was sent in
context.message.channel.send(embed);
}).catch(err => { // If the bot couldn't bulk delete
errorEmbed(context, "An error has occurred");
console.log(err);
});
} else { // If the user didn't give a number valid (between 1 and 100)
errorEmbed(context, "Please specify an amount between 1 and 100");
}
} else { // If the user doesn't have the mod role
errorEmbed(context, `This command requires the \`${context.client.config.clear.modrole}\` role to run`);
}
}
}
// Function to send an error embed
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = clear;

25
commands/eval.js Normal file
View file

@ -0,0 +1,25 @@
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
class evaluate extends command {
constructor() {
super("evaluate");
super.description = "Evaluates an expression";
super.category = "Administration";
super.requiredConfigs = "ownerid";
}
evaluate(context) {
if (context.message.author.id == context.client.config.eval.ownerid) {
const result = eval(context.arguments.join(" "));
const embed = new MessageEmbed()
.setDescription(result)
.setColor(0x3050ba);
context.message.channel.send(embed);
}
}
}
module.exports = evaluate;

150
commands/help.js Normal file
View file

@ -0,0 +1,150 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { readdirSync } = require('fs');
const embedColor = "0x3050ba";
// Command Class
class help extends command {
constructor() {
// Set the execute method, description, category, and example usage
super("help");
super.description = "Gives a list of commands available in the bot";
super.category = "General";
super.usage = "[command]";
}
// Execute method
help(context) {
// Get the list of command folders the bot has been setup to check
const commandFolders = context.client.config.commands;
// Empty arrays for commands
// allCommands: Will contain objects of all commands with their related info
// categories: Will contain strings of all the categories the commands are set to, unique
const allCommands = [];
const categories = [];
// Loop through all the command folders set
// i = folder index
for (let i = 0; i < commandFolders.length; i++) {
// The current folder the bot is looking through
const folder = commandFolders[i];
// Read the directory of the current folder
const contents = readdirSync(`${process.cwd()}/${folder}`);
// Loop through the contents of the folder
// j = file index in folder i
for (let j = 0; j < contents.length; j++) {
// Get command in the current folder to read
const file = require(`${process.cwd()}/${folder}/${contents[j]}`);
// Initialise the command
const obj = new file();
// Data object containing the command information
const data = {
"name": contents[j].replace(".js", ""),
"description": obj.description,
"category": obj.category,
"usage": obj.usage,
"roles": obj.roles
};
// Push the command data to the allCommands Array
allCommands.push(data);
}
}
// Loop through all the commands discovered by the previous loop
for (let i = 0; i < allCommands.length; i++) {
// Get the current command category name, otherwise "none"
const category = allCommands[i].category || "none";
// If the command isn't already set, set it.
// This will then make the categories array be an array of all categories which have been used but only one of each.
if (!categories.includes(category)) categories.push(category);
}
// If an command name has been passed as an argument
// If so, send information about that command
// If not, send the help embed of all commands
if (context.arguments[0]) {
sendCommand(context, allCommands, context.arguments[0]);
} else {
sendAll(context, categories, allCommands);
}
}
}
// Send embed of all commands
// context: The command context json string
// categories: The array of categories found
// allCommands: The array of the commands found
function sendAll(context, categories, allCommands) {
// Embed to be sent
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle("Commands");
// Loop through each command
for (let i = 0; i < categories.length; i++) {
// The category name of the current one to check
const category = categories[i];
// Empty Array for the next loop to filter out the current category
const commandsFilter = [];
// Loop through allCommands
// If the command is set to the current category being checked, add it to the filter array
for (let j = 0; j < allCommands.length; j++) {
if (allCommands[j].category == category) commandsFilter.push(`\`${allCommands[j].name}\``);
}
// Add a field to the embed which contains the category name and all the commands in that category
embed.addField(category, commandsFilter.join(", "));
}
// Send the embed
context.message.channel.send(embed);
}
// Send information about a specific command
// context: The command context json string
// allCommands: The array of categories found
// name: The command name to check
function sendCommand(context, allCommands, name) {
let command = {};
// Loop through all commands, if the command name is the same as the one we're looking for, select it
for (let i = 0; i < allCommands.length; i++) {
if (allCommands[i].name == name) command = allCommands[i];
}
// If a matching command has been found
if (command.name) {
// Create an embed containing the related information of the command
// The title is the command name but sets the first letter to be capitalised
// If a set of information isn't set, set it to say "none"
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle(command.name[0].toUpperCase() + command.name.substring(1))
.setDescription(command.description || "*none*")
.addField("Category", command.category || "*none*", true)
.addField("Usage", command.usage || "*none*", true)
.addField("Required Roles", command.roles.join(", ") || "*none*");
// Send the embed
context.message.channel.send(embed);
} else { // If no command has been found, then send an embed which says this
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription("Command does not exist");
context.message.channel.send(embed);
}
}
module.exports = help;

93
commands/kick.js Normal file
View file

@ -0,0 +1,93 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class kick extends command {
constructor() {
// Sets the command's run method, description, category, and usage
super("kick");
super.description = "Kicks the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Sets the required configs for the command
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// The command's run method
kick(context) {
// Checks if the user has the mod role, set in the config json string
if (context.message.member.roles.cache.find(role => role.name == context.client.config.kick.modrole)) {
// Gets the first user pinged in the command
const user = context.message.mentions.users.first();
// If a user was pinged
if (user) {
// Gets the guild member object of the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e if the user is in the server
if (member) {
// Gets the part of the argument array which holds the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Joins the reason into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can kick the mentioned member
if (member.kickable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Kicked")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been kicked`);
// Attemtp to kick the user, if successful send the embeds, if unsuccessful notify the chat and log the error
member.kick({ reason: reason }).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.kick.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error has occurred");
console.log(err);
});
} else { // If the user isn't kickable
errorEmbed(context, "I am unable to kick this user");
}
}
} else { // If the member object is invalid
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object is invalid
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Function to post an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = kick;

98
commands/mute.js Normal file
View file

@ -0,0 +1,98 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class mute extends command {
constructor() {
// Set the command's run method, description, category, and usage
super("mute");
super.description = "Mutes the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set the required configs for the command
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
super.requiredConfigs = "muterole";
}
// The command's run method
mute(context) {
// Check if the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object of the mentioned user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if the user is in the server
if (member) {
// Get the part of the arguments array which contains the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the reason into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can manage the user's roles
if (member.manageable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setTitle("Member Muted")
.setColor(embedColor)
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been muted`)
.addField("Reason", reason || "*none*");
// Get the 'Muted' role
const mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.mute.muterole);
// Attempt to mute the user, if successful send the embeds, if not log the error
member.roles.add(mutedRole, reason).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.mute.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error occurred");
console.log(err);
});
} else { // If the bot can't manage the user
errorEmbed(context, "I am unable to mute this user");
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Send an embed when an error occurs
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = mute;

60
commands/partner.js Normal file
View file

@ -0,0 +1,60 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { existsSync, readFileSync } = require('fs');
// Command Variables
const embedColor = "0x3050ba";
// Command class
class partner extends command {
constructor() {
// Set the command's run method, description, and category
super("partner");
super.description = "Generates the embeds for the partner from the partners.json file";
super.category = "Admin";
// Require in the config the name of the admin role and the rules file name
super.requiredConfigs = "adminrole";
super.requiredConfigs = "partnersfile";
}
// Run method
partner(context) {
if (context.message.member.roles.cache.find(role => role.name == context.client.config.partner.adminrole)) {
if (existsSync(context.client.config.partner.partnersfile)) {
const partnerJson = JSON.parse(readFileSync(context.client.config.partner.partnersfile));
for (const i in partnerJson) {
const serverName = partnerJson[i].name;
const serverInvite = partnerJson[i].invite;
const serverDescription = partnerJson[i].description;
const serverIcon = partnerJson[i].icon;
const embed = new MessageEmbed()
.setColor(embedColor)
.setTitle(serverName)
.setDescription(serverDescription)
.setURL(serverInvite)
.setThumbnail(serverIcon);
context.message.channel.send(embed);
}
} else {
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription('File does not exist');
context.message.channel.send(errorEmbed);
}
} else {
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription('You do not have permission to run this command');
context.message.channel.send(errorEmbed);
}
}
}
module.exports = partner;

View file

@ -1,6 +1,7 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const emojiRegex = require('emoji-regex/RGI_Emoji');
// Command variables
const embedColor = "0x3050ba";
@ -20,40 +21,53 @@ class poll extends command {
// Get the command's arguments, and split them by a semicolon rather than a space
// This allows the variables to be able to use spaces in them
let args = context.arguments;
let argsJoined = args.join(' ');
const argsJoined = args.join(' ');
args = argsJoined.split(';');
// If the argument has 3 or more arguments and less than 11 arguments
// This allows the title and 2-9 options
if (args.length >= 3 && args.length < 11) {
// Set the title to the first argument
let title = args[0];
const title = args[0];
let optionString = "";
// Array used to get the numbers as their words
// arrayOfNumbers[n] = "n written in full words"
let arrayOfNumbers = [
'zero',
'one',
'two',
'three',
'four',
'five',
'six',
'seven',
'eight',
'nine'
const arrayOfNumbers = [
':zero:',
':one:',
':two:',
':three:',
':four:',
':five:',
':six:',
':seven:',
':eight:',
':nine:'
];
// Array containing the numbers as their emoji
const reactionEmojis = ["0⃣", "1⃣", "2⃣", "3⃣", "4⃣", "5⃣", "6⃣", "7⃣", "8⃣", "9⃣"];
// Loop through all the arguments after the title
// Add them to the optionString, with their index turned into a number emoji
// Example: :one: Option 1
for (let i = 1; i < args.length; i++) {
optionString += `:${arrayOfNumbers[i]}: ${args[i]}\n`;
// If the option contains an emoji, replace the emoji with it
const regex = emojiRegex();
const match = regex.exec(args[i]);
if (match) {
const emoji = match[0];
reactionEmojis[i] = emoji;
arrayOfNumbers[i] = '';
}
optionString += `${arrayOfNumbers[i]} ${args[i]}\n`;
}
// Create the embed with the title at the top of the description with the options below
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`**${title}**\n\n${optionString}`);
@ -61,71 +75,71 @@ class poll extends command {
// the bot will determine how many to react with for the amount of options inputted
context.message.channel.send(embed).then(message => {
if (args.length == 2) {
message.react("1⃣");
message.react(reactionEmojis[1]);
} else if (args.length == 3) {
message.react("1⃣")
.then(() => message.react("2⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]));
} else if (args.length == 4) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]));
} else if (args.length == 5) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]));
} else if (args.length == 6) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"))
.then(() => message.react("5⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]));
} else if (args.length == 7) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"))
.then(() => message.react("5⃣"))
.then(() => message.react("6⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]));
} else if (args.length == 8) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"))
.then(() => message.react("5⃣"))
.then(() => message.react("6⃣"))
.then(() => message.react("7⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]));
} else if (args.length == 9) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"))
.then(() => message.react("5⃣"))
.then(() => message.react("6⃣"))
.then(() => message.react("7⃣"))
.then(() => message.react("8⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]))
.then(() => message.react(reactionEmojis[8]));
} else if (args.length == 10) {
message.react("1⃣")
.then(() => message.react("2⃣"))
.then(() => message.react("3⃣"))
.then(() => message.react("4⃣"))
.then(() => message.react("5⃣"))
.then(() => message.react("6⃣"))
.then(() => message.react("7⃣"))
.then(() => message.react("8⃣"))
.then(() => message.react("9⃣"));
message.react(reactionEmojis[1])
.then(() => message.react(reactionEmojis[2]))
.then(() => message.react(reactionEmojis[3]))
.then(() => message.react(reactionEmojis[4]))
.then(() => message.react(reactionEmojis[5]))
.then(() => message.react(reactionEmojis[6]))
.then(() => message.react(reactionEmojis[7]))
.then(() => message.react(reactionEmojis[8]))
.then(() => message.react(reactionEmojis[9]));
}
}).catch(console.error);
// Delete the message
context.message.delete();
} else if (args.length >= 11) { // If the user inputted more than 9 options
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setDescription("The poll command can only accept up to 9 options");
context.message.channel.send(errorEmbed);
} else { // If the user didn't give enough data
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setDescription("Please use the correct usage: <title>;<option 1>;<option 2>... (separate options with semicolons)");
context.message.channel.send(errorEmbed);

View file

@ -21,7 +21,7 @@ class role extends command {
// Run method
role(context) {
// Get the array containing the assignable roles
let roles = context.client.config.role.assignable;
const roles = context.client.config.role.assignable;
let requestedRole = "";
// If the arguments specifys a specific role
@ -37,13 +37,13 @@ class role extends command {
// If a matching assignable role was found
if (requestedRole != "") {
// Get the role object from the server with the role name
let role = context.message.guild.roles.cache.find(r => r.name == requestedRole);
const role = context.message.guild.roles.cache.find(r => r.name == requestedRole);
// If the user already has the role, remove the role from them and send an embed
// Otherwise, add the role and send an embed
if (context.message.member.roles.cache.find(r => r.name == requestedRole)) {
context.message.member.roles.remove(role).then(() => {
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`Removed role: ${requestedRole}`);
@ -51,7 +51,7 @@ class role extends command {
}).catch(err => {
console.error(err);
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("An error occured. Please check logs");
@ -59,7 +59,7 @@ class role extends command {
});
} else { // If the user doesn't have the role
context.message.member.roles.add(role).then(() => {
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`Gave role: ${requestedRole}`);
@ -67,7 +67,7 @@ class role extends command {
}).catch(err => {
console.error(err);
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("An error occured. Please check logs");
@ -75,7 +75,7 @@ class role extends command {
});
}
} else { // If the role can't be found, send an error embed
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription("This role does not exist, see assignable roles with the role command (no arguments)");
@ -91,7 +91,7 @@ class role extends command {
}
// Create an embed containing the text
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setTitle("Roles")
.setColor(embedColor)
.setDescription(rolesString);

View file

@ -1,4 +1,4 @@
// Required components
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const { existsSync, readFileSync } = require('fs');
@ -12,7 +12,7 @@ class rules extends command {
// Set the command's run method, description, and category
super("rules");
super.description = "Generates the rules embeds from the rules.txt file";
super.category = "Administration";
super.category = "Admin";
// Require in the config the name of the admin role and the rules file name
super.requiredConfigs = "adminrole";
@ -34,19 +34,19 @@ class rules extends command {
for (let i = 0; i < rulesText.length; i++) {
// If the first line after "> " has a "#", create and embed with an image of the url specified after
if (rulesText[i].charAt(0) == '#') {
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setColor(embedColor)
.setImage(rulesText[i].substring(1));
context.message.channel.send(embed);
} else { // If the file doesn't have a "#" at the start
// Split the embed into different lines, set the first line as the title, and the rest as the description
let rulesLines = rulesText[i].split("\n");
let rulesTitle = rulesLines[0];
let rulesDescription = rulesLines.slice(1).join("\n");
const rulesLines = rulesText[i].split("\n");
const rulesTitle = rulesLines[0];
const rulesDescription = rulesLines.slice(1).join("\n");
// Create the embed with the specified information above
let embed = new MessageEmbed()
const embed = new MessageEmbed()
.setTitle(rulesTitle)
.setColor(embedColor)
.setDescription(rulesDescription);
@ -56,14 +56,14 @@ class rules extends command {
}
}
} else { // If the rules file doesn't exist
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${context.client.config.rules.rulesfile} doesn't exist`);
context.message.channel.send(errorEmbed);
}
} else { // If the user doesn't have the Admin role
let errorEmbed = new MessageEmbed()
const errorEmbed = new MessageEmbed()
.setColor(embedColor)
.setDescription("You do not have permission to run this command");

98
commands/unmute.js Normal file
View file

@ -0,0 +1,98 @@
// Required components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class unmute extends command {
constructor() {
// Set run method, description, category, usage
super("unmute");
super.description = "Unmutes the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set required configs
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
super.requiredConfigs = "muterole";
}
// The command's run method
unmute(context) {
// Check if the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.mute.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object from the pinged user
const member = context.message.guild.member(user);
// If the member object exists, i.e. if the user is in the server
if (member) {
// Get the part of the argument array which contains the reason
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// If the bot client can manage the user
if (member.manageable) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setColor(embedColor)
.setTitle("Member Unmuted")
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been unmuted`)
.addField("Reason", reason || "*none*");
// Get the muted role
const mutedRole = context.message.guild.roles.cache.find(role => role.name == context.client.config.unmute.muterole);
// Attempt to remove the role from the user, and then send the embeds. If unsuccessful log the error
member.roles.remove(mutedRole, reason).then(() => {
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.unmute.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}).catch(err => {
errorEmbed(context, "An error occurred");
console.log(err);
});
} else { // If the bot can't manage the user
errorEmbed(context, "I am unable to unmute this user");
}
}
} else { // If the member object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
}
}
}
// Send an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = unmute;

86
commands/warn.js Normal file
View file

@ -0,0 +1,86 @@
// Required Components
const { command } = require('vylbot-core');
const { MessageEmbed } = require('discord.js');
const embedColor = "0x3050ba";
// Command Class
class warn extends command {
constructor() {
// Set the run method, description, category, and usage
super("warn");
super.description = "Warns the mentioned user with an optional reason";
super.category = "Moderation";
super.usage = "<@user> [reason]";
// Set the required configs
super.requiredConfigs = "modrole";
super.requiredConfigs = "logchannel";
}
// The command's run method
warn(context) {
// If the user has the mod role
if (context.message.member.roles.cache.find(role => role.name == context.client.config.warn.modrole)) {
// Get the user first pinged in the message
const user = context.message.mentions.users.first();
// If the user object exists
if (user) {
// Get the guild member object from the user
const member = context.message.guild.member(user);
// If the member object exists. i.e. if the user is in the server
if (member) {
// Get the part of the argument array which the reason is in
const reasonArgs = context.arguments;
reasonArgs.splice(0, 1);
// Join the array into a string
const reason = reasonArgs.join(" ");
// If the server is available
if (context.message.guild.available) {
// The embed to go into the bot log
const embedLog = new MessageEmbed()
.setColor(embedColor)
.setTitle("Member Warned")
.addField("User", `${user} \`${user.tag}\``, true)
.addField("Moderator", `${context.message.author} \`${context.message.author.tag}\``, true)
.addField("Reason", reason || "*none*")
.setThumbnail(user.displayAvatarURL);
// The embed to go into the channel the command was sent in
const embedPublic = new MessageEmbed()
.setColor(embedColor)
.setDescription(`${user} has been warned`)
.addField("Reason", reason || "*none*");
// Send the embeds
context.message.guild.channels.cache.find(channel => channel.name == context.client.config.warn.logchannel).send(embedLog);
context.message.channel.send(embedPublic);
context.message.delete();
}
} else { // If the member objest doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user object doesn't exist
errorEmbed(context, "Please specify a valid user");
}
} else { // If the user isn't mod
errorEmbed(context, "You do not have permission to run this command");
}
}
}
// Send an embed in case of an error
function errorEmbed(context, message) {
const embed = new MessageEmbed()
.setColor(embedColor)
.setDescription(message);
context.message.channel.send(embed);
}
module.exports = warn;