mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-31 17:31:32 +00:00
Fixed some variables, bugfixes
This commit is contained in:
parent
0e8dbbe472
commit
01ff2d995a
5 changed files with 89 additions and 89 deletions
44
bot/bot.js
44
bot/bot.js
|
@ -11,7 +11,7 @@ const claimbot = require('./modules/claimbot.js');
|
|||
const commandsV2 = require('./modules/commandsV2.js');
|
||||
const supportbot = require('./modules/supportbot.js');
|
||||
|
||||
var aliases;
|
||||
let aliases;
|
||||
try {
|
||||
aliases = require('./alias.json');
|
||||
} catch (e) {
|
||||
|
@ -24,7 +24,7 @@ try {
|
|||
}
|
||||
};
|
||||
}
|
||||
var commands = {
|
||||
let commands = {
|
||||
ping: {
|
||||
description: 'responds pong, useful for checking if bot is alive',
|
||||
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() {
|
||||
console.log('Logged in! Serving in ' + bot.guilds.array().length + ' servers');
|
||||
|
@ -88,8 +88,8 @@ function checkMessageForCommand(msg, isEdit) {
|
|||
return;
|
||||
});
|
||||
}
|
||||
var 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 cmdTxt = msg.content.split(' ')[0].substring(config.prefix.length);
|
||||
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)) {
|
||||
try {
|
||||
cmdTxt = msg.content.split(' ')[1];
|
||||
|
@ -102,26 +102,26 @@ function checkMessageForCommand(msg, isEdit) {
|
|||
}
|
||||
let alias = aliases[cmdTxt];
|
||||
if (alias) {
|
||||
var cmd = alias;
|
||||
let cmd = alias;
|
||||
} else {
|
||||
var cmd = commands[cmdTxt];
|
||||
let cmd = commands[cmdTxt];
|
||||
|
||||
}
|
||||
if (cmdTxt === 'help') {
|
||||
//help is special since it iterates over the other commands
|
||||
if (suffix) {
|
||||
var cmds = suffix.split(' ').filter(function(cmd) {
|
||||
let cmds = suffix.split(' ').filter(function(cmd) {
|
||||
return commands[cmd];
|
||||
});
|
||||
var info = '';
|
||||
for (var i = 0; i < cmds.length; i++) {
|
||||
var cmd = cmds[i];
|
||||
let info = '';
|
||||
for (let i = 0; i < cmds.length; i++) {
|
||||
let cmd = cmds[i];
|
||||
info += '**' + config.prefix + cmd + '**';
|
||||
var usage = commands[cmd].usage;
|
||||
let usage = commands[cmd].usage;
|
||||
if (usage) {
|
||||
info += ' ' + usage;
|
||||
}
|
||||
var description = commands[cmd].description;
|
||||
let description = commands[cmd].description;
|
||||
if (description instanceof Function) {
|
||||
description = description();
|
||||
}
|
||||
|
@ -133,23 +133,23 @@ function checkMessageForCommand(msg, isEdit) {
|
|||
msg.channel.send(info);
|
||||
} else {
|
||||
msg.author.send('**Available Commands:**').then(function() {
|
||||
var batch = '';
|
||||
var sortedCommands = Object.keys(commands).sort();
|
||||
for (var i in sortedCommands) {
|
||||
var cmd = sortedCommands[i];
|
||||
var info = '**' + config.prefix + cmd + '**';
|
||||
var usage = commands[cmd].usage;
|
||||
let batch = '';
|
||||
let sortedCommands = Object.keys(commands).sort();
|
||||
for (let i in sortedCommands) {
|
||||
let cmd = sortedCommands[i];
|
||||
let info = '**' + config.prefix + cmd + '**';
|
||||
let usage = commands[cmd].usage;
|
||||
if (usage) {
|
||||
info += ' ' + usage;
|
||||
}
|
||||
var description = commands[cmd].description;
|
||||
let description = commands[cmd].description;
|
||||
if (description instanceof Function) {
|
||||
description = description();
|
||||
}
|
||||
if (description) {
|
||||
info += '\n\t' + description;
|
||||
}
|
||||
var newBatch = batch + '\n' + info;
|
||||
let newBatch = batch + '\n' + info;
|
||||
if (newBatch.length > 1024 - 8) {
|
||||
//limit message length
|
||||
msg.author.send(batch);
|
||||
|
@ -169,7 +169,7 @@ function checkMessageForCommand(msg, isEdit) {
|
|||
try {
|
||||
cmd.process(bot, msg, suffix, isEdit);
|
||||
} catch (e) {
|
||||
var msgTxt = 'command ' + cmdTxt + ' failed :(';
|
||||
let msgTxt = 'command ' + cmdTxt + ' failed :(';
|
||||
if (config.debug) {
|
||||
msgTxt += '\n' + e.stack;
|
||||
}
|
||||
|
|
|
@ -23,25 +23,25 @@ exports.altprice = {
|
|||
.filter(function(n) {
|
||||
return n !== '';
|
||||
});
|
||||
var currency1 = words[0].toUpperCase();
|
||||
let currency1 = words[0].toUpperCase();
|
||||
if (words[1] == undefined) {
|
||||
var currency2 = 'BTC';
|
||||
let currency2 = 'BTC';
|
||||
} else {
|
||||
var currency2 = words[1].toUpperCase();
|
||||
let currency2 = words[1].toUpperCase();
|
||||
}
|
||||
if (words[2] == undefined) {
|
||||
var amount = '1';
|
||||
let amount = '1';
|
||||
} else {
|
||||
if (getValidatedAmount(words[2]) === null) {
|
||||
msg.reply('Please specify a number for <amount>');
|
||||
return;
|
||||
}
|
||||
var amount = words[2].toUpperCase();
|
||||
let amount = words[2].toUpperCase();
|
||||
}
|
||||
} else {
|
||||
var currency1 = 'BTC';
|
||||
var currency2 = 'USD';
|
||||
var amount = '1';
|
||||
let currency1 = 'BTC';
|
||||
let currency2 = 'USD';
|
||||
let amount = '1';
|
||||
}
|
||||
needle.get('https://min-api.cryptocompare.com/data/all/coinlist', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
|
@ -55,9 +55,9 @@ exports.altprice = {
|
|||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var price = Number(response.body[currency2]);
|
||||
var newprice = price * amount;
|
||||
var message = amount + ' ' + currency1 + ' = ' + newprice.toFixed(8) + ' ' + currency2 + '\n' + '*Updated: ' + timestamp + '*';
|
||||
let price = Number(response.body[currency2]);
|
||||
let newprice = price * amount;
|
||||
let message = amount + ' ' + currency1 + ' = ' + newprice.toFixed(8) + ' ' + currency2 + '\n' + '*Updated: ' + timestamp + '*';
|
||||
msg.channel.send(message);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -57,7 +57,7 @@ exports.antiSpam = function(bot) {
|
|||
ban(msg, msg.author.id);
|
||||
}
|
||||
|
||||
matched = 0;
|
||||
let matched = 0;
|
||||
|
||||
for (let i = 0; i < authors.length; i++) {
|
||||
if (authors[i].time > now - interval) {
|
||||
|
|
|
@ -25,14 +25,14 @@ exports.speech = {
|
|||
return;
|
||||
}
|
||||
|
||||
var command = '!speech';
|
||||
let command = '!speech';
|
||||
words = suffix
|
||||
.trim()
|
||||
.split(' ')
|
||||
.filter(function(n) {
|
||||
return n !== '';
|
||||
});
|
||||
var imagename = words[0];
|
||||
let imagename = words[0];
|
||||
|
||||
//check if image name is help, if it is then do help message
|
||||
if (imagename == 'help') {
|
||||
|
@ -42,13 +42,13 @@ exports.speech = {
|
|||
//check if imagename is defined if not do error
|
||||
if (imagename === undefined) {
|
||||
if (FullDebug === 'true') {
|
||||
var message = '`no name provided`';
|
||||
let message = '`no name provided`';
|
||||
console.log('no name provided');
|
||||
msg.channel.send(message);
|
||||
doHelp(bot, msg, suffix);
|
||||
return;
|
||||
} else {
|
||||
var message = '`no name provided`';
|
||||
let message = '`no name provided`';
|
||||
msg.channel.send(message);
|
||||
doHelp(bot, msg, suffix);
|
||||
return;
|
||||
|
@ -56,17 +56,17 @@ exports.speech = {
|
|||
}
|
||||
|
||||
//set second word to url
|
||||
var filepath = words[1];
|
||||
let filepath = words[1];
|
||||
|
||||
//check if a url is provided if none do help message
|
||||
if (filepath === undefined) {
|
||||
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');
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
} 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);
|
||||
return;
|
||||
}
|
||||
|
@ -74,34 +74,34 @@ exports.speech = {
|
|||
|
||||
//prepare url for other uses
|
||||
//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
|
||||
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
|
||||
if (linkvalid !== 'http') {
|
||||
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);
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
} 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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//function to check if url is an image
|
||||
var isUriImage = function(uri) {
|
||||
let isUriImage = function(uri) {
|
||||
//make sure we remove any nasty GET params
|
||||
uri = uri.split('?')[0];
|
||||
//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 )
|
||||
var extension = parts[parts.length - 1];
|
||||
let extension = parts[parts.length - 1];
|
||||
//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
|
||||
if (imageTypes.indexOf(extension) !== -1) {
|
||||
return true;
|
||||
|
@ -113,18 +113,18 @@ exports.speech = {
|
|||
//check if url is an image if its not throw error and help message
|
||||
if (isUriImage(url) === false) {
|
||||
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);
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
} 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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//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
|
||||
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
|
||||
var source = url;
|
||||
let source = url;
|
||||
//parse the filename to use to save file
|
||||
filepath = source.split('/').pop();
|
||||
//set proper directory for downloading image
|
||||
var outputFile = 'speech-uploads/' + filepath;
|
||||
let outputFile = 'speech-uploads/' + filepath;
|
||||
//set download directory to current working directory
|
||||
var dir = process.cwd();
|
||||
let dir = process.cwd();
|
||||
//set full path to directory for speech uploading
|
||||
var fullpath = dir + '\\speech-uploads\\' + filepath;
|
||||
let fullpath = dir + '\\speech-uploads\\' + filepath;
|
||||
|
||||
//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
|
||||
download.on('error', function(err) {
|
||||
if (FullDebug === 'true') {
|
||||
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);
|
||||
return;
|
||||
} else {
|
||||
var message = '`error url could not be reached`';
|
||||
let message = '`error url could not be reached`';
|
||||
msg.channel.send(message);
|
||||
return;
|
||||
}
|
||||
|
@ -213,11 +213,11 @@ exports.speech = {
|
|||
if (body.message === 'no files found in request') {
|
||||
if (FullDebug === 'true') {
|
||||
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);
|
||||
return;
|
||||
} 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);
|
||||
return;
|
||||
}
|
||||
|
@ -227,18 +227,18 @@ exports.speech = {
|
|||
if (body.message === 'no name field found in request') {
|
||||
if (FullDebug === 'true') {
|
||||
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);
|
||||
return;
|
||||
} 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);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//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 + '"');
|
||||
msg.channel.send(message);
|
||||
}
|
||||
|
|
|
@ -20,23 +20,23 @@ exports.stats = {
|
|||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var rank = data.rank;
|
||||
var price_usd = Number(data.price_usd);
|
||||
var price_btc = Number(data.price_btc);
|
||||
var market_cap_usd = Number(data.market_cap_usd);
|
||||
var available_supply = Number(data.available_supply);
|
||||
var total_supply = Number(data.total_supply);
|
||||
var percent_change_1h = Number(data.percent_change_1h);
|
||||
var percent_change_24h = Number(data.percent_change_24h);
|
||||
var json = response.body[0];
|
||||
var newjson = parse_obj(json);
|
||||
var parse = JSON.stringify(newjson);
|
||||
var volume24_usd = parse.replace(/[^0-9]/g, '');
|
||||
var dt = new Date();
|
||||
var timestamp = dt.toUTCString();
|
||||
var hr_indicator = ':thumbsup:';
|
||||
var day_indicator = ':thumbsup:';
|
||||
let data = response.body[0];
|
||||
let rank = data.rank;
|
||||
let price_usd = Number(data.price_usd);
|
||||
let price_btc = Number(data.price_btc);
|
||||
let market_cap_usd = Number(data.market_cap_usd);
|
||||
let available_supply = Number(data.available_supply);
|
||||
let total_supply = Number(data.total_supply);
|
||||
let percent_change_1h = Number(data.percent_change_1h);
|
||||
let percent_change_24h = Number(data.percent_change_24h);
|
||||
let json = response.body[0];
|
||||
let newjson = parse_obj(json);
|
||||
let parse = JSON.stringify(newjson);
|
||||
let volume24_usd = parse.replace(/[^0-9]/g, '');
|
||||
let dt = new Date();
|
||||
let timestamp = dt.toUTCString();
|
||||
let hr_indicator = ':thumbsup:';
|
||||
let day_indicator = ':thumbsup:';
|
||||
if (percent_change_1h < 0) {
|
||||
hr_indicator = ':thumbsdown:';
|
||||
}
|
||||
|
@ -48,14 +48,14 @@ exports.stats = {
|
|||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_gbp = Number(data.price_gbp);
|
||||
let data = response.body[0];
|
||||
let price_gbp = Number(data.price_gbp);
|
||||
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_eur = Number(data.price_eur);
|
||||
let data = response.body[0];
|
||||
let price_eur = Number(data.price_eur);
|
||||
description =
|
||||
'**Rank: [' +
|
||||
rank +
|
||||
|
@ -139,12 +139,12 @@ exports.stats = {
|
|||
}
|
||||
});
|
||||
function parse_obj(obj) {
|
||||
var array = [];
|
||||
var prop;
|
||||
let array = [];
|
||||
let prop;
|
||||
for (prop in obj) {
|
||||
if (obj.hasOwnProperty(prop)) {
|
||||
var key = parseInt(prop, 10);
|
||||
var value = obj[prop];
|
||||
let key = parseInt(prop, 10);
|
||||
let value = obj[prop];
|
||||
if (typeof value == 'object') {
|
||||
value = parse_obj(value);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue