Add comments to bunny and poll commands
This commit is contained in:
parent
d2493f9131
commit
2e13b4d861
2 changed files with 31 additions and 4 deletions
|
@ -1,25 +1,33 @@
|
||||||
|
// Required components
|
||||||
const { command } = require('vylbot-core');
|
const { command } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
const randomPuppy = require('random-puppy');
|
const randomPuppy = require('random-puppy');
|
||||||
|
|
||||||
|
// Command variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
|
|
||||||
|
// Command class
|
||||||
class bunny extends command {
|
class bunny extends command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set run method, description, and category
|
||||||
super("bunny");
|
super("bunny");
|
||||||
super.description = "Gives you a random bunny";
|
super.description = "Gives you a random bunny";
|
||||||
super.category = "Fun";
|
super.category = "Fun";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
bunny(context) {
|
bunny(context) {
|
||||||
|
// Get a random post from r/Rabbits
|
||||||
randomPuppy('Rabbits').then(image => {
|
randomPuppy('Rabbits').then(image => {
|
||||||
|
// Create an embed containing the random image
|
||||||
let embed = new MessageEmbed()
|
let embed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setImage(image);
|
.setImage(image);
|
||||||
|
|
||||||
|
// Send the embed
|
||||||
context.message.channel.send(embed);
|
context.message.channel.send(embed);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = bunny;
|
module.exports = bunny;
|
||||||
|
|
|
@ -1,25 +1,37 @@
|
||||||
|
// Required components
|
||||||
const { command } = require('vylbot-core');
|
const { command } = require('vylbot-core');
|
||||||
const { MessageEmbed } = require('discord.js');
|
const { MessageEmbed } = require('discord.js');
|
||||||
|
|
||||||
|
// Command variables
|
||||||
const embedColor = "0x3050ba";
|
const embedColor = "0x3050ba";
|
||||||
|
|
||||||
|
// Command class
|
||||||
class poll extends command {
|
class poll extends command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
// Set the command's run method, description, category, and example usage
|
||||||
super("poll");
|
super("poll");
|
||||||
super.description = "Generates a poll with reaction numbers";
|
super.description = "Generates a poll with reaction numbers";
|
||||||
super.category = "General";
|
super.category = "General";
|
||||||
super.usage = "<title>;<option 1>;<option 2>...";
|
super.usage = "<title>;<option 1>;<option 2>...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Run method
|
||||||
poll(context) {
|
poll(context) {
|
||||||
|
// 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 args = context.arguments;
|
||||||
let argsJoined = args.join(' ');
|
let argsJoined = args.join(' ');
|
||||||
args = argsJoined.split(';');
|
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) {
|
if (args.length >= 3 && args.length < 11) {
|
||||||
|
// Set the title to the first argument
|
||||||
let title = args[0];
|
let title = args[0];
|
||||||
let optionString = "";
|
let optionString = "";
|
||||||
|
|
||||||
|
// Array used to get the numbers as their words
|
||||||
|
// arrayOfNumbers[n] = "n written in full words"
|
||||||
let arrayOfNumbers = [
|
let arrayOfNumbers = [
|
||||||
'zero',
|
'zero',
|
||||||
'one',
|
'one',
|
||||||
|
@ -33,14 +45,20 @@ class poll extends command {
|
||||||
'nine'
|
'nine'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
// 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++) {
|
for (let i = 1; i < args.length; i++) {
|
||||||
optionString += `:${arrayOfNumbers[i]}: ${args[i]}\n`;
|
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()
|
let embed = new MessageEmbed()
|
||||||
.setColor(embedColor)
|
.setColor(embedColor)
|
||||||
.setDescription(`**${title}**\n\n${optionString}`);
|
.setDescription(`**${title}**\n\n${optionString}`);
|
||||||
|
|
||||||
|
// Send the embed and then react with the numbers for users to react with,
|
||||||
|
// the bot will determine how many to react with for the amount of options inputted
|
||||||
context.message.channel.send(embed).then(message => {
|
context.message.channel.send(embed).then(message => {
|
||||||
if (args.length == 2) {
|
if (args.length == 2) {
|
||||||
message.react("1️⃣");
|
message.react("1️⃣");
|
||||||
|
@ -99,13 +117,14 @@ class poll extends command {
|
||||||
}
|
}
|
||||||
}).catch(console.error);
|
}).catch(console.error);
|
||||||
|
|
||||||
|
// Delete the message
|
||||||
context.message.delete();
|
context.message.delete();
|
||||||
} else if (args.length >= 11) {
|
} else if (args.length >= 11) { // If the user inputted more than 9 options
|
||||||
let errorEmbed = new MessageEmbed()
|
let errorEmbed = new MessageEmbed()
|
||||||
.setDescription("The poll command can only accept up to 9 options");
|
.setDescription("The poll command can only accept up to 9 options");
|
||||||
|
|
||||||
context.message.channel.send(errorEmbed);
|
context.message.channel.send(errorEmbed);
|
||||||
} else {
|
} else { // If the user didn't give enough data
|
||||||
let errorEmbed = new MessageEmbed()
|
let errorEmbed = new MessageEmbed()
|
||||||
.setDescription("Please use the correct usage: <title>;<option 1>;<option 2>... (separate options with semicolons)");
|
.setDescription("Please use the correct usage: <title>;<option 1>;<option 2>... (separate options with semicolons)");
|
||||||
|
|
||||||
|
@ -114,4 +133,4 @@ class poll extends command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = poll;
|
module.exports = poll;
|
||||||
|
|
Loading…
Reference in a new issue