Compare commits
10 Commits
41742456be
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37b1576e27 | ||
|
|
2b8f86368a | ||
|
|
d92e2fc22c | ||
|
|
ceedb3b277 | ||
|
|
95ff57ea6f | ||
|
|
2d4f3f4c72 | ||
|
|
d2e2c160e6 | ||
|
|
32bdbd1ec9 | ||
|
|
f928baf779 | ||
|
|
3c2d6ea65f |
24
CONTRIBUTING.md
Normal file
24
CONTRIBUTING.md
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
First off, i'd like to thank you for taking the time to contribute to JefferyBot.
|
||||||
|
|
||||||
|
When contributing or submitting pull requests follow these guidelines or your contribution will not be taken seriously.
|
||||||
|
|
||||||
|
## Make sure your code is
|
||||||
|
|
||||||
|
1. Functional
|
||||||
|
2. Maintainable and Scalable
|
||||||
|
3. Readable
|
||||||
|
|
||||||
|
## Linting
|
||||||
|
|
||||||
|
* Tabs - 2 spaces
|
||||||
|
* Same line bracing
|
||||||
|
* Honestly just look around the code base and imitate the style
|
||||||
|
* Use Let let types pls
|
||||||
|
* Use '' for string literals and if needed ``
|
||||||
|
* Keep code well commented
|
||||||
|
|
||||||
|
## Pull requests we reject
|
||||||
|
|
||||||
|
* Anything from b_boy_ww
|
||||||
23
README.md
23
README.md
@@ -1,3 +1,26 @@
|
|||||||
# JefferyBot
|
# JefferyBot
|
||||||
|
|
||||||
An open source, customizable discord bot, made with the discord.js framework.
|
An open source, customizable discord bot, made with the discord.js framework.
|
||||||
|
|
||||||
|
## Discord
|
||||||
|
|
||||||
|
[](https://discord.gg/782zeM9)
|
||||||
|
|
||||||
|
The official JefferyBot server with the master version of Jeffery running live
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
To run JefferyBot, first you must install node. Then run cd to the install directory, then run `npm install` and all of Jeffery's dependencies will automatically install. The first time you run Jeffery it wil instantly exit, a configuration file will be created in the resources folder, a child to the root directory.
|
||||||
|
|
||||||
|
In config.json you must put your bot's token, and the rest is self explanitory.
|
||||||
|
|
||||||
|
Once you have set up the config file, run `node main.js` inside the JefferyBot directory and Jeffery will be running. Then in discord, in a server that your copy of Jeffery is in you can run +help for an extensive list of commands.
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT
|
||||||
|
|
||||||
|
## Contrubuters
|
||||||
|
|
||||||
|
- Ben (plane000)#8618 - Creator, maintaner
|
||||||
|
- xX_WhatsTheGeek_Xx#8606 - Contributer
|
||||||
@@ -5,52 +5,74 @@ const Logger = require('./logger');
|
|||||||
const Config = require('./config');
|
const Config = require('./config');
|
||||||
const Commands = require('./commands/commands')
|
const Commands = require('./commands/commands')
|
||||||
const MultiServerCommands = require('./commands/multiservercommands')
|
const MultiServerCommands = require('./commands/multiservercommands')
|
||||||
|
const SpaceCommands = require('./commands/spacecommands')
|
||||||
const AdminCommands = require('./commands/admincommands')
|
const AdminCommands = require('./commands/admincommands')
|
||||||
const CommandManager = require('./main');
|
const CommandManager = require('./main');
|
||||||
|
|
||||||
var commands = {};
|
let commands = {};
|
||||||
|
|
||||||
module.exports.commands = commands;
|
module.exports.commands = commands;
|
||||||
|
|
||||||
function addCommand(name, command, alt, usage, desc, requrePerms, functionReference) {
|
function addCommand(name, command, alt, usage, desc, requrePerms, functionReference) {
|
||||||
commands[command] = {
|
commands[command] = {
|
||||||
name: name,
|
name: name,
|
||||||
command: command,
|
command: command,
|
||||||
alt: alt,
|
alt: alt,
|
||||||
usage: usage,
|
usage: usage,
|
||||||
desc: desc,
|
desc: desc,
|
||||||
requrePerms: requrePerms,
|
requrePerms: requrePerms,
|
||||||
functionReference: functionReference
|
functionReference: functionReference
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*command name, command, alt, usage, description, require permission, reference*/
|
/*command name, command, alt, usage, description, require permission, reference*/
|
||||||
|
|
||||||
module.exports.loadCommands = function() {
|
module.exports.loadCommands = function() {
|
||||||
//general commands
|
//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('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('Say', 'say', undefined, 'say [input]', 'Repeats the input', false, Commands.say);
|
||||||
addCommand('Version', 'version', undefined, 'version', 'Returns the version', false, Commands.version);
|
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('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('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('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('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('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);
|
||||||
|
addCommand('Is', 'is', undefined, 'is [thing]', 'Determains wheather a thing is a thing or not', false, Commands.is);
|
||||||
|
addCommand('Are', 'are', undefined, 'are [things a thing]', 'Determains wheather some things are things or not', false, Commands.are);
|
||||||
|
addCommand('YEET', 'yeet', undefined, 'yeet', 'Y E E T', false, Commands.YEET);
|
||||||
|
addCommand('DABBBBB', 'dab', undefined, 'dab', 'dabs on the h8rz', false, Commands.dab);
|
||||||
|
|
||||||
//rule commands
|
//rule commands
|
||||||
addCommand('Rules', 'rules', undefined, 'rules', 'Returns all the rules for the server the command was issued on', false, MultiServerCommands.rules);
|
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 on', false, MultiServerCommands.rule);
|
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 on', true, MultiServerCommands.addrule);
|
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 on', true, MultiServerCommands.delrule);
|
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 on', true, MultiServerCommands.editrule);
|
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);
|
||||||
|
|
||||||
//vote commands
|
//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('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);
|
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);
|
||||||
|
|
||||||
//admin commands
|
//space commands
|
||||||
addCommand('Shutdown', 'stop', undefined, 'stop', 'Shutsdown JefferyBot', true, AdminCommands.stop);
|
addCommand('Next Launch', 'nextlaunch', undefined, 'nextlaunch', 'Returns information on the next significant space flight in the space industry', false, SpaceCommands.nextlaunch);
|
||||||
addCommand('Reload', 'reload', undefined, 'reload', 'Reloads the server config and the misc config', false, AdminCommands.reload);
|
addCommand('Space Image', 'spaceimg', undefined, 'spaceimg [latitude];[longitude]', 'Returns a satelite image of the specified location taken the day before', false, SpaceCommands.spaceimg);
|
||||||
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);
|
//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);
|
||||||
|
addCommand('Dump Roles', 'dumproles', undefined, 'dumproles', 'Dumps the servers roles and their ID\'s', false, AdminCommands.dumpRoles);
|
||||||
|
addCommand('Output Servers Config', 'serverconfig', undefined, 'serverconfig', 'Dumps the server config file, only issuable by the bot owner themself', true, AdminCommands.serverconfig);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ module.exports.addadminrole = function(message, msg, args, discordclient) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.stop = async function(message, msg, args, discordclient) {
|
module.exports.stop = function(message, msg, args, discordclient) {
|
||||||
message.channel.send(':white_check_mark: \`Disconnected...\`');
|
message.channel.send(':white_check_mark: \`Disconnected...\`');
|
||||||
Logger.failed('Disconnected');
|
Logger.failed('Disconnected');
|
||||||
discordclient.destroy();
|
discordclient.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.reload = async function(message, msg, args, discordclient) {
|
module.exports.reload = function(message, msg, args, discordclient) {
|
||||||
try {
|
try {
|
||||||
Config.loadFromFile();
|
Config.loadFromFile();
|
||||||
message.channel.send(':white_check_mark: \`Configuration reloaded...\`');
|
message.channel.send(':white_check_mark: \`Configuration reloaded...\`');
|
||||||
@@ -26,9 +26,9 @@ module.exports.reload = async function(message, msg, args, discordclient) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.setprefix = async function(message, msg, args, discordclient) {
|
module.exports.setprefix = function(message, msg, args, discordclient) {
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
var servers = Config.getservers()
|
let servers = Config.getservers()
|
||||||
servers[message.guild.id].prefix = args[1]
|
servers[message.guild.id].prefix = args[1]
|
||||||
Config.setservers(servers);
|
Config.setservers(servers);
|
||||||
Config.writeToFile();
|
Config.writeToFile();
|
||||||
@@ -38,6 +38,71 @@ module.exports.setprefix = async function(message, msg, args, discordclient) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.setgame = async function(message, msg, args, discordclient) {
|
module.exports.setgame = 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 = 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 + '```');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.serverconfig = async function (message, msg, args, discordclient) {
|
||||||
|
if (message.author.id == Config.getconfig().OwnerID) {//bot owners id
|
||||||
|
message.channel.send('Uploading...')
|
||||||
|
|
||||||
|
let atm = new Discord.Attachment();
|
||||||
|
atm.setAttachment('./resources/servers.json', 'Servers.json');
|
||||||
|
|
||||||
|
message.channel.send(atm);
|
||||||
|
|
||||||
|
await Helper.sleep(40);
|
||||||
|
message.channel.fetchMessages({ limit: 10 })
|
||||||
|
.then((_messages) => {
|
||||||
|
let messages = _messages.array();
|
||||||
|
let counter = 0;
|
||||||
|
for (let i = 0; i < messages.length; i++) {
|
||||||
|
if (messages[i].author.id === discordclient.user.id) {
|
||||||
|
if (counter == 0) {
|
||||||
|
counter++;
|
||||||
|
} else {
|
||||||
|
messages[i].delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch();
|
||||||
|
} else {
|
||||||
|
message.channel.send(':no_entry_sign: \`You are not authorized to issue this command\`')
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const ping = require('ping');
|
const ping = require('ping');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const qr = require('qr-image');
|
||||||
const Config = require('../config.js');
|
const Config = require('../config.js');
|
||||||
const CommandManager = require('../commandmanager.js');
|
const CommandManager = require('../commandmanager.js');
|
||||||
const Helper = require('../helper.js');
|
const Helper = require('../helper.js');
|
||||||
|
|
||||||
/*message object, messaage full, message args, discord client*/
|
/*message object, messaage full, message args, discord client*/
|
||||||
|
|
||||||
module.exports.help = async function(message, msg, args, discordclient) {
|
module.exports.help = function(message, msg, args, discordclient) {
|
||||||
var commands = CommandManager.commands;
|
let commands = CommandManager.commands;
|
||||||
|
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
if (commands[args[1].toLowerCase()]) {
|
if (commands[args[1].toLowerCase()]) {
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setTitle(commands[args[1]].name);
|
em.setTitle(commands[args[1]].name);
|
||||||
em.addField('Command:', commands[args[1]].command);
|
em.addField('Command:', commands[args[1]].command);
|
||||||
@@ -26,23 +28,50 @@ module.exports.help = async function(message, msg, args, discordclient) {
|
|||||||
message.channel.send(`:no_entry_sign: \`That command does not exist\``);
|
message.channel.send(`:no_entry_sign: \`That command does not exist\``);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(`See a full command list at http://www.plane000.co.uk`); //temporary
|
let counter = 0;
|
||||||
|
|
||||||
|
let em = new Discord.RichEmbed();
|
||||||
|
em.setColor('BLUE');
|
||||||
|
em.setTitle('All commands: (Name, Usage)');
|
||||||
|
for (i in commands) {
|
||||||
|
counter++
|
||||||
|
if (counter == 25) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
em.addField(commands[i].name + ', ' + commands[i].command, commands[i].usage);
|
||||||
|
}
|
||||||
|
message.channel.send(em);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
let em1 = new Discord.RichEmbed();
|
||||||
|
em1.setColor('BLUE');
|
||||||
|
em1.setFooter('Do `help [command]` to see more information about the specified command');
|
||||||
|
|
||||||
|
counter = 0
|
||||||
|
for (i in commands) {
|
||||||
|
counter++
|
||||||
|
if (counter >= 25) {
|
||||||
|
em1.addField(commands[i].name + ', ' + commands[i].command, commands[i].usage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message.channel.send(em1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.say = async function(message, msg, args, discordclient) {
|
module.exports.say = function(message, msg, args, discordclient) {
|
||||||
message.channel.send(msg.slice(4, msg.length));
|
message.channel.send(msg.slice(4, msg.length));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.version = async function(message, msg, args, discordclient) {
|
module.exports.version = function(message, msg, args, discordclient) {
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setTitle('Version:');
|
em.setTitle('Version:');
|
||||||
em.setDescription(Config.getconfig().Version);
|
em.setDescription(Config.getconfig().Version);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.ping = async function(message, msg, args, discordclient) {
|
module.exports.ping = function(message, msg, args, discordclient) {
|
||||||
ping.promise.probe("discordapp.com", {
|
ping.promise.probe("discordapp.com", {
|
||||||
timeout: 10
|
timeout: 10
|
||||||
}).then((output) => {
|
}).then((output) => {
|
||||||
@@ -51,26 +80,26 @@ module.exports.ping = async function(message, msg, args, discordclient) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.cat = 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';
|
let url = 'http://thecatapi.com/api/images/get?format=xml&results_per_page=1&api_key=MzA1Njcz';
|
||||||
var result = await Helper.requestPromise(url);
|
let result = await Helper.requestPromise(url);
|
||||||
var output = result.match(/<url>(.*?)<\/url>/)[1];
|
let output = result.match(/<url>(.*?)<\/url>/)[1];
|
||||||
|
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setImage(output);
|
em.setImage(output);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.dog = async function(message, msg, args, discordclient) {
|
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 {
|
try {
|
||||||
var result = await Helper.requestPromise(url);
|
let result = await Helper.requestPromise(url);
|
||||||
var output = JSON.parse(result).message;
|
let output = JSON.parse(result).messsage;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.channel.send(`:no_entry_sign: \`Somthing went wrong\``);
|
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setImage(output);
|
em.setImage(output);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
@@ -79,8 +108,8 @@ module.exports.dog = async function(message, msg, args, discordclient) {
|
|||||||
module.exports.undo = function (message, msg, args, discordclient) {
|
module.exports.undo = function (message, msg, args, discordclient) {
|
||||||
message.channel.fetchMessages({ limit: 50 })
|
message.channel.fetchMessages({ limit: 50 })
|
||||||
.then((_messages) => {
|
.then((_messages) => {
|
||||||
var messages = _messages.array();
|
let messages = _messages.array();
|
||||||
for (var i = 0; i < messages.length; i++) {
|
for (let i = 0; i < messages.length; i++) {
|
||||||
if (messages[i].author.id === discordclient.user.id) {
|
if (messages[i].author.id === discordclient.user.id) {
|
||||||
messages[i].delete();
|
messages[i].delete();
|
||||||
return;
|
return;
|
||||||
@@ -91,7 +120,86 @@ module.exports.undo = function (message, msg, args, discordclient) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.hug = function(message, msg, args, discordclient) {
|
module.exports.hug = function(message, msg, args, discordclient) {
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
|
em.setColor('BLUE');
|
||||||
em.setImage('https://cdn.discordapp.com/attachments/345580737149403146/442232811605458957/cat-instantly-hugs-plush-toy.gif');
|
em.setImage('https://cdn.discordapp.com/attachments/345580737149403146/442232811605458957/cat-instantly-hugs-plush-toy.gif');
|
||||||
messgae.channel.send(em);
|
message.channel.send(em);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.pallet = 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 = 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\`');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.is = function(message, msg, args, discordclient) {
|
||||||
|
let thonk = Math.floor(Math.random() * 3);
|
||||||
|
|
||||||
|
if (thonk == 0) {
|
||||||
|
message.channel.send('Yes');
|
||||||
|
} else if (thonk == 1) {
|
||||||
|
message.channel.send('No');
|
||||||
|
} else {
|
||||||
|
message.channel.send('Maybe');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.are = function(message, msg, args, discordclient) {
|
||||||
|
let thonk = Math.floor(Math.random() * 3);
|
||||||
|
|
||||||
|
if (thonk == 0) {
|
||||||
|
message.channel.send('Yes');
|
||||||
|
} else if (thonk == 1) {
|
||||||
|
message.channel.send('No');
|
||||||
|
} else {
|
||||||
|
message.channel.send('Maybe');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.YEET = function(message, msg, args, discordclient) {
|
||||||
|
message.channel.send('THIS BITCH IS ***__E M P T Y__***');
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.dab = function(message, msg, args, discordclient) {
|
||||||
|
let em = new Discord.RichEmbed();
|
||||||
|
em.setColor('BLUE');
|
||||||
|
em.setImage('https://steamuserimages-a.akamaihd.net/ugc/858355614967886347/020C871E91BC00FE277C7D58C3925CAA639F99B0/');
|
||||||
|
message.channel.send(em)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
const Discord = require('discord.js');
|
||||||
|
const Logger = require('../logger');
|
||||||
|
const Config = require('../config');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,51 +1,51 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const ping = require('ping');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const PImage = require('pureimage');
|
||||||
const Config = require('../config.js');
|
const Config = require('../config.js');
|
||||||
const Helper = require('../helper.js');
|
const Helper = require('../helper.js');
|
||||||
|
|
||||||
/*message object, messaage full, message args, discord client*/
|
/*message object, messaage full, message args, discord client*/
|
||||||
|
|
||||||
/*rule commands*/
|
/*rule commands*/
|
||||||
module.exports.rules = async function(message, msg, args, discordclient) {
|
module.exports.rules = function(message, msg, args, discordclient) {
|
||||||
var serverName = message.guild.name;
|
let serverName = message.guild.name;
|
||||||
var serverID = message.guild.id;
|
let serverID = message.guild.id;
|
||||||
var serversConfig = Config.getservers();
|
let serversConfig = Config.getservers();
|
||||||
var Rules = serversConfig[serverID].rules;
|
let Rules = serversConfig[serverID].rules;
|
||||||
|
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setTitle(serverName + '\'s Server Rules');
|
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]);
|
em.addField(`Rule ${i}:`, Rules[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.rule = async function(message, msg, args, discordclient) {
|
module.exports.rule = function(message, msg, args, discordclient) {
|
||||||
var serverName = message.guild.name;
|
let serverName = message.guild.name;
|
||||||
var serverID = message.guild.id;
|
let serverID = message.guild.id;
|
||||||
var serversConfig = Config.getservers();
|
let serversConfig = Config.getservers();
|
||||||
var Rules = serversConfig[serverID].rules;
|
let Rules = serversConfig[serverID].rules;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var rule = Rules[args[1]];
|
let rule = Rules[args[1]];
|
||||||
message.channel.send(`Rule ${args[1]}: ${rule}`);
|
message.channel.send(`Rule ${args[1]}: ${rule}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
|
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.addrule = async function(message, msg, args, discordclient) {
|
module.exports.addrule = function(message, msg, args, discordclient) {
|
||||||
var serverName = message.guild.name;
|
let serverName = message.guild.name;
|
||||||
var serverID = message.guild.id;
|
let serverID = message.guild.id;
|
||||||
var serversConfig = Config.getservers();
|
let serversConfig = Config.getservers();
|
||||||
var Rules = serversConfig[serverID].rules;
|
let Rules = serversConfig[serverID].rules;
|
||||||
|
|
||||||
var newRule = args[1] + ' ';
|
let newRule = args[1] + ' ';
|
||||||
for (var i = 2; i < args.length; i++) {
|
for (let i = 2; i < args.length; i++) {
|
||||||
newRule += args[i] + ' ';
|
newRule += args[i] + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,45 +58,48 @@ module.exports.addrule = async function(message, msg, args, discordclient) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setTitle('Rule successfully added!');
|
em.setTitle('Rule successfully added!');
|
||||||
em.addField(`Rule ${Rules.length - 1}:`, newRule);
|
em.addField(`Rule ${Rules.length - 1}:`, newRule);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.delrule = async function(message, msg, args, discordclient) {
|
module.exports.delrule = function(message, msg, args, discordclient) {
|
||||||
var serverName = message.guild.name;
|
if (args[1]) {
|
||||||
var serverID = message.guild.id;
|
let serverName = message.guild.name;
|
||||||
var serversConfig = Config.getservers();
|
let serverID = message.guild.id;
|
||||||
var Rules = serversConfig[serverID].rules;
|
let serversConfig = Config.getservers();
|
||||||
|
let Rules = serversConfig[serverID].rules;
|
||||||
var toDelete = args[1];
|
let toDelete = args[1];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Rules.splice(toDelete, 1);
|
Rules.splice(toDelete, 1);
|
||||||
serversConfig[serverID].rules = Rules;
|
serversConfig[serverID].rules = Rules;
|
||||||
Config.writeToFile();
|
Config.writeToFile();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
|
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``)
|
||||||
return;
|
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) {
|
module.exports.editrule = function(message, msg, args, discordclient) {
|
||||||
var serverName = message.guild.name;
|
let serverName = message.guild.name;
|
||||||
var serverID = message.guild.id;
|
let serverID = message.guild.id;
|
||||||
var serversConfig = Config.getservers();
|
let serversConfig = Config.getservers();
|
||||||
var Rules = serversConfig[serverID].rules;
|
let Rules = serversConfig[serverID].rules;
|
||||||
|
|
||||||
var newRule = args[2] + ' ';
|
let newRule = args[2] + ' ';
|
||||||
for (var i = 3; i < args.length; i++) {
|
for (let i = 3; i < args.length; i++) {
|
||||||
newRule += args[i] + ' ';
|
newRule += args[i] + ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,30 +111,65 @@ module.exports.editrule = async function(message, msg, args, discordclient) {
|
|||||||
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``);
|
message.channel.send(`:no_entry_sign: \`That is not a valid rule\``);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var em = new Discord.RichEmbed();
|
let em = new Discord.RichEmbed();
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
em.setTitle('Rule successfully edited!');
|
em.setTitle('Rule successfully edited!');
|
||||||
em.addField(`Rule ${args[1]}:`, newRule);
|
em.addField(`Rule ${args[1]}:`, newRule);
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*birthday commands*/
|
||||||
|
module.exports.addbirthday = 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 = 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 = function(message, msg, args, discordclient) {
|
||||||
|
let birthdays = Config.getservers()[message.guild.id].birthdays;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.allbirthdays = function(message, msg, args, discordclient) {
|
||||||
|
let birthdays = Config.getservers()[message.guild.id].birthdays;
|
||||||
|
}
|
||||||
|
|
||||||
/*poll commands*/
|
/*poll commands*/
|
||||||
var polls = {};
|
let polls = {};
|
||||||
|
|
||||||
module.exports.poll = async function(message, msg, args, discordclient) {
|
module.exports.poll = async function(message, msg, args, discordclient) {
|
||||||
if (args[1] == 'start') {
|
if (args[1] == 'start') {
|
||||||
|
//checks if there is even a question
|
||||||
if (args[2]) {
|
if (args[2]) {
|
||||||
|
// checks if a poll is allready running
|
||||||
if (!polls[message.guild.id]) {
|
if (!polls[message.guild.id]) {
|
||||||
|
// starts poll object
|
||||||
await startPoll(message, args);
|
await startPoll(message, args);
|
||||||
var options = '';
|
|
||||||
|
// makes output options string and removes end comma
|
||||||
|
let options = '';
|
||||||
for (i in polls[message.guild.id].options) {
|
for (i in polls[message.guild.id].options) {
|
||||||
options += polls[message.guild.id].options[i] + ', ';
|
options += polls[message.guild.id].options[i] + ', ';
|
||||||
}
|
}
|
||||||
options = options.substring(0, options.length - 2);
|
options = options.substring(0, options.length - 2);
|
||||||
|
|
||||||
var em = new Discord.RichEmbed();
|
// sends poll
|
||||||
em.setTitle('Poll started!');
|
let em = new Discord.RichEmbed();
|
||||||
|
em.setAuthor('Poll started!');
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
|
em.setTitle(polls[message.guild.id].pollq);
|
||||||
em.addField('With the options:', options)
|
em.addField('With the options:', options)
|
||||||
em.setFooter('Type \'vote [option]\' to vote for that option');
|
em.setFooter('Type \'vote [option]\' to vote for that option');
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
@@ -145,61 +183,107 @@ module.exports.poll = async function(message, msg, args, discordclient) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (args[1] == 'stop') {
|
} else if (args[1] == 'stop') {
|
||||||
|
// checks if a poll is running
|
||||||
if (polls[message.guild.id]) {
|
if (polls[message.guild.id]) {
|
||||||
|
|
||||||
var results = polls[message.guild.id].votes
|
// takes poll objects, determines option with the most votes and maps that to an object
|
||||||
.map((x, i) =>
|
let results = polls[message.guild.id].votes
|
||||||
{
|
.map((x, i) =>
|
||||||
return {
|
{
|
||||||
count: x,
|
return {
|
||||||
value: polls[message.guild.id].options[i]
|
count: x,
|
||||||
};
|
value: polls[message.guild.id].options[i]
|
||||||
}
|
};
|
||||||
)
|
}
|
||||||
.sort((a, b) => b.count - a.count)
|
)
|
||||||
.filter((x, i, arr) => x.count == arr[0].count)
|
.sort((a, b) => b.count - a.count)
|
||||||
//.map(x => x.value)
|
.filter((x, i, arr) => x.count == arr[0].count);
|
||||||
|
//.map(x => x.value)
|
||||||
|
|
||||||
var winners = '';
|
let winners = '';
|
||||||
var votesForWinners = '';
|
let votesForWinners = '';
|
||||||
|
|
||||||
for (var i = 0; i < results.length; i++) {
|
// makes winning string and adds the votes for the winners
|
||||||
winners += results[i].value + ' and ';
|
for (let i = 0; i < results.length; i++) {
|
||||||
votesForWinners = results[i].count;
|
winners += results[i].value + ' and ';
|
||||||
|
votesForWinners = results[i].count;
|
||||||
}
|
}
|
||||||
winners = winners.substring(0, winners.length - 5);
|
winners = winners.substring(0, winners.length - 5);
|
||||||
|
|
||||||
var em = new Discord.RichEmbed();
|
// sends results
|
||||||
em.setTitle('Poll Results');
|
let em = new Discord.RichEmbed();
|
||||||
|
em.setAuthor('Poll Results');
|
||||||
em.setColor('BLUE');
|
em.setColor('BLUE');
|
||||||
|
em.setTitle(polls[message.guild.id].pollq)
|
||||||
em.addField(winners + ' wins!', 'with ' + votesForWinners + ' vote(s)');
|
em.addField(winners + ' wins!', 'with ' + votesForWinners + ' vote(s)');
|
||||||
message.channel.send(em);
|
message.channel.send(em);
|
||||||
delete polls[message.guild.id];
|
delete polls[message.guild.id];
|
||||||
return;
|
return;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(':no_entry_sign: \`There are no polls running, you can type \'poll start\' to start a new poll\`');
|
message.channel.send(':no_entry_sign: \`There are no polls running, you can type \'poll start\' to start a new poll\`');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else if (args[1] == 'view') {
|
||||||
|
// checks if a poll is running
|
||||||
|
if (polls[message.guild.id]) {
|
||||||
|
|
||||||
|
// gets current poll info
|
||||||
|
let poll = polls[message.guild.id];
|
||||||
|
let q = poll.pollq;
|
||||||
|
let options = poll.options;
|
||||||
|
let votes = poll.votes;
|
||||||
|
|
||||||
|
// bracing for 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);
|
||||||
|
|
||||||
|
// sends message
|
||||||
|
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 {
|
} else {
|
||||||
message.channel.send(':no_entry_sign: \`Incorrect arguments given, try \'help poll\' for usage\`');
|
message.channel.send(':no_entry_sign: \`Incorrect arguments given, try \'help poll\' for usage\`');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.vote = async function(message, msg, args, discordclient) {
|
module.exports.vote = function(message, msg, args, discordclient) {
|
||||||
|
// checks if a poll is running
|
||||||
if (polls[message.guild.id]) {
|
if (polls[message.guild.id]) {
|
||||||
var poll = polls[message.guild.id];
|
let poll = polls[message.guild.id];
|
||||||
var hasVoted = false;
|
let hasVoted = false;
|
||||||
for (var i = 0; i < poll.voted.length; i++) {
|
for (let i = 0; i < poll.voted.length; i++) {
|
||||||
if (poll.voted[i] == message.author.id) {
|
if (poll.voted[i] == message.author.id) {
|
||||||
hasVoted = true;
|
hasVoted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!hasVoted) {
|
if (!hasVoted) {
|
||||||
var option = args.slice(1).join(" ");
|
let option = args.slice(1).join(" ");
|
||||||
var index;
|
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) {
|
if (poll.options[i] == option) {
|
||||||
index = i
|
index = i
|
||||||
poll.votes[i]++;
|
poll.votes[i]++;
|
||||||
@@ -217,7 +301,7 @@ module.exports.vote = async function(message, msg, args, discordclient) {
|
|||||||
|
|
||||||
message.channel.send(`${message.author} voted for ${option}!`);
|
message.channel.send(`${message.author} voted for ${option}!`);
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(':no_entry_sign: \`You have allready voted\`');
|
message.channel.send(':no_entry_sign: \`You have already voted\`');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(':no_entry_sign: \`There are no polls running at the moment, use \'poll start\' to start one\`');
|
message.channel.send(':no_entry_sign: \`There are no polls running at the moment, use \'poll start\' to start one\`');
|
||||||
@@ -225,9 +309,17 @@ module.exports.vote = async function(message, msg, args, discordclient) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startPoll(messageObj, args) {
|
async function startPoll(messageObj, args) {
|
||||||
var parsedOptions =args.slice(2).join(" ").match(/(\\.|[^/])+/g)
|
let parsedOptions = args.slice(2).join(" ").split("--");
|
||||||
var parsedVotes = await getStartingVotes(parsedOptions)
|
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] = {
|
polls[messageObj.guild.id] = {
|
||||||
|
pollq: pollquestion,
|
||||||
options: parsedOptions,
|
options: parsedOptions,
|
||||||
votes: parsedVotes,
|
votes: parsedVotes,
|
||||||
voted: []
|
voted: []
|
||||||
@@ -235,9 +327,180 @@ async function startPoll(messageObj, args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function getStartingVotes(options) {
|
async function getStartingVotes(options) {
|
||||||
var votes = [];
|
let votes = [];
|
||||||
for (i in options) {
|
for (i in options) {
|
||||||
votes.push('0');
|
votes.push('0');
|
||||||
}
|
}
|
||||||
return votes;
|
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;
|
||||||
|
|
||||||
|
try {
|
||||||
|
player1 = message.mentions.members.first();
|
||||||
|
} catch (e) {
|
||||||
|
message.channel.send(':no_entry_sign: \`You have not mentioned a user to play with...\`')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player1.id == message.author.id) {
|
||||||
|
message.channel.send(':no_entry_sign: \`You cannot play with yourself :(\`')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player1.id == discordclient.user.id) {
|
||||||
|
message.channel.send(':no_entry_sign: \`You cannot play with me :(\`')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await initBoard(message, message.author, player1);
|
||||||
|
let board = await drawcurrentstate(message);
|
||||||
|
|
||||||
|
message.channel.send('```' + board + '```');
|
||||||
|
message.channel.send();
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
console.log(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, channelID) {
|
||||||
|
chess[message.guild.id] = {
|
||||||
|
channel: {
|
||||||
|
id: channelID
|
||||||
|
},
|
||||||
|
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 += `│ - │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │\n`;
|
||||||
|
board += `├─-─╆━-━┿━-━┿━-━┿━-━┿━-━┿━-━┿━-━┿━-━┥\n`;
|
||||||
|
board += `| A ┃ ${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 += `| B ┃ ${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 ┃ ${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 += `| D ┃ ${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 += `| E ┃ ${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 += `| F ┃ ${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 += `| G ┃ ${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 += `| H ┃ ${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;
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupGame(guild) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function disbandGame(guild) {
|
||||||
|
|
||||||
|
}
|
||||||
130
commands/spacecommands.js
Normal file
130
commands/spacecommands.js
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
const Discord = require('discord.js');
|
||||||
|
const https = require('https');
|
||||||
|
const fs = require('fs');
|
||||||
|
const Config = require('../config.js');
|
||||||
|
const Helper = require('../helper.js');
|
||||||
|
|
||||||
|
/*message object, messaage full, message args, discord client*/
|
||||||
|
|
||||||
|
module.exports.nextlaunch = async function(message, msg, args, discordclient) {
|
||||||
|
let url = 'https://launchlibrary.net/1.4/launch/next/1';
|
||||||
|
try {
|
||||||
|
try {
|
||||||
|
let launch = JSON.parse(result).launches[0];
|
||||||
|
|
||||||
|
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;
|
||||||
|
} catch (e) {
|
||||||
|
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let result = await Helper.requestPromise(url);
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
em.addBlankField();
|
||||||
|
|
||||||
|
let rocket = launch.rocket;
|
||||||
|
let 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.addBlankField();
|
||||||
|
|
||||||
|
let location = launch.location;
|
||||||
|
let pad = location.pads[0];
|
||||||
|
|
||||||
|
em.addField('Launch Pad:', pad.name);
|
||||||
|
em.addField('Loacation Name:', location.name, true);
|
||||||
|
em.addField('Country:', location.countryCode, true);
|
||||||
|
|
||||||
|
em.addBlankField();
|
||||||
|
|
||||||
|
let mission = launch.missions[0];
|
||||||
|
let missionagency = mission.agencies[0];
|
||||||
|
let payload = mission.payloads[0];
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
} catch (e) {
|
||||||
|
message.channel.send(`:no_entry_sign: \`There was a problem with the API...\``);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = 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 = 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';
|
||||||
|
}
|
||||||
14
config.js
14
config.js
@@ -1,7 +1,7 @@
|
|||||||
const fs = require("fs");
|
const fs = require('fs');
|
||||||
|
|
||||||
var config = {};
|
let config = {};
|
||||||
var servers = {};
|
let servers = {};
|
||||||
|
|
||||||
module.exports.getconfig = function() {
|
module.exports.getconfig = function() {
|
||||||
return config;
|
return config;
|
||||||
@@ -23,6 +23,7 @@ module.exports.addServer = function(guild) {
|
|||||||
servers[guild.id] = {
|
servers[guild.id] = {
|
||||||
name: guild.name,
|
name: guild.name,
|
||||||
rules: ["Oh yeah, arrays start at 0"],
|
rules: ["Oh yeah, arrays start at 0"],
|
||||||
|
birthdays: [],
|
||||||
prefix: '+',
|
prefix: '+',
|
||||||
adminroles: []
|
adminroles: []
|
||||||
}
|
}
|
||||||
@@ -30,7 +31,11 @@ module.exports.addServer = function(guild) {
|
|||||||
|
|
||||||
module.exports.loadDefaults = function() {
|
module.exports.loadDefaults = function() {
|
||||||
config = {
|
config = {
|
||||||
Token: 'DISCORD_TOKEN',
|
Token: '[DISCORD TOKEN HERE]',
|
||||||
|
NASA_APIKey: '[NASA API KEY HERE]',
|
||||||
|
InviteLink: '[BOT INVITE LINK HERE]',
|
||||||
|
AdminLink: '[ADMIN INVITE LINK HERE]',
|
||||||
|
OwnerID: '[YOUR ID HERE]',
|
||||||
NowPlaying: 'RealLife.exe',
|
NowPlaying: 'RealLife.exe',
|
||||||
Version: '2.0.1',
|
Version: '2.0.1',
|
||||||
};
|
};
|
||||||
@@ -38,6 +43,7 @@ module.exports.loadDefaults = function() {
|
|||||||
servers['SERVER ID'] = {
|
servers['SERVER ID'] = {
|
||||||
name: 'SERVER NAME',
|
name: 'SERVER NAME',
|
||||||
rules: ['RULE 0', 'RULE 1'],
|
rules: ['RULE 0', 'RULE 1'],
|
||||||
|
birthdays: [],
|
||||||
prefix: '+',
|
prefix: '+',
|
||||||
adminroles: ['123456789101112', '123456789101112']
|
adminroles: ['123456789101112', '123456789101112']
|
||||||
};
|
};
|
||||||
|
|||||||
25
helper.js
25
helper.js
@@ -1,6 +1,5 @@
|
|||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const ping = require('ping');
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const request = require('request');
|
const request = require('request');
|
||||||
const colors = require('colors');
|
const colors = require('colors');
|
||||||
@@ -9,7 +8,7 @@ const Config = require('./config');
|
|||||||
const Commands = require('./commands/commands')
|
const Commands = require('./commands/commands')
|
||||||
const CommandManager = require('./commandmanager');
|
const CommandManager = require('./commandmanager');
|
||||||
|
|
||||||
module.exports.requestPromise = function(url) {
|
module.exports.requestPromise = async function(url) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request(url, function(error, response, body) {
|
request(url, function(error, response, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@@ -21,5 +20,25 @@ module.exports.requestPromise = function(url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.isUserAdmin = function(message) {
|
module.exports.isUserAdmin = function(message) {
|
||||||
|
if (message.author.id == Config.getconfig().OwnerID) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
message.author.roles.array.forEach(role => {
|
||||||
|
let r = role.id;
|
||||||
|
Config.getservers()[message.guild.id].adminroles.forEach((e) => {
|
||||||
|
if (r == e) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports.sleep = function(ms) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, ms);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
17
logger.js
17
logger.js
@@ -12,7 +12,7 @@ colors.setTheme({
|
|||||||
});
|
});
|
||||||
|
|
||||||
module.exports.logMSG = function(msg) {
|
module.exports.logMSG = function(msg) {
|
||||||
var time = getTime();
|
let time = getTime();
|
||||||
console.log(
|
console.log(
|
||||||
'[' + time + '] '
|
'[' + time + '] '
|
||||||
+ 'In '
|
+ 'In '
|
||||||
@@ -23,7 +23,6 @@ module.exports.logMSG = function(msg) {
|
|||||||
+ msg.author.discriminator
|
+ msg.author.discriminator
|
||||||
+ ' issued the command: '
|
+ ' issued the command: '
|
||||||
+ msg.content
|
+ msg.content
|
||||||
.input
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +31,7 @@ module.exports.logJOIN = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.log = function(msg) {
|
module.exports.log = function(msg) {
|
||||||
var time = getTime();
|
let time = getTime();
|
||||||
console.log(
|
console.log(
|
||||||
'[' + time + '] '
|
'[' + time + '] '
|
||||||
+ msg
|
+ msg
|
||||||
@@ -41,7 +40,7 @@ module.exports.log = function(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.success = function(msg) {
|
module.exports.success = function(msg) {
|
||||||
var time = getTime();
|
let time = getTime();
|
||||||
console.log(
|
console.log(
|
||||||
'[' + time + '] '
|
'[' + time + '] '
|
||||||
+ msg
|
+ msg
|
||||||
@@ -52,7 +51,7 @@ module.exports.success = function(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.failed = function(msg) {
|
module.exports.failed = function(msg) {
|
||||||
var time = getTime();
|
let time = getTime();
|
||||||
console.log(
|
console.log(
|
||||||
'[' + time + '] '
|
'[' + time + '] '
|
||||||
+ msg
|
+ msg
|
||||||
@@ -63,7 +62,7 @@ module.exports.failed = function(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports.warn = function(msg) {
|
module.exports.warn = function(msg) {
|
||||||
var time = getTime();
|
let time = getTime();
|
||||||
console.log(
|
console.log(
|
||||||
'[' + time + '] '
|
'[' + time + '] '
|
||||||
+ msg
|
+ msg
|
||||||
@@ -85,7 +84,7 @@ module.exports.welcome = function() {
|
|||||||
|___/
|
|___/
|
||||||
`.rainbow);
|
`.rainbow);
|
||||||
console.log('Invite JefferyBot to your server! '
|
console.log('Invite JefferyBot to your server! '
|
||||||
+ 'https://discordapp.com/api/oauth2/authorize?client_id=423592273151000576&permissions=506981494&scope=bot' .debug);
|
+ 'https://discordapp.com/oauth2/authorize?client_id=423592273151000576&permissions=8&scope=bot' .debug);
|
||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +95,7 @@ function pad(n, width, z) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getTime() {
|
function getTime() {
|
||||||
var t = new Date();
|
let t = new Date();
|
||||||
var time = (pad(t.getHours(), 2) + ':' + pad(t.getMinutes(), 2) + ':' + pad(t.getSeconds(), 2))
|
let time = (pad(t.getHours(), 2) + ':' + pad(t.getMinutes(), 2) + ':' + pad(t.getSeconds(), 2))
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|||||||
30
main.js
30
main.js
@@ -9,9 +9,11 @@ const Commands = require('./commands/commands')
|
|||||||
const CommandManager = require('./commandmanager');
|
const CommandManager = require('./commandmanager');
|
||||||
const Helper = require('./helper')
|
const Helper = require('./helper')
|
||||||
|
|
||||||
const client = new Discord.Client({autoReconnect:true});
|
const client = new Discord.Client({
|
||||||
Logger.welcome();
|
autoReconnect:true,
|
||||||
|
});
|
||||||
|
|
||||||
|
Logger.welcome();
|
||||||
|
|
||||||
/*checks if config exists*/
|
/*checks if config exists*/
|
||||||
if (!fs.existsSync('resources/config.json') || !fs.existsSync('resources/servers.json')) {
|
if (!fs.existsSync('resources/config.json') || !fs.existsSync('resources/servers.json')) {
|
||||||
@@ -21,8 +23,10 @@ if (!fs.existsSync('resources/config.json') || !fs.existsSync('resources/servers
|
|||||||
fs.mkdirSync('resources/');
|
fs.mkdirSync('resources/');
|
||||||
}
|
}
|
||||||
Config.loadDefaults();
|
Config.loadDefaults();
|
||||||
/*gets all current servers info*/
|
|
||||||
Config.writeToFile();
|
Config.writeToFile();
|
||||||
|
Logger.success('Config Successfully created');
|
||||||
|
Logger.log('Add your bot token to the newly created /resources/config.json to use Jeffery');
|
||||||
|
process.exit(1);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
Logger.warn(`Could not create the config: ${e.message}`);
|
Logger.warn(`Could not create the config: ${e.message}`);
|
||||||
@@ -53,12 +57,12 @@ try {
|
|||||||
Logger.failed(`Could not connect to discord: ${e.message}`)
|
Logger.failed(`Could not connect to discord: ${e.message}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*once connected*/
|
/*once connected*/
|
||||||
client.on('ready', () => {
|
client.on('ready', () => {
|
||||||
try {
|
try {
|
||||||
Logger.success('Connected to discords API');
|
Logger.success('Connected to discords API');
|
||||||
|
|
||||||
|
|
||||||
/*adds all servers not in config to config*/
|
/*adds all servers not in config to config*/
|
||||||
Logger.log('Setting up the server spesific commands...')
|
Logger.log('Setting up the server spesific commands...')
|
||||||
client.guilds.array().forEach((g) => {
|
client.guilds.array().forEach((g) => {
|
||||||
@@ -69,7 +73,6 @@ client.on('ready', () => {
|
|||||||
Config.writeToFile();
|
Config.writeToFile();
|
||||||
Logger.success('Server commands set up');
|
Logger.success('Server commands set up');
|
||||||
|
|
||||||
|
|
||||||
Logger.log('Logging in...')
|
Logger.log('Logging in...')
|
||||||
client.user.setPresence('online');
|
client.user.setPresence('online');
|
||||||
client.user.setActivity(Config.getconfig().NowPlaying);
|
client.user.setActivity(Config.getconfig().NowPlaying);
|
||||||
@@ -92,8 +95,8 @@ client.on('message', async (message) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Logger.logMSG(message);
|
Logger.logMSG(message);
|
||||||
var msg = message.content.toLowerCase().substring(Config.getservers()[message.guild.id].prefix.length);
|
let 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 args = message.content.substring(Config.getservers()[message.guild.id].prefix.length).split(' ');
|
||||||
args[0] = args[0].toLowerCase();
|
args[0] = args[0].toLowerCase();
|
||||||
|
|
||||||
/*command manager checks if command exists*/
|
/*command manager checks if command exists*/
|
||||||
@@ -124,6 +127,19 @@ client.on('guildDelete', async (guild) => {
|
|||||||
Logger.log(`JefferyBot left the \'${guild.name}\' server!`);
|
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 () {
|
client.on("disconnected", function () {
|
||||||
Logger.failed('Disconnected...')
|
Logger.failed('Disconnected...')
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|||||||
68
package-lock.json
generated
68
package-lock.json
generated
@@ -243,6 +243,11 @@
|
|||||||
"sshpk": "1.14.1"
|
"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": {
|
"is-typedarray": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||||
@@ -253,6 +258,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
|
||||||
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
|
"integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
|
||||||
},
|
},
|
||||||
|
"jpeg-js": {
|
||||||
|
"version": "0.3.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.3.4.tgz",
|
||||||
|
"integrity": "sha512-6IzjQxvnlT8UlklNmDXIJMWxijULjqGrzgqc0OG7YadZdvm7KPQ1j0ehmQQHckgEWOfgpptzcnWgESovxudpTA=="
|
||||||
|
},
|
||||||
"jsbn": {
|
"jsbn": {
|
||||||
"version": "0.1.1",
|
"version": "0.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz",
|
||||||
@@ -308,6 +318,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",
|
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz",
|
||||||
"integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM="
|
"integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM="
|
||||||
},
|
},
|
||||||
|
"opentype.js": {
|
||||||
|
"version": "0.4.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/opentype.js/-/opentype.js-0.4.11.tgz",
|
||||||
|
"integrity": "sha1-KBojkGOcwVkxyVXY1jwUp8d3K0E="
|
||||||
|
},
|
||||||
"performance-now": {
|
"performance-now": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
|
||||||
@@ -322,6 +337,11 @@
|
|||||||
"underscore": "1.9.0"
|
"underscore": "1.9.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"pngjs": {
|
||||||
|
"version": "3.3.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-3.3.3.tgz",
|
||||||
|
"integrity": "sha512-1n3Z4p3IOxArEs1VRXnZ/RXdfEniAUS9jb68g58FIXMNkPJeZd+Qh4Uq7/e0LVxAQGos1eIUrqrt4FpjdnEd+Q=="
|
||||||
|
},
|
||||||
"prism-media": {
|
"prism-media": {
|
||||||
"version": "0.0.2",
|
"version": "0.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/prism-media/-/prism-media-0.0.2.tgz",
|
||||||
@@ -332,11 +352,49 @@
|
|||||||
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz",
|
||||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4="
|
||||||
},
|
},
|
||||||
|
"pureimage": {
|
||||||
|
"version": "0.1.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/pureimage/-/pureimage-0.1.6.tgz",
|
||||||
|
"integrity": "sha512-t74leLaXyD3VGmMbcFZNWZoHqPQNX805gHYNBCrNEVRjUkDfdlopLJnDJI9QYdhWXwtNiD02coq+NB7+CryAwg==",
|
||||||
|
"requires": {
|
||||||
|
"jpeg-js": "0.3.4",
|
||||||
|
"opentype.js": "0.4.11",
|
||||||
|
"pngjs": "3.3.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"pureimage-beta": {
|
||||||
|
"version": "0.0.16",
|
||||||
|
"resolved": "https://registry.npmjs.org/pureimage-beta/-/pureimage-beta-0.0.16.tgz",
|
||||||
|
"integrity": "sha1-pWLIUmOaqbM5XbU12/c+Anc8aQo=",
|
||||||
|
"requires": {
|
||||||
|
"jpeg-js": "0.0.4",
|
||||||
|
"opentype.js": "0.4.11",
|
||||||
|
"pngjs": "0.4.0",
|
||||||
|
"richtext": "0.0.4"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"jpeg-js": {
|
||||||
|
"version": "0.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/jpeg-js/-/jpeg-js-0.0.4.tgz",
|
||||||
|
"integrity": "sha1-Bqr0fv7HrwsZJKWc1pWm0rXthw4="
|
||||||
|
},
|
||||||
|
"pngjs": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-0.4.0.tgz",
|
||||||
|
"integrity": "sha1-KUBxrcGytgv9SspNvkdZvM7m/Xc="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"q": {
|
"q": {
|
||||||
"version": "1.5.1",
|
"version": "1.5.1",
|
||||||
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
|
||||||
"integrity": "sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc="
|
"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": {
|
"qs": {
|
||||||
"version": "6.5.2",
|
"version": "6.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
|
||||||
@@ -370,11 +428,21 @@
|
|||||||
"uuid": "3.2.1"
|
"uuid": "3.2.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"richtext": {
|
||||||
|
"version": "0.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/richtext/-/richtext-0.0.4.tgz",
|
||||||
|
"integrity": "sha1-3kwKJqWE2P3JJN5aajnreEazl70="
|
||||||
|
},
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.2",
|
"version": "5.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz",
|
||||||
"integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
|
"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": {
|
"snekfetch": {
|
||||||
"version": "3.6.4",
|
"version": "3.6.4",
|
||||||
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",
|
"resolved": "https://registry.npmjs.org/snekfetch/-/snekfetch-3.6.4.tgz",
|
||||||
|
|||||||
@@ -25,7 +25,12 @@
|
|||||||
"discord.js": "^11.3.2",
|
"discord.js": "^11.3.2",
|
||||||
"fs": "0.0.1-security",
|
"fs": "0.0.1-security",
|
||||||
"http": "0.0.0",
|
"http": "0.0.0",
|
||||||
|
"https": "^1.0.0",
|
||||||
"ping": "^0.2.2",
|
"ping": "^0.2.2",
|
||||||
"request": "^2.86.0"
|
"pureimage": "^0.1.6",
|
||||||
|
"pureimage-beta": "0.0.16",
|
||||||
|
"qr-image": "^3.2.0",
|
||||||
|
"request": "^2.86.0",
|
||||||
|
"smartcar-unit": "^1.1.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user