Merge pull request #175 from lbryio/bugfix-vars

Fixed some variables, bugfixes
This commit is contained in:
filipnyquist 2018-05-30 18:22:22 +02:00 committed by GitHub
commit a79c839fca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 89 deletions

View file

@ -11,7 +11,7 @@ const claimbot = require('./modules/claimbot.js');
const commandsV2 = require('./modules/commandsV2.js'); const commandsV2 = require('./modules/commandsV2.js');
const supportbot = require('./modules/supportbot.js'); const supportbot = require('./modules/supportbot.js');
var aliases; let aliases;
try { try {
aliases = require('./alias.json'); aliases = require('./alias.json');
} catch (e) { } catch (e) {
@ -24,7 +24,7 @@ try {
} }
}; };
} }
var commands = { let commands = {
ping: { ping: {
description: 'responds pong, useful for checking if bot is alive', description: 'responds pong, useful for checking if bot is alive',
process: async function(bot, msg, suffix) { process: async function(bot, msg, suffix) {
@ -37,7 +37,7 @@ var commands = {
} }
}; };
var bot = new Discord.Client(); let bot = new Discord.Client();
bot.on('ready', function() { bot.on('ready', function() {
console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers'); console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers');
@ -88,8 +88,8 @@ function checkMessageForCommand(msg, isEdit) {
return; return;
}); });
} }
var cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length); let cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length);
var suffix = msg.content.substring(cmdTxt.length + config.prefix.length + 1); //add one for the ! and one for the space let suffix = msg.content.substring(cmdTxt.length + config.prefix.length + 1); //add one for the ! and one for the space
if (msg.isMentioned(bot.user)) { if (msg.isMentioned(bot.user)) {
try { try {
cmdTxt = msg.content.split(' ')[1]; cmdTxt = msg.content.split(' ')[1];
@ -102,26 +102,26 @@ function checkMessageForCommand(msg, isEdit) {
} }
let alias = aliases[cmdTxt]; let alias = aliases[cmdTxt];
if (alias) { if (alias) {
var cmd = alias; let cmd = alias;
} else { } else {
var cmd = commands[cmdTxt]; let cmd = commands[cmdTxt];
} }
if (cmdTxt === 'help') { if (cmdTxt === 'help') {
//help is special since it iterates over the other commands //help is special since it iterates over the other commands
if (suffix) { if (suffix) {
var cmds = suffix.split(' ').filter(function(cmd) { let cmds = suffix.split(' ').filter(function(cmd) {
return commands[cmd]; return commands[cmd];
}); });
var info = ''; let info = '';
for (var i = 0; i < cmds.length; i++) { for (let i = 0; i < cmds.length; i++) {
var cmd = cmds[i]; let cmd = cmds[i];
info += '**' + config.prefix + cmd + '**'; info += '**' + config.prefix + cmd + '**';
var usage = commands[cmd].usage; let usage = commands[cmd].usage;
if (usage) { if (usage) {
info += ' ' + usage; info += ' ' + usage;
} }
var description = commands[cmd].description; let description = commands[cmd].description;
if (description instanceof Function) { if (description instanceof Function) {
description = description(); description = description();
} }
@ -133,23 +133,23 @@ function checkMessageForCommand(msg, isEdit) {
msg.channel.send(info); msg.channel.send(info);
} else { } else {
msg.author.send('**Available Commands:**').then(function() { msg.author.send('**Available Commands:**').then(function() {
var batch = ''; let batch = '';
var sortedCommands = Object.keys(commands).sort(); let sortedCommands = Object.keys(commands).sort();
for (var i in sortedCommands) { for (let i in sortedCommands) {
var cmd = sortedCommands[i]; let cmd = sortedCommands[i];
var info = '**' + config.prefix + cmd + '**'; let info = '**' + config.prefix + cmd + '**';
var usage = commands[cmd].usage; let usage = commands[cmd].usage;
if (usage) { if (usage) {
info += ' ' + usage; info += ' ' + usage;
} }
var description = commands[cmd].description; let description = commands[cmd].description;
if (description instanceof Function) { if (description instanceof Function) {
description = description(); description = description();
} }
if (description) { if (description) {
info += '\n\t' + description; info += '\n\t' + description;
} }
var newBatch = batch + '\n' + info; let newBatch = batch + '\n' + info;
if (newBatch.length > 1024 - 8) { if (newBatch.length > 1024 - 8) {
//limit message length //limit message length
msg.author.send(batch); msg.author.send(batch);
@ -169,7 +169,7 @@ function checkMessageForCommand(msg, isEdit) {
try { try {
cmd.process(bot, msg, suffix, isEdit); cmd.process(bot, msg, suffix, isEdit);
} catch (e) { } catch (e) {
var msgTxt = 'command ' + cmdTxt + ' failed :('; let msgTxt = 'command ' + cmdTxt + ' failed :(';
if (config.debug) { if (config.debug) {
msgTxt += '\n' + e.stack; msgTxt += '\n' + e.stack;
} }

View file

@ -23,25 +23,25 @@ exports.altprice = {
.filter(function(n) { .filter(function(n) {
return n !== ''; return n !== '';
}); });
var currency1 = words[0].toUpperCase(); let currency1 = words[0].toUpperCase();
if (words[1] == undefined) { if (words[1] == undefined) {
var currency2 = 'BTC'; let currency2 = 'BTC';
} else { } else {
var currency2 = words[1].toUpperCase(); let currency2 = words[1].toUpperCase();
} }
if (words[2] == undefined) { if (words[2] == undefined) {
var amount = '1'; let amount = '1';
} else { } else {
if (getValidatedAmount(words[2]) === null) { if (getValidatedAmount(words[2]) === null) {
msg.reply('Please specify a number for <amount>'); msg.reply('Please specify a number for <amount>');
return; return;
} }
var amount = words[2].toUpperCase(); let amount = words[2].toUpperCase();
} }
} else { } else {
var currency1 = 'BTC'; let currency1 = 'BTC';
var currency2 = 'USD'; let currency2 = 'USD';
var amount = '1'; let amount = '1';
} }
needle.get('https://min-api.cryptocompare.com/data/all/coinlist', function(error, response) { needle.get('https://min-api.cryptocompare.com/data/all/coinlist', function(error, response) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
@ -55,9 +55,9 @@ exports.altprice = {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coinmarketcap API is not available');
} else { } else {
var price = Number(response.body[currency2]); let price = Number(response.body[currency2]);
var newprice = price * amount; let newprice = price * amount;
var message = amount + ' ' + currency1 + ' = ' + newprice.toFixed(8) + ' ' + currency2 + '\n' + '*Updated: ' + timestamp + '*'; let message = amount + ' ' + currency1 + ' = ' + newprice.toFixed(8) + ' ' + currency2 + '\n' + '*Updated: ' + timestamp + '*';
msg.channel.send(message); msg.channel.send(message);
} }
}); });

View file

@ -57,7 +57,7 @@ exports.antiSpam = function(bot) {
ban(msg, msg.author.id); ban(msg, msg.author.id);
} }
matched = 0; let matched = 0;
for (let i = 0; i < authors.length; i++) { for (let i = 0; i < authors.length; i++) {
if (authors[i].time > now - interval) { if (authors[i].time > now - interval) {

View file

@ -25,14 +25,14 @@ exports.speech = {
return; return;
} }
var command = '!speech'; let command = '!speech';
words = suffix words = suffix
.trim() .trim()
.split(' ') .split(' ')
.filter(function(n) { .filter(function(n) {
return n !== ''; return n !== '';
}); });
var imagename = words[0]; let imagename = words[0];
//check if image name is help, if it is then do help message //check if image name is help, if it is then do help message
if (imagename == 'help') { if (imagename == 'help') {
@ -42,13 +42,13 @@ exports.speech = {
//check if imagename is defined if not do error //check if imagename is defined if not do error
if (imagename === undefined) { if (imagename === undefined) {
if (FullDebug === 'true') { if (FullDebug === 'true') {
var message = '`no name provided`'; let message = '`no name provided`';
console.log('no name provided'); console.log('no name provided');
msg.channel.send(message); msg.channel.send(message);
doHelp(bot, msg, suffix); doHelp(bot, msg, suffix);
return; return;
} else { } else {
var message = '`no name provided`'; let message = '`no name provided`';
msg.channel.send(message); msg.channel.send(message);
doHelp(bot, msg, suffix); doHelp(bot, msg, suffix);
return; return;
@ -56,17 +56,17 @@ exports.speech = {
} }
//set second word to url //set second word to url
var filepath = words[1]; let filepath = words[1];
//check if a url is provided if none do help message //check if a url is provided if none do help message
if (filepath === undefined) { if (filepath === undefined) {
if (FullDebug === 'true') { if (FullDebug === 'true') {
var message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename; let message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename;
console.log('no url provided'); console.log('no url provided');
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename; let message = '`no url provided, fetching image from:`\n' + 'https://spee.ch/' + imagename;
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
@ -74,34 +74,34 @@ exports.speech = {
//prepare url for other uses //prepare url for other uses
//we will just set filepath to url to be safe //we will just set filepath to url to be safe
var url = filepath; let url = filepath;
//parse first 4 letters of url should be http //parse first 4 letters of url should be http
var linkvalid = url.slice(0, 4); let linkvalid = url.slice(0, 4);
//check of url provided begins with http in not throw error and help message //check of url provided begins with http in not throw error and help message
if (linkvalid !== 'http') { if (linkvalid !== 'http') {
if (FullDebug === 'true') { if (FullDebug === 'true') {
var message = '`error not a valid url, please start with http or https`'; let message = '`error not a valid url, please start with http or https`';
console.log('invalid url provided: ' + filepath); console.log('invalid url provided: ' + filepath);
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`error not a valid url, please start with http or https`'; let message = '`error not a valid url, please start with http or https`';
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
} }
//function to check if url is an image //function to check if url is an image
var isUriImage = function(uri) { let isUriImage = function(uri) {
//make sure we remove any nasty GET params //make sure we remove any nasty GET params
uri = uri.split('?')[0]; uri = uri.split('?')[0];
//moving on, split the uri into parts that had dots before them //moving on, split the uri into parts that had dots before them
var parts = uri.split('.'); let parts = uri.split('.');
//get the last part ( should be the extension ) //get the last part ( should be the extension )
var extension = parts[parts.length - 1]; let extension = parts[parts.length - 1];
//define some image types to test against //define some image types to test against
var imageTypes = ['jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp']; let imageTypes = ['jpg', 'jpeg', 'tiff', 'png', 'gif', 'bmp'];
//check if the extension matches anything in the list. if it does set true if not set false //check if the extension matches anything in the list. if it does set true if not set false
if (imageTypes.indexOf(extension) !== -1) { if (imageTypes.indexOf(extension) !== -1) {
return true; return true;
@ -113,18 +113,18 @@ exports.speech = {
//check if url is an image if its not throw error and help message //check if url is an image if its not throw error and help message
if (isUriImage(url) === false) { if (isUriImage(url) === false) {
if (FullDebug === 'true') { if (FullDebug === 'true') {
var message = '`error not a valid image url, be sure the link includes a file type`'; let message = '`error not a valid image url, be sure the link includes a file type`';
console.log('invalid url provided: ' + url); console.log('invalid url provided: ' + url);
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`error not a valid image url, be sure the link includes a file type`'; let message = '`error not a valid image url, be sure the link includes a file type`';
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
} }
//set third word to nsfw, with it being an optional functionality //set third word to nsfw, with it being an optional functionality
var eighteen = words[2]; let eighteen = words[2];
//check is NSFW if yes or no sets proper value if none //check is NSFW if yes or no sets proper value if none
if (eighteen == '' || eighteen == 'none' || eighteen == undefined || eighteen == null || eighteen == 'no' || eighteen == 'false' || eighteen == false || eighteen == 'n') { if (eighteen == '' || eighteen == 'none' || eighteen == undefined || eighteen == null || eighteen == 'no' || eighteen == 'false' || eighteen == false || eighteen == 'n') {
@ -134,27 +134,27 @@ exports.speech = {
} }
//prepare url for wget //prepare url for wget
var source = url; let source = url;
//parse the filename to use to save file //parse the filename to use to save file
filepath = source.split('/').pop(); filepath = source.split('/').pop();
//set proper directory for downloading image //set proper directory for downloading image
var outputFile = 'speech-uploads/' + filepath; let outputFile = 'speech-uploads/' + filepath;
//set download directory to current working directory //set download directory to current working directory
var dir = process.cwd(); let dir = process.cwd();
//set full path to directory for speech uploading //set full path to directory for speech uploading
var fullpath = dir + '\\speech-uploads\\' + filepath; let fullpath = dir + '\\speech-uploads\\' + filepath;
//download url via wget //download url via wget
var download = wget.download(url, outputFile); let download = wget.download(url, outputFile);
//check if url is reachable if not throw error //check if url is reachable if not throw error
download.on('error', function(err) { download.on('error', function(err) {
if (FullDebug === 'true') { if (FullDebug === 'true') {
console.log('error could not reach: ' + url + ' : ' + err); console.log('error could not reach: ' + url + ' : ' + err);
var message = '`error url could not be reached`'; let message = '`error url could not be reached`';
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`error url could not be reached`'; let message = '`error url could not be reached`';
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
@ -213,11 +213,11 @@ exports.speech = {
if (body.message === 'no files found in request') { if (body.message === 'no files found in request') {
if (FullDebug === 'true') { if (FullDebug === 'true') {
console.log('no file found: ' + fullpath); console.log('no file found: ' + fullpath);
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
@ -227,18 +227,18 @@ exports.speech = {
if (body.message === 'no name field found in request') { if (body.message === 'no name field found in request') {
if (FullDebug === 'true') { if (FullDebug === 'true') {
console.log('no name field found: ' + imagename); console.log('no name field found: ' + imagename);
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message); msg.channel.send(message);
return; return;
} else { } else {
var message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists'; let message = '`Failed to upload file internally!!`\n please contact <@244245498746241025> or another moderator if the issue persists';
msg.channel.send(message); msg.channel.send(message);
return; return;
} }
} }
//if no errors post this message //if no errors post this message
var message = 'uploading... \n "name":"' + imagename + '",\n "URL": "' + url + '",\n "nsfw":"' + eighteen + '"\n to spee.ch'; let message = 'uploading... \n "name":"' + imagename + '",\n "URL": "' + url + '",\n "nsfw":"' + eighteen + '"\n to spee.ch';
console.log('uploading... \n "name":"' + imagename + '",\n "file name": "' + filepath + '",\n "url":"' + url + '"\n "path":"' + fullpath + '"\n "nsfw": "' + eighteen + '"'); console.log('uploading... \n "name":"' + imagename + '",\n "file name": "' + filepath + '",\n "url":"' + url + '"\n "path":"' + fullpath + '"\n "nsfw": "' + eighteen + '"');
msg.channel.send(message); msg.channel.send(message);
} }

View file

@ -20,23 +20,23 @@ exports.stats = {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coinmarketcap API is not available');
} else { } else {
var data = response.body[0]; let data = response.body[0];
var rank = data.rank; let rank = data.rank;
var price_usd = Number(data.price_usd); let price_usd = Number(data.price_usd);
var price_btc = Number(data.price_btc); let price_btc = Number(data.price_btc);
var market_cap_usd = Number(data.market_cap_usd); let market_cap_usd = Number(data.market_cap_usd);
var available_supply = Number(data.available_supply); let available_supply = Number(data.available_supply);
var total_supply = Number(data.total_supply); let total_supply = Number(data.total_supply);
var percent_change_1h = Number(data.percent_change_1h); let percent_change_1h = Number(data.percent_change_1h);
var percent_change_24h = Number(data.percent_change_24h); let percent_change_24h = Number(data.percent_change_24h);
var json = response.body[0]; let json = response.body[0];
var newjson = parse_obj(json); let newjson = parse_obj(json);
var parse = JSON.stringify(newjson); let parse = JSON.stringify(newjson);
var volume24_usd = parse.replace(/[^0-9]/g, ''); let volume24_usd = parse.replace(/[^0-9]/g, '');
var dt = new Date(); let dt = new Date();
var timestamp = dt.toUTCString(); let timestamp = dt.toUTCString();
var hr_indicator = ':thumbsup:'; let hr_indicator = ':thumbsup:';
var day_indicator = ':thumbsup:'; let day_indicator = ':thumbsup:';
if (percent_change_1h < 0) { if (percent_change_1h < 0) {
hr_indicator = ':thumbsdown:'; hr_indicator = ':thumbsdown:';
} }
@ -48,14 +48,14 @@ exports.stats = {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coinmarketcap API is not available');
} else { } else {
var data = response.body[0]; let data = response.body[0];
var price_gbp = Number(data.price_gbp); let price_gbp = Number(data.price_gbp);
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR', function(error, response) { needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR', function(error, response) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coinmarketcap API is not available');
} else { } else {
var data = response.body[0]; let data = response.body[0];
var price_eur = Number(data.price_eur); let price_eur = Number(data.price_eur);
description = description =
'**Rank: [' + '**Rank: [' +
rank + rank +
@ -139,12 +139,12 @@ exports.stats = {
} }
}); });
function parse_obj(obj) { function parse_obj(obj) {
var array = []; let array = [];
var prop; let prop;
for (prop in obj) { for (prop in obj) {
if (obj.hasOwnProperty(prop)) { if (obj.hasOwnProperty(prop)) {
var key = parseInt(prop, 10); let key = parseInt(prop, 10);
var value = obj[prop]; let value = obj[prop];
if (typeof value == 'object') { if (typeof value == 'object') {
value = parse_obj(value); value = parse_obj(value);
} }