This commit is contained in:
plane000
2018-06-15 11:28:50 +01:00
12 changed files with 614 additions and 193 deletions

View File

@@ -9,52 +9,65 @@ const SpaceCommands = require('./commands/spacecommands')
const AdminCommands = require('./commands/admincommands')
const CommandManager = require('./main');
var commands = {};
let commands = {};
module.exports.commands = commands;
function addCommand(name, command, alt, usage, desc, requrePerms, functionReference) {
commands[command] = {
name: name,
command: command,
alt: alt,
usage: usage,
desc: desc,
requrePerms: requrePerms,
functionReference: functionReference
}
commands[command] = {
name: name,
command: command,
alt: alt,
usage: usage,
desc: desc,
requrePerms: requrePerms,
functionReference: functionReference
}
}
/*command name, command, alt, usage, description, require permission, reference*/
module.exports.loadCommands = function() {
//general commands
addCommand('Help', 'help', undefined, 'help [command] or help', 'Returns a usage chart for the command requested, or returns a link to a command list', false, Commands.help);
addCommand('Say', 'say', undefined, 'say [input]', 'Repeats the input', false, Commands.say);
addCommand('Version', 'version', undefined, 'version', 'Returns the version', false, Commands.version);
addCommand('Ping', 'ping', undefined, 'ping', 'Returns round trip time to discords servers', false, Commands.ping);
addCommand('Cat', 'cat', undefined, 'cat', 'Returns a picture of a cat', false, Commands.cat);
addCommand('Dog', 'dog', undefined, 'dog', 'Returns a picture of a dog', false, Commands.dog);
addCommand('Undo', 'undo', undefined, 'undo', 'Deletes last message sent by Jeffery from the channel the command was issued in', false, Commands.undo);
addCommand('HUG', 'hug', undefined, 'hug', 'Sends cutest hugs', false, Commands.hug);
//general commands
addCommand('Help', 'help', undefined, 'help [command] or help', 'Returns a usage chart for the command requested, or returns a link to a command list', false, Commands.help);
addCommand('Say', 'say', undefined, 'say [input]', 'Repeats the input', false, Commands.say);
addCommand('Version', 'version', undefined, 'version', 'Returns the version', false, Commands.version);
addCommand('Ping', 'ping', undefined, 'ping', 'Returns round trip time to discords servers', false, Commands.ping);
addCommand('Cat', 'cat', undefined, 'cat', 'Returns a picture of a cat', false, Commands.cat);
addCommand('Dog', 'dog', undefined, 'dog', 'Returns a picture of a dog', false, Commands.dog);
addCommand('Undo', 'undo', undefined, 'undo', 'Deletes last message sent by Jeffery from the channel the command was issued in', false, Commands.undo);
addCommand('HUG', 'hug', undefined, 'hug', 'Sends cutest hugs', false, Commands.hug);
addCommand('Pallet', 'pallet', undefined, 'pallet [number of colours]', 'Returns a random colour palet with the amount of colours specified (2-7)', false, Commands.pallet);
addCommand('QR Code', 'qr', undefined, 'qr [string]', 'Generates a QR code from the string of text provided', false, Commands.qr);
//rule commands
addCommand('Rules', 'rules', undefined, 'rules', 'Returns all the rules for the server the command was issued in', false, MultiServerCommands.rules);
addCommand('Rule', 'rule', undefined, 'rule [rule number]', 'Returns corresponding rule for the server the command was issued in', false, MultiServerCommands.rule);
addCommand('Add Rule', 'addrule', undefined, 'addrule [new rule]', 'Adds a rule to the rule list for the server the command was issued in', true, MultiServerCommands.addrule);
addCommand('Delete Rule', 'delrule', undefined, 'delrule [rule number]', 'Deletes the corresponding rule for the server the command was issued in', true, MultiServerCommands.delrule);
addCommand('EditRule', 'editrule', undefined, 'editrule [rule number] [new rule]', 'Edits the corresponding rule for the server the command was issued in', true, MultiServerCommands.editrule);
//birthday commands
addCommand('Add Birthday', 'addbirthday', undefined, 'addbirthday [DD/MM/YYYY] [Who\'s birthday]', 'Adds a users birthday for the server the command was issued in, including a date and a name', false, MultiServerCommands.addbirthday);
addCommand('Delete Birthday', 'delbirthday', undefined, 'delbirthday [Who\'s birthday]', 'Deletes a users birthday for the server the command was issued in', false, MultiServerCommands.delbirthday);
addCommand('Next Birthday', 'nextbirthday', undefined, 'nextbirthday', 'Returns the next persons birthday and the date of their birthday on the server the command was issued in', false, MultiServerCommands.delbirthday);
addCommand('All Birthdays', 'allbirthdays', undefined, 'allbirthdays', 'Returns a list of all the birthdays registered on the server the command was issued on', false, MultiServerCommands.allbirthdays);
//rule commands
addCommand('Rules', 'rules', undefined, 'rules', 'Returns all the rules for the server the command was issued on', false, MultiServerCommands.rules);
addCommand('Rule', 'rule', undefined, 'rule [rule number]', 'Returns corresponding rule for the server the command was issued on', false, MultiServerCommands.rule);
addCommand('Add Rule', 'addrule', undefined, 'addrule [new rule]', 'Adds a rule to the rule list for the server the command was issued on', true, MultiServerCommands.addrule);
addCommand('Delete Rule', 'delrule', undefined, 'delrule [rule number]', 'Deletes the corresponding rule for the server the command was issued on', true, MultiServerCommands.delrule);
addCommand('EditRule', 'editrule', undefined, 'editrule [rule number] [new rule]', 'Edits the corresponding rule for the server the command was issued on', true, MultiServerCommands.editrule);
//vote commands
addCommand('Poll', 'poll', undefined, 'poll start [poll name/question] [--option1--option2...] or poll stop or poll view', 'Starts/stops an automated poll with the options given as a fourth argument to \'poll start\' and are seperated with --s, stopping a poll will produce the results. Veiwing a poll will produce the options', false, MultiServerCommands.poll);
addCommand('Vote', 'vote', undefined, 'vote [option]', 'Places your vote on the option you chose, based on the running poll in the server the \'poll start\' command was issued in', false, MultiServerCommands.vote);
//vote commands
addCommand('Poll', 'poll', undefined, 'poll start [option1/option2...] or poll stop', 'Starts/stops an automated poll with the options given as a third argument to \'poll start\' and are seperated with a \'/\' with no spaces, stopping a poll will produce the results', false, MultiServerCommands.poll);
addCommand('Vote', 'vote', undefined, 'vote [option]', 'Places your vote on the option you chose, based on the running poll in the server the \'poll start\' command was issued in', false, MultiServerCommands.vote);
//space commands
addCommand('Next Launch', 'nextlaunch', undefined, 'nextlaunch', 'Returns information on the next significant space flight in the space industry', false, SpaceCommands.nextlaunch);
addCommand('Space Image', 'spaceimg', undefined, 'spaceimg [latitude];[longitude]', 'Returns a satelite image of the specified location taken the day before', false, SpaceCommands.spaceimg);
//space commands
addCommand('Next Launch', 'nextlaunch', undefined, 'nextlaunch', 'Returns information on the next significant space flight in the space industry', false, SpaceCommands.nextlaunch);
//chess commands
addCommand('Start Game', 'startgame', undefined, 'startgame [user you want to play againt\'s tag', 'Starts a chess game against you and the user you choose to play', false, MultiServerCommands.startGame);
//admin commands
addCommand('Shutdown', 'stop', undefined, 'stop', 'Shutsdown JefferyBot', true, AdminCommands.stop);
addCommand('Reload', 'reload', undefined, 'reload', 'Reloads the server config and the misc config', false, AdminCommands.reload);
addCommand('Set Prefix', 'setprefix', undefined, 'setprefix [new prefix]', 'Changes Jeffery\'s prefix in the server it was issued in to the new prefix', true, AdminCommands.setprefix);
addCommand('Set Game', 'setgame', undefined, 'setgame [new game]', 'Changes Jeffery\'s game to the new game', true, AdminCommands.setgame);
//admin commands
addCommand('Shutdown', 'stop', undefined, 'stop', 'Shutsdown JefferyBot', true, AdminCommands.stop);
addCommand('Reload', 'reload', undefined, 'reload', 'Reloads the server config and the misc config', false, AdminCommands.reload);
addCommand('Set Prefix', 'setprefix', undefined, 'setprefix [new prefix]', 'Changes Jeffery\'s prefix in the server it was issued in to the new prefix', true, AdminCommands.setprefix);
addCommand('Set Game', 'setgame', undefined, 'setgame [new game]', 'Changes Jeffery\'s game to the new game', true, AdminCommands.setgame);
addCommand('Dump Roles', 'dumproles', undefined, 'dumproles', 'Dumps the servers roles and their ID\'s', false, AdminCommands.dumpRoles);
}

View File

@@ -7,7 +7,7 @@ const Helper = require('../helper.js');
/*message object, messaage full, message args, discord client*/
module.exports.addadminrole = function(message, msg, args, discordclient) {
module.exports.addadminrole = async function(message, msg, args, discordclient) {
}
@@ -28,7 +28,7 @@ module.exports.reload = async function(message, msg, args, discordclient) {
module.exports.setprefix = async function(message, msg, args, discordclient) {
if (args[1]) {
var servers = Config.getservers()
let servers = Config.getservers()
servers[message.guild.id].prefix = args[1]
Config.setservers(servers);
Config.writeToFile();
@@ -39,5 +39,39 @@ module.exports.setprefix = async function(message, msg, args, discordclient) {
}
module.exports.setgame = async function(message, msg, args, discordclient) {
if (args[1]) {
let newGame = '';
for (let i = 1; i < args.length; i++) {
newGame += args[i] + ' ';
}
Config.getconfig().NowPlaying = newGame;
Config.writeToFile();
discordclient.user.setActivity(Config.getconfig().NowPlaying);
message.channel.send(`:white_check_mark: \`Jeffery's game is now ${newGame} \``);
} else {
message.channel.send(':no_entry_sign: \`No new game specified\`')
}
}
module.exports.dumpRoles = async function(message, msg, args, discordclient) {
let output = 'Role name | Role Snowflake ID \n---------------------------------------------------\n'
let padding = 22;
message.guild.roles.array().forEach((role) => {
let nameLength = role.name.length;
let spacing = padding - nameLength;
let rolename = role.name;
let roleID = role.id;
output += rolename;
for (let i = 0; i < spacing; i++) {
output += ' ';
}
output += ' | ';
output += roleID + '\n';
});
message.channel.send('```' + output + '```');
}

View File

@@ -1,6 +1,7 @@
const Discord = require('discord.js');
const ping = require('ping');
const fs = require('fs');
const qr = require('qr-image');
const Config = require('../config.js');
const CommandManager = require('../commandmanager.js');
const Helper = require('../helper.js');
@@ -8,10 +9,10 @@ const Helper = require('../helper.js');
/*message object, messaage full, message args, discord client*/
module.exports.help = async function(message, msg, args, discordclient) {
var commands = CommandManager.commands;
let commands = CommandManager.commands;
if (args[1]) {
if (commands[args[1].toLowerCase()]) {
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle(commands[args[1]].name);
em.addField('Command:', commands[args[1]].command);
@@ -35,7 +36,7 @@ module.exports.say = async function(message, msg, args, discordclient) {
}
module.exports.version = async function(message, msg, args, discordclient) {
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle('Version:');
em.setDescription(Config.getconfig().Version);
@@ -51,36 +52,36 @@ module.exports.ping = async function(message, msg, args, discordclient) {
}
module.exports.cat = async function(message, msg, args, discordclient) {
var url = 'http://thecatapi.com/api/images/get?format=xml&results_per_page=1&api_key=MzA1Njcz';
var result = await Helper.requestPromise(url);
var output = result.match(/<url>(.*?)<\/url>/)[1];
let url = 'http://thecatapi.com/api/images/get?format=xml&results_per_page=1&api_key=MzA1Njcz';
let result = await Helper.requestPromise(url);
let output = result.match(/<url>(.*?)<\/url>/)[1];
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setImage(output);
message.channel.send(em);
}
module.exports.dog = async function(message, msg, args, discordclient) {
var url = 'https://dog.ceo/api/breeds/image/random';
let url = 'https://dog.ceo/api/breeds/image/random';
try {
var result = await Helper.requestPromise(url);
var output = JSON.parse(result).messsage;
let result = await Helper.requestPromise(url);
let output = JSON.parse(result).messsage;
} catch (e) {
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
return;
}
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setImage(output);
message.channel.send(em);
}
module.exports.undo = function (message, msg, args, discordclient) {
module.exports.undo = async function (message, msg, args, discordclient) {
message.channel.fetchMessages({ limit: 50 })
.then((_messages) => {
var messages = _messages.array();
for (var i = 0; i < messages.length; i++) {
let messages = _messages.array();
for (let i = 0; i < messages.length; i++) {
if (messages[i].author.id === discordclient.user.id) {
messages[i].delete();
return;
@@ -90,9 +91,52 @@ module.exports.undo = function (message, msg, args, discordclient) {
.catch();
};
module.exports.hug = function(message, msg, args, discordclient) {
var em = new Discord.RichEmbed();
module.exports.hug = async function(message, msg, args, discordclient) {
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setImage('https://cdn.discordapp.com/attachments/345580737149403146/442232811605458957/cat-instantly-hugs-plush-toy.gif');
message.channel.send(em);
}
module.exports.pallet = async function(message, msg, args, discordclient) {
if(args[1]) {
if (args[1] <= 7) {
if (args[1] >= 2) {
let hex = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'];
let colours = args[1];
let output = '';
for (let i = 0; i < colours; i++) {
let currentcol = '#';
for (let j = 0; j < 6; j++) {
let rnd = Math.floor(Math.random() * 16);
currentcol += hex[rnd];
}
output += currentcol + ', ';
}
output = output.substring(0, output.length - 3);
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.addField(`Here are ${colours} random colours!`, output);
message.channel.send(em);
} else {
message.channel.send(`:no_entry_sign: \`Too few colours entered (2-7)\``);
}
} else {
message.channel.send(`:no_entry_sign: \`Too many colours entered (2-7)\``);
}
} else {
message.channel.send(`:no_entry_sign: \`Please provide the ammount of colours you want (2-7)\``);
}
}
module.exports.qr = async function(message, msg, args, discordclient) {
if (args[1]) {
message.channel.send('', new Discord.Attachment(qr.image(msg.substring(3), { type: 'png' })));
}
else {
message.channel.send(':no_entry_sign: \`Please provide what you want turned into a QR code\`');
}
}

View File

@@ -0,0 +1,17 @@
const Discord = require('discord.js');
const Logger = require('../logger');
const Config = require('../config');

View File

@@ -1,5 +1,4 @@
const Discord = require('discord.js');
const ping = require('ping');
const fs = require('fs');
const Config = require('../config.js');
const Helper = require('../helper.js');
@@ -8,16 +7,16 @@ const Helper = require('../helper.js');
/*rule commands*/
module.exports.rules = async function(message, msg, args, discordclient) {
var serverName = message.guild.name;
var serverID = message.guild.id;
var serversConfig = Config.getservers();
var Rules = serversConfig[serverID].rules;
let serverName = message.guild.name;
let serverID = message.guild.id;
let serversConfig = Config.getservers();
let Rules = serversConfig[serverID].rules;
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle(serverName + '\'s Server Rules');
for (var i = 1; i < Rules.length; i++) {
for (let i = 1; i < Rules.length; i++) {
em.addField(`Rule ${i}:`, Rules[i]);
}
@@ -25,13 +24,13 @@ module.exports.rules = async function(message, msg, args, discordclient) {
}
module.exports.rule = async function(message, msg, args, discordclient) {
var serverName = message.guild.name;
var serverID = message.guild.id;
var serversConfig = Config.getservers();
var Rules = serversConfig[serverID].rules;
let serverName = message.guild.name;
let serverID = message.guild.id;
let serversConfig = Config.getservers();
let Rules = serversConfig[serverID].rules;
try {
var rule = Rules[args[1]];
let rule = Rules[args[1]];
message.channel.send(`Rule ${args[1]}: ${rule}`);
} catch (e) {
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
@@ -39,13 +38,13 @@ module.exports.rule = async function(message, msg, args, discordclient) {
}
module.exports.addrule = async function(message, msg, args, discordclient) {
var serverName = message.guild.name;
var serverID = message.guild.id;
var serversConfig = Config.getservers();
var Rules = serversConfig[serverID].rules;
let serverName = message.guild.name;
let serverID = message.guild.id;
let serversConfig = Config.getservers();
let Rules = serversConfig[serverID].rules;
var newRule = args[1] + ' ';
for (var i = 2; i < args.length; i++) {
let newRule = args[1] + ' ';
for (let i = 2; i < args.length; i++) {
newRule += args[i] + ' ';
}
@@ -58,7 +57,7 @@ module.exports.addrule = async function(message, msg, args, discordclient) {
return;
}
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle('Rule successfully added!');
em.addField(`Rule ${Rules.length - 1}:`, newRule);
@@ -66,37 +65,40 @@ module.exports.addrule = async function(message, msg, args, discordclient) {
}
module.exports.delrule = async function(message, msg, args, discordclient) {
var serverName = message.guild.name;
var serverID = message.guild.id;
var serversConfig = Config.getservers();
var Rules = serversConfig[serverID].rules;
var toDelete = args[1];
try {
Rules.splice(toDelete, 1);
serversConfig[serverID].rules = Rules;
Config.writeToFile();
} catch (e) {
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
return;
if (args[1]) {
let serverName = message.guild.name;
let serverID = message.guild.id;
let serversConfig = Config.getservers();
let Rules = serversConfig[serverID].rules;
let toDelete = args[1];
try {
Rules.splice(toDelete, 1);
serversConfig[serverID].rules = Rules;
Config.writeToFile();
} catch (e) {
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
return;
}
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle('Rule successfully deleted!');
em.addField(`Rule ${toDelete} deleted`, 'All subsiquent rules pushed one space to the left');
message.channel.send(em);
} else {
message.channel.send(`:no_entry_sign: \`You did not specify what to delete\``);
}
var em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle('Rule successfully deleted!');
em.addField(`Rule ${toDelete} deleted`, 'All subsiquent rules pushed one space to the left');
message.channel.send(em);
}
module.exports.editrule = async function(message, msg, args, discordclient) {
var serverName = message.guild.name;
var serverID = message.guild.id;
var serversConfig = Config.getservers();
var Rules = serversConfig[serverID].rules;
let serverName = message.guild.name;
let serverID = message.guild.id;
let serversConfig = Config.getservers();
let Rules = serversConfig[serverID].rules;
var newRule = args[2] + ' ';
for (var i = 3; i < args.length; i++) {
let newRule = args[2] + ' ';
for (let i = 3; i < args.length; i++) {
newRule += args[i] + ' ';
}
@@ -108,30 +110,59 @@ module.exports.editrule = async function(message, msg, args, discordclient) {
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``);
return;
}
var em = new Discord.RichEmbed();
let em = new Discord.RichEmbed();
em.setColor('BLUE');
em.setTitle('Rule successfully edited!');
em.addField(`Rule ${args[1]}:`, newRule);
message.channel.send(em);
}
/*birthday commands*/
module.exports.addbirthday = async function(message, msg, args, discordclient) {
//input date is [DD/MM/YYYY] such that 14/05/2002
let birthdays = Config.getservers()[message.guild.id].birthdays;
Config.getservers()[message.guild.id].birthdays = birthdays;
Config.writeToFile();
}
module.exports.delbirthday = async function(message, msg, args, discordclient) {
let birthdays = Config.getservers()[message.guild.id].birthdays;
Config.getservers()[message.guild.id].birthdays = birthdays;
Config.writeToFile();
}
module.exports.nextbirthday = async function(message, msg, args, discordclient) {
let birthdays = Config.getservers()[message.guild.id].birthdays;
}
module.exports.allbirthdays = async function(message, msg, args, discordclient) {
let birthdays = Config.getservers()[message.guild.id].birthdays;
}
/*poll commands*/
var polls = {};
let polls = {};
module.exports.poll = async function(message, msg, args, discordclient) {
if (args[1] == 'start') {
if (args[2]) {
if (!polls[message.guild.id]) {
await startPoll(message, args);
var options = '';
let options = '';
for (i in polls[message.guild.id].options) {
options += polls[message.guild.id].options[i] + ', ';
}
options = options.substring(0, options.length - 2);
var em = new Discord.RichEmbed();
em.setTitle('Poll started!');
let em = new Discord.RichEmbed();
em.setAuthor('Poll started!');
em.setColor('BLUE');
em.setTitle(polls[message.guild.id].pollq);
em.addField('With the options:', options)
em.setFooter('Type \'vote [option]\' to vote for that option');
message.channel.send(em);
@@ -147,7 +178,7 @@ module.exports.poll = async function(message, msg, args, discordclient) {
} else if (args[1] == 'stop') {
if (polls[message.guild.id]) {
var results = polls[message.guild.id].votes
let results = polls[message.guild.id].votes
.map((x, i) =>
{
return {
@@ -160,26 +191,62 @@ module.exports.poll = async function(message, msg, args, discordclient) {
.filter((x, i, arr) => x.count == arr[0].count)
//.map(x => x.value)
var winners = '';
var votesForWinners = '';
let winners = '';
let votesForWinners = '';
for (var i = 0; i < results.length; i++) {
for (let i = 0; i < results.length; i++) {
winners += results[i].value + ' and ';
votesForWinners = results[i].count;
}
winners = winners.substring(0, winners.length - 5);
var em = new Discord.RichEmbed();
em.setTitle('Poll Results');
let em = new Discord.RichEmbed();
em.setAuthor('Poll Results');
em.setColor('BLUE');
em.setTitle(polls[message.guild.id].pollq)
em.addField(winners + ' wins!', 'with ' + votesForWinners + ' vote(s)');
message.channel.send(em);
delete polls[message.guild.id];
return;
} else {
message.channel.send(':no_entry_sign: \`There are no polls running, you can type \'poll start\' to start a new poll\`');
return;
}
} else if (args[1] == 'view') {
if (polls[message.guild.id]) {
let poll = polls[message.guild.id];
let q = poll.pollq;
let options = poll.options;
let votes = poll.votes;
let firstline = '';
let secondline = ' ';
for(let i = 0; i < options.length; i++) {
firstline += options[i] + ', ';
let length = options[i].length + 2;
let padding = length - 1;
for(let j = 0; j < padding; j++) {
secondline += ' ';
}
secondline += votes[i];
for(let j = 0; j < padding; j++) {
secondline += ' ';
}
}
firstline = firstline.substring(0, firstline.length - 2);
let em = new Discord.RichEmbed();
em.setAuthor(`For the question \'${q}\'`);
em.setTitle('With the options and votes:');
em.setColor('BLUE');
em.addField(firstline, secondline);
message.channel.send(em);
} else {
message.channel.send(':no_entry_sign: \`There are no polls running, you can type \'poll start\' to start a new poll\`');
}
} else {
message.channel.send(':no_entry_sign: \`Incorrect arguments given, try \'help poll\' for usage\`');
return;
@@ -188,18 +255,18 @@ module.exports.poll = async function(message, msg, args, discordclient) {
module.exports.vote = async function(message, msg, args, discordclient) {
if (polls[message.guild.id]) {
var poll = polls[message.guild.id];
var hasVoted = false;
for (var i = 0; i < poll.voted.length; i++) {
let poll = polls[message.guild.id];
let hasVoted = false;
for (let i = 0; i < poll.voted.length; i++) {
if (poll.voted[i] == message.author.id) {
hasVoted = true;
}
}
if (!hasVoted) {
var option = args.slice(1).join(" ");
var index;
let option = args.slice(1).join(" ");
let index;
for (var i = 0; i < poll.options.length; i++) {
for (let i = 0; i < poll.options.length; i++) {
if (poll.options[i] == option) {
index = i
poll.votes[i]++;
@@ -225,9 +292,17 @@ module.exports.vote = async function(message, msg, args, discordclient) {
}
async function startPoll(messageObj, args) {
var parsedOptions =args.slice(2).join(" ").match(/(\\.|[^/])+/g)
var parsedVotes = await getStartingVotes(parsedOptions)
let parsedOptions = args.slice(2).join(" ").split("--");
let pollquestion = parsedOptions[0];
for(let i = 0; i < parsedOptions.length; i++) {
parsedOptions[i]= parsedOptions[i].trim();
}
parsedOptions.splice(0, 1);
let parsedVotes = await getStartingVotes(parsedOptions)
polls[messageObj.guild.id] = {
pollq: pollquestion,
options: parsedOptions,
votes: parsedVotes,
voted: []
@@ -235,9 +310,153 @@ async function startPoll(messageObj, args) {
}
async function getStartingVotes(options) {
var votes = [];
let votes = [];
for (i in options) {
votes.push('0');
}
return votes;
}
/*chess commands*/
let chess = {};
module.exports.startGame = async function(message, msg, args, discordclient) {
if (!chess[message.guild.id]) {
if (args[1]) {
try {
let player1 = message.mentions.members.first();
await initBoard(message, message.author, player1);
let em = new Discord.RichEmbed();
em.setAuthor()
message.channel.send('```' + await drawcurrentstate(message) + '```');
} catch (e) {
message.channel.send(':no_entry_sign: \`You have not mentioned a user to play with...\`')
}
} else {
message.channel.send(':no_entry_sign: \`You have not mentioned a user to play with\`')
}
} else {
message.channel.send(':no_entry_sign: \`There is allready a game in progress.\`');
}
}
module.exports.move = async function(message, msg, args, discordclient) {
}
//game logic
async function initBoard(message, p1, p2) {
chess[message.guild.id] = {
board: await initMatrix(8, 8, ''),
prevMoves: [],
winner: 0,
players: [
{
playerName: p1.name,
playerID: p1.id,
score: 0,
takenPeices: {
queen: 0,
rook: 0,
bishop: 0,
knight: 0,
pawn: 0
}
},
{
playerName: p2.name,
playerID: p1.id,
score: 0,
takenPeices: {
queen: 0,
rook: 0,
bishop: 0,
knight: 0,
pawn: 0
}
}
]
}
}
async function initMatrix(width, height, defValue) {
//array is layed out such that arr[y][x] = x, y
let matrix = [];
for (let i = 0; i < height; i++) {
matrix[i] = [];
if (defValue) {
for (let j = 0; j < width; j++) {
matrix[i][j] = defValue;
}
}
}
matrix[0][0] = '♖';
matrix[0][1] = '♘';
matrix[0][2] = '♗';
matrix[0][3] = '♕';
matrix[0][4] = '♔';
matrix[0][5] = '♗';
matrix[0][6] = '♘';
matrix[0][7] = '♖';
matrix[1][0] = '♙';
matrix[1][1] = '♙';
matrix[1][2] = '♙';
matrix[1][3] = '♙';
matrix[1][4] = '♙';
matrix[1][5] = '♙';
matrix[1][6] = '♙';
matrix[1][7] = '♙';
matrix[7][0] = '♜';
matrix[7][1] = '♞';
matrix[7][2] = '♝';
matrix[7][3] = '♚';
matrix[7][4] = '♛';
matrix[7][5] = '♝';
matrix[7][6] = '♞';
matrix[7][7] = '♜';
matrix[6][0] = '♟';
matrix[6][1] = '♟';
matrix[6][2] = '♟';
matrix[6][3] = '♟';
matrix[6][4] = '♟';
matrix[6][5] = '♟';
matrix[6][6] = '♟';
matrix[6][7] = '♟';
return matrix;
}
async function drawcurrentstate(message) {
let c = chess[message.guild.id].board;
let board = '';
board += `┌─-─┬─-─┬─-─┬─-─┬─-─┬─-─┬─-─┬─-─┬─-─┐\n`;
board += `\n`;
board += `├─-─╆━-━┿━-━┿━-━┿━-━┿━-━┿━-━┿━-━┿━-━┥\n`;
board += `| ${c[0][0]}${c[0][1]}${c[0][2]}${c[0][3]}${c[0][4]}${c[0][5]}${c[0][6]}${c[0][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[1][0]}${c[1][1]}${c[1][2]}${c[1][3]}${c[1][4]}${c[1][5]}${c[1][6]}${c[1][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[2][0]}${c[2][1]}${c[2][2]}${c[2][3]}${c[2][4]}${c[2][5]}${c[2][6]}${c[2][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[3][0]}${c[3][1]}${c[3][2]}${c[3][3]}${c[3][4]}${c[3][5]}${c[3][6]}${c[3][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[4][0]}${c[4][1]}${c[4][2]}${c[4][3]}${c[4][4]}${c[4][5]}${c[4][6]}${c[4][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[5][0]}${c[5][1]}${c[5][2]}${c[5][3]}${c[5][4]}${c[5][5]}${c[5][6]}${c[5][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[6][0]}${c[6][1]}${c[6][2]}${c[6][3]}${c[6][4]}${c[6][5]}${c[6][6]}${c[6][7]} |\n`;
board += `├─-─╂─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┼─-─┤\n`;
board += `| ${c[7][0]}${c[7][1]}${c[7][2]}${c[7][3]}${c[7][4]}${c[7][5]}${c[7][6]}${c[7][7]} |\n`;
board += `└─-─┸─-─┴─-─┴─-─┴─-─┴─-─┴─-─┴─-─┴─-─┘\n`;
return board;
}

View File

@@ -1,5 +1,5 @@
const Discord = require('discord.js');
const ping = require('ping');
const https = require('https');
const fs = require('fs');
const Config = require('../config.js');
const Helper = require('../helper.js');
@@ -7,78 +7,126 @@ const Helper = require('../helper.js');
/*message object, messaage full, message args, discord client*/
module.exports.nextlaunch = async function(message, msg, args, discordclient) {
var url = 'https://launchlibrary.net/1.4/launch/next/1';
try {
var result = await Helper.requestPromise(url);
var launch = JSON.parse(result).launches[0];
let url = 'https://launchlibrary.net/1.4/launch/next/1';
try {
let result = await Helper.requestPromise(url);
let launch = JSON.parse(result).launches[0];
var em = new Discord.RichEmbed();
em.setTitle(launch.name);
em.setColor('BLUE');
em.setAuthor('Next Launch Info:', 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/NASA_logo.svg/1200px-NASA_logo.svg.png', 'https://spaceflightnow.com/launch-schedule/');
em.setThumbnail('https://www.nasa.gov/sites/default/files/saturnv-3_0.jpg');
em.url = launch.location.pads[0].mapURL;
let em = new Discord.RichEmbed();
em.setTitle(launch.name);
em.setColor('BLUE');
em.setAuthor('Next Launch Info:', 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/NASA_logo.svg/1200px-NASA_logo.svg.png', 'https://spaceflightnow.com/launch-schedule/');
em.setThumbnail('https://www.nasa.gov/sites/default/files/saturnv-3_0.jpg');
em.url = launch.location.pads[0].mapURL;
let status = 'Unknown';
if (launch.status == 1) {
status = 'Green For Launch';
} else if (launch.status == 2) {
staus = 'RED For Launch';
} else if (launch.status == 3) {
status = 'Mission Success';
} else if (launch.status == 4) {
status = 'Mission Failed';
}
em.addField('Mission Status:', status);
var status = 'Unknown';
if (launch.status == 1) {
status = 'Green For Launch';
} else if (launch.status == 2) {
staus = 'RED For Launch';
} else if (launch.status == 3) {
status = 'Mission Success';
} else if (launch.status == 4) {
status = 'Mission Failed';
}
em.addField('Mission Status:', status);
em.addField('Launch Window Start', launch.windowstart + ' ', true);
em.addField('Launch Window End', launch.windowend, true);
em.addField('Launch Window Start', launch.windowstart + ' ', true);
em.addField('Launch Window End', launch.windowend, true);
if (launch.probability != -1) {
em.addField('Probability of launch:', launch.probability + '%', true);
} else {
em.addField('Probability of launch:', 'Unknown at this time...', true);
}
em.addField('Last Updated At:', launch.changed, true)
if (launch.probability != -1) {
em.addField('Probability of launch:', launch.probability, true);
} else {
em.addField('Probability of launch:', 'Unknown at this time...', true);
}
em.addField('Last Updated At:', launch.changed, true)
em.addBlankField();
em.addBlankField();
let rocket = launch.rocket;
let agencies = rocket.agencies[0];
var rocket = launch.rocket;
var agencies = rocket.agencies[0];
em.addField('Rocket Name:', rocket.name, true);
em.addField('Launch Agency:', agencies.name, true);
em.addField(`More information about ${agencies.name}`, agencies.wikiURL);
em.addField('Rocket Name:', rocket.name, true);
em.addField('Launch Agency:', agencies.name, true);
em.addField(`More information about ${agencies.name}`, agencies.wikiURL);
em.addBlankField();
em.addBlankField();
let location = launch.location;
let pad = location.pads[0];
var location = launch.location;
var pad = location.pads[0];
em.addField('Launch Pad:', pad.name);
em.addField('Loacation Name:', location.name, true);
em.addField('Country:', location.countryCode, true);
em.addField('Launch Pad:', pad.name);
em.addField('Loacation Name:', location.name, true);
em.addField('Country:', location.countryCode, true);
em.addBlankField();
em.addBlankField();
let mission = launch.missions[0];
let missionagency = mission.agencies[0];
let payload = mission.payloads[0];
var mission = launch.missions[0];
var missionagency = mission.agencies[0];
var payload = mission.payloads[0];
em.addField('Mission Name:', mission.name, true);
em.addField('Mission Type:', mission.typeName, true);
em.addField('Mission Name:', mission.name, true);
em.addField('Mission Type:', mission.typeName, true);
em.addField('Agency Name:', missionagency.name, true);
em.addField('Agency Region:', missionagency.countryCode, true);
em.addField('Mission Description:', mission.description)
message.channel.send(em);
<<<<<<< HEAD
em.addField('Agency Name:', missionagency.name, true);
em.addField('Agency Region:', missionagency.countryCode, true);
em.addField('Mission Description:', mission.description)
message.channel.send(em);
} catch (e) {
console.log(e);
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
}
=======
} catch (e) {
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
}
}
>>>>>>> d2e2c160e6597833c3bdf44372777e81e32eeb97
module.exports.spaceimg = async function(message, msg, args, discordclient) {
if (args.length >= 2) {
let position = args[1].split(";");
if (position.length === 2) {
https.get(`https://api.nasa.gov/planetary/earth/imagery/?lon=${position[1]}&lat=${position[0]}&api_key=${Config.getconfig().NASA_APIKey}`, (resp) => {
let data = "";
resp.on("data", (chunk) => {
data += chunk;
});
resp.on("end", () => {
let image = JSON.parse(data);
if (image.url) {
let em = new Discord.RichEmbed();
em.setColor("BLUE");
em.setTitle("Satellite picture");
em.setURL(image.url);
em.setFooter(`Long: ${position[1]}, Lat: ${position[0]}, Date: ${image.date}`);
em.setImage(image.url);
message.channel.send(em);
} else {
message.channel.send(":no_entry_sign: `Invalid coordonates :/`");
}
});
}).on("error", (err) => {
message.channel.send(":no_entry_sign: `Nasa API service not available :/`");
});
} else {
message.channel.send(":no_entry_sign: `Invalid longitude and latitude. Use this format: lat;long`");
}
} else {
message.channel.send(":no_entry_sign: `Please supply a longitude and a latitude in this format: lat;long`");
}
}
module.exports.pictureoftheday = async function(message, msg, args, discordclient) {
let apiKey = Config.getconfig().NASA_APIKey;
let url = 'https://api.nasa.gov/planetary/apod?api_key=DEMO_KEY';
}
module.exports.nearearthobj = async function(message, msg, args, discordclient) {
let apiKey = Config.getconfig().NASA_APIKey;
let url = 'https://api.nasa.gov/neo/rest/v1/neo/browse?api_key=DEMO_KEY';
}

View File

@@ -1,7 +1,7 @@
const fs = require("fs");
const fs = require('fs');
var config = {};
var servers = {};
let config = {};
let servers = {};
module.exports.getconfig = function() {
return config;
@@ -23,6 +23,7 @@ module.exports.addServer = function(guild) {
servers[guild.id] = {
name: guild.name,
rules: ["Oh yeah, arrays start at 0"],
birthdays: [],
prefix: '+',
adminroles: []
}
@@ -30,7 +31,8 @@ module.exports.addServer = function(guild) {
module.exports.loadDefaults = function() {
config = {
Token: 'DISCORD_TOKEN',
Token: '[DISCORD TOKEN HERE]',
NASA_APIKey: '[NASA API KEY HERE]',
NowPlaying: 'RealLife.exe',
Version: '2.0.1',
};
@@ -38,6 +40,7 @@ module.exports.loadDefaults = function() {
servers['SERVER ID'] = {
name: 'SERVER NAME',
rules: ['RULE 0', 'RULE 1'],
birthdays: [],
prefix: '+',
adminroles: ['123456789101112', '123456789101112']
};

View File

@@ -1,6 +1,5 @@
const Discord = require('discord.js');
const http = require('http');
const ping = require('ping');
const fs = require('fs');
const request = require('request');
const colors = require('colors');
@@ -21,5 +20,17 @@ module.exports.requestPromise = async function(url) {
}
module.exports.isUserAdmin = function(message) {
let isAdmin = false;
if(Config.getservers[message.guild.id].isUserAdmin) {
}
}
module.exports.sleep = function(ms) {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, ms);
});
}

View File

@@ -12,7 +12,7 @@ colors.setTheme({
});
module.exports.logMSG = function(msg) {
var time = getTime();
let time = getTime();
console.log(
'[' + time + '] '
+ 'In '
@@ -23,7 +23,6 @@ module.exports.logMSG = function(msg) {
+ msg.author.discriminator
+ ' issued the command: '
+ msg.content
.input
);
}
@@ -32,7 +31,7 @@ module.exports.logJOIN = function() {
}
module.exports.log = function(msg) {
var time = getTime();
let time = getTime();
console.log(
'[' + time + '] '
+ msg
@@ -41,7 +40,7 @@ module.exports.log = function(msg) {
}
module.exports.success = function(msg) {
var time = getTime();
let time = getTime();
console.log(
'[' + time + '] '
+ msg
@@ -52,7 +51,7 @@ module.exports.success = function(msg) {
}
module.exports.failed = function(msg) {
var time = getTime();
let time = getTime();
console.log(
'[' + time + '] '
+ msg
@@ -63,7 +62,7 @@ module.exports.failed = function(msg) {
}
module.exports.warn = function(msg) {
var time = getTime();
let time = getTime();
console.log(
'[' + time + '] '
+ msg
@@ -96,7 +95,7 @@ function pad(n, width, z) {
}
function getTime() {
var t = new Date();
var time = (pad(t.getHours(), 2) + ':' + pad(t.getMinutes(), 2) + ':' + pad(t.getSeconds(), 2))
let t = new Date();
let time = (pad(t.getHours(), 2) + ':' + pad(t.getMinutes(), 2) + ':' + pad(t.getSeconds(), 2))
return time;
}

25
main.js
View File

@@ -9,9 +9,11 @@ const Commands = require('./commands/commands')
const CommandManager = require('./commandmanager');
const Helper = require('./helper')
const client = new Discord.Client({autoReconnect:true});
Logger.welcome();
const client = new Discord.Client({
autoReconnect:true,
});
Logger.welcome();
/*checks if config exists*/
if (!fs.existsSync('resources/config.json') || !fs.existsSync('resources/servers.json')) {
@@ -21,7 +23,6 @@ if (!fs.existsSync('resources/config.json') || !fs.existsSync('resources/servers
fs.mkdirSync('resources/');
}
Config.loadDefaults();
/*gets all current servers info*/
Config.writeToFile();
}
catch (e) {
@@ -53,6 +54,7 @@ try {
Logger.failed(`Could not connect to discord: ${e.message}`)
}
/*once connected*/
client.on('ready', () => {
try {
@@ -92,8 +94,8 @@ client.on('message', async (message) => {
}
Logger.logMSG(message);
var msg = message.content.toLowerCase().substring(Config.getservers()[message.guild.id].prefix.length);
var args = message.content.substring(Config.getservers()[message.guild.id].prefix.length).split(' ');
let msg = message.content.toLowerCase().substring(Config.getservers()[message.guild.id].prefix.length);
let args = message.content.substring(Config.getservers()[message.guild.id].prefix.length).split(' ');
args[0] = args[0].toLowerCase();
/*command manager checks if command exists*/
@@ -124,6 +126,19 @@ client.on('guildDelete', async (guild) => {
Logger.log(`JefferyBot left the \'${guild.name}\' server!`);
});
client.on("guildMemberAdd", async member => {
if(member.guild.id == "443095663018770432") {
let role = member.guild.roles.find(r => r.name === "Regular Joe");
if (!role) {
Logger.log("role not found")
return;
};
if(member.bot) return;
if(member.roles.find(r => r.name === "Regular Joe")) return Logger.warn("User already has role!");
member.addRole(role)
};
});
client.on("disconnected", function () {
Logger.failed('Disconnected...')
process.exit(1);

15
package-lock.json generated
View File

@@ -243,6 +243,11 @@
"sshpk": "1.14.1"
}
},
"https": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
"integrity": "sha1-PDfHrhqO65ZpBKKtHpdaGUt+06Q="
},
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
@@ -337,6 +342,11 @@
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc="
},
"qr-image": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/qr-image/-/qr-image-3.2.0.tgz",
"integrity": "sha1-n6gpW+rlDEoUnPn5CaHbRkqGcug="
},
"qs": {
"version": "6.5.2",
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
@@ -375,6 +385,11 @@
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
"smartcar-unit": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/smartcar-unit/-/smartcar-unit-1.1.4.tgz",
"integrity": "sha512-BHZ1+E8BImLPLpqSXxCeLCqnzqIGjoqoeCbqKNmgoIEm+8VBsp7xplIKhWwIx51mD9pzEJuhpF4G1RV0gWf7sg=="
},
"snekfetch": {
"version": "3.6.4",
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",

View File

@@ -25,7 +25,10 @@
"discord.js": "^11.3.2",
"fs": "0.0.1-security",
"http": "0.0.0",
"https": "^1.0.0",
"ping": "^0.2.2",
"request": "^2.86.0"
"qr-image": "^3.2.0",
"request": "^2.86.0",
"smartcar-unit": "^1.1.4"
}
}