Merge branch 'master' into Coolguy3289-patch-3

This commit is contained in:
Ralph 2019-11-17 13:55:46 -05:00 committed by GitHub
commit fa0a916774
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 344 additions and 412 deletions

View file

@ -73,9 +73,9 @@ bot.on('error', function(error) {
function checkMessageForCommand(msg, isEdit) { function checkMessageForCommand(msg, isEdit) {
//check if message is a command //check if message is a command
if (msg.author.id != bot.user.id && msg.content.startsWith(config.prefix)) { if (msg.author.id !== bot.user.id && msg.content.startsWith(config.prefix)) {
//check if user is Online //check if user is Online
if (!msg.author.presence.status || msg.author.presence.status == 'offline' || msg.author.presence.status == 'invisible') { if (!msg.author.presence.status || msg.author.presence.status === 'offline' || msg.author.presence.status === 'invisible') {
msg.author.send('Please set your Discord Presence to Online to talk to the bot!').catch(function(error) { msg.author.send('Please set your Discord Presence to Online to talk to the bot!').catch(function(error) {
msg.channel msg.channel
.send( .send(
@ -185,7 +185,7 @@ function checkMessageForCommand(msg, isEdit) {
return; return;
} }
if (msg.author != bot.user && msg.isMentioned(bot.user)) { if (msg.author !== bot.user && msg.isMentioned(bot.user)) {
msg.channel.send('yes?'); //using a mention here can lead to looping msg.channel.send('yes?'); //using a mention here can lead to looping
} else { } else {
} }

View file

@ -6,7 +6,6 @@ let config = require('config');
let channels = config.get('claimbot').channels; let channels = config.get('claimbot').channels;
const Discord = require('discord.js'); const Discord = require('discord.js');
const request = require('request'); const request = require('request');
let lastProcessedBlock = 0;
module.exports = { module.exports = {
init: init init: init

View file

@ -14,7 +14,7 @@ exports.price = {
usage: '<currency> <amount>', usage: '<currency> <amount>',
description: 'displays price of lbc', description: 'displays price of lbc',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
var options = { let options = {
defaultCurrency: 'BTC', defaultCurrency: 'BTC',
// supported currencies and api steps to arrive at the final value // supported currencies and api steps to arrive at the final value
@ -503,22 +503,22 @@ exports.price = {
// refresh rate in milliseconds to retrieve a new price (default to 10 minutes) // refresh rate in milliseconds to retrieve a new price (default to 10 minutes)
refreshTime: 100000 refreshTime: 100000
}; };
var words = suffix let words = suffix
.trim() .trim()
.split(' ') .split(' ')
.filter(function(n) { .filter(function(n) {
return n !== ''; return n !== '';
}); });
var currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency; let currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency;
var amount = words.length > 1 ? parseFloat(words[1], 10) : 1; let amount = words.length > 1 ? parseFloat(words[1], 10) : 1;
var showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1; let showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1;
// store the last retrieved rate // store the last retrieved rate
var cachedRates = {}; let cachedRates = {};
var command = '!price'; let command = '!price';
var currencies = Object.keys(options.currencies); let currencies = Object.keys(options.currencies);
for (var i = 0; i < currencies.length; i++) { for (let i = 0; i < currencies.length; i++) {
cachedRates[currencies[i]] = { cachedRates[currencies[i]] = {
rate: 0, rate: 0,
time: null time: null
@ -539,7 +539,7 @@ exports.price = {
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.'); msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
return; return;
} }
var message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency} let message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency}
**${command} help**: this message **${command} help**: this message
**${command} CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below **${command} CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below
**${command} CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY **${command} CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY
@ -548,28 +548,28 @@ exports.price = {
} }
function formatMessage(amount, rate, option) { function formatMessage(amount, rate, option) {
var cur = option.sign; let cur = option.sign;
var value = numeral(rate.rate * amount).format(option.format); let value = numeral(rate.rate * amount).format(option.format);
return `*${numeral(amount).format('0,0[.][00000000]')} LBC = ${cur} ${value}* return `*${numeral(amount).format('0,0[.][00000000]')} LBC = ${cur} ${value}*
_last updated ${rate.time.utc().format(options.dtFormat)}_`; _last updated ${rate.time.utc().format(options.dtFormat)}_`;
} }
function doSteps(bot, currency, amount) { function doSteps(bot, currency, amount) {
var option = options.currencies[currency]; let option = options.currencies[currency];
var shouldReload = true; let shouldReload = true;
if (cachedRates[currency]) { if (cachedRates[currency]) {
var cache = cachedRates[currency]; let cache = cachedRates[currency];
shouldReload = cache.time === null || moment().diff(cache.time) >= options.refreshTime; shouldReload = cache.time === null || moment().diff(cache.time) >= options.refreshTime;
if (!shouldReload) { if (!shouldReload) {
var message = formatMessage(amount, cache, option); let message = formatMessage(amount, cache, option);
msg.channel.send(message); msg.channel.send(message);
} }
} }
if (shouldReload) { if (shouldReload) {
// copy the steps array // copy the steps array
var steps = []; let steps = [];
for (var i = 0; i < option.steps.length; i++) { for (let i = 0; i < option.steps.length; i++) {
steps.push(option.steps[i]); steps.push(option.steps[i]);
} }
@ -579,19 +579,19 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
function processSteps(bot, currency, rate, amount, steps, option) { function processSteps(bot, currency, rate, amount, steps, option) {
if (steps.length > 0) { if (steps.length > 0) {
var pairName = steps[0]; let pairName = steps[0];
if (!options.api[pairName]) { if (!options.api[pairName]) {
msg.channel.send(`There was a configuration error. ${pairName} pair was not found.`); msg.channel.send(`There was a configuration error. ${pairName} pair was not found.`);
return; return;
} }
var pair = options.api[pairName]; let pair = options.api[pairName];
request.get(pair.url, function(error, response, body) { request.get(pair.url, function(error, response, body) {
if (error) { if (error) {
msg.channel.send(err.message ? err.message : 'The request could not be completed at this time. Please try again later.'); msg.channel.send(err.message ? err.message : 'The request could not be completed at this time. Please try again later.');
return; return;
} }
var pairRate = 0; let pairRate = 0;
try { try {
pairRate = jp.query(JSON.parse(body), pair.path); pairRate = jp.query(JSON.parse(body), pair.path);
if (Array.isArray(pairRate) && pairRate.length > 0) { if (Array.isArray(pairRate) && pairRate.length > 0) {
@ -610,7 +610,7 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
} }
// final step, cache and then response // final step, cache and then response
var result = { let result = {
rate: rate, rate: rate,
time: moment() time: moment()
}; };

View file

@ -13,12 +13,13 @@ exports.purge = {
return; return;
} }
if (hasPerms(msg)) { if (hasPerms(msg)) {
let newamount = 0;
if (!suffix) { if (!suffix) {
var newamount = '2'; newamount = 2;
} else { } else {
var amount = Number(suffix); let amount = Number(suffix);
var adding = 1; let adding = 1;
var newamount = amount + adding; newamount = amount + adding;
} }
let messagecount = newamount.toString(); let messagecount = newamount.toString();
msg.channel msg.channel

View file

@ -5,167 +5,127 @@ let inPrivate = require('../helpers.js').inPrivate;
let ChannelID = config.get('gitrelease').channel; let ChannelID = config.get('gitrelease').channel;
exports.commands = [ exports.commands = [
'releasenotes' // command that is in this file, every command needs it own export as shown below 'releasenotes' // command that is in this file, every command needs it own export as shown below
]; ];
exports.releasenotes = { exports.releasenotes = {
usage: '', usage: '<desktop/android>',
description: 'gets current release notes from GITHUB', description: 'gets current release notes from GitHub, for either Desktop or Android',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
const headers = { let releaseType = suffix.toLowerCase();
'Content-Type': 'application/json', let releaseTypePost = null;
'User-Agent': 'Super Agent/0.0.1' if (releaseType === 'android post' || 'desktop post') {
}; releaseTypePost = releaseType.charAt(0).toUpperCase() + releaseType.slice(1,7);
// Configure the request console.log('Post message detected ' + releaseTypePost);
const options = {
url: 'https://api.github.com/repos/lbryio/lbry-desktop/releases/latest',
method: 'GET',
headers: headers
};
// Start the request
let message;
request(options, function(error, response, body) {
let releasemessage = JSON.parse(body).body;
let releasename = JSON.parse(body).name;
let releasedate = JSON.parse(body).published_at;
let releaseurl = JSON.parse(body).html_url;
if (releasemessage.length < 2000) {
message = {
embed: {
title: '*Download ' + releasename + ' here!*',
description: releasemessage,
url: releaseurl,
color: 7976557,
timestamp: releasedate,
author: {
name: 'LBRY Desktop release Notes for ' + releasename,
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY Desktop Updated '
}
}
};
if (inPrivate(msg)) {
msg.channel.send(message);
return;
} }
if (hasPerms(msg) && suffix === 'post') { let releaseTypeName = releaseType.charAt(0).toUpperCase() + releaseType.slice(1);
bot.channels.get(ChannelID).send(message); if (releaseType !== 'android' && releaseType !== 'desktop' && releaseType !== 'android post' && releaseType !== 'desktop post') {
msg.reply('Please specify which release notes to display: "desktop" or "android".');
return;
}
const headers = {
'Content-Type': 'application/json',
'User-Agent': 'Super Agent/0.0.1'
};
// Configure the request
let options;
if (releaseTypePost !== null) {
options = {
url: 'https://api.github.com/repos/lbryio/lbry-' + releaseTypePost + '/releases/latest',
method: 'GET',
headers: headers
};
} else { } else {
msg.channel.send(msg.author + ' Release notes sent via DM'); console.log('Release being sent: ' + releaseTypeName);
msg.author.send(message); options = {
url: 'https://api.github.com/repos/lbryio/lbry-' + releaseTypeName + '/releases/latest',
method: 'GET',
headers: headers
};
} }
} else { // Start the request
message = releasemessage let message;
.trim() request(options, function(error, response, body) {
.split('###') let json = JSON.parse(body);
.filter(function(n) { let releasemessage = json.body;
return n !== ''; console.log(releasemessage);
}); let releasename = json.name || json.tag_name;
let releasemessage1 = message[0]; let releasedate = json.published_at;
let releasemessage2 = message[1]; let releaseurl = json.html_url;
let releasemessage3 = message[2]; if (releasemessage.length < 2000) {
let releasemessage4 = message[3]; message = {
let releasemessage5 = message[4]; embed: {
let message1 = { title: '*Download ' + releasename + ' here!*',
embed: { description: releasemessage.replace('###', ''),
title: '*Download ' + releasename + ' here!*', url: releaseurl,
description: releasemessage1, color: 7976557,
url: releaseurl, timestamp: releasedate,
color: 7976557, author: {
timestamp: releasedate, name: 'LBRY ' + releaseType + ' release notes for ' + releasename,
author: { icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
name: 'LBRY Desktop Release Notes for ' + releasename, },
icon_url: 'https://spee.ch/b/Github-PNG-Image.png' footer: {
}, icon_url: 'https://spee.ch/2/pinkylbryheart.png',
footer: { text: 'LBRY ' + releaseType + ' updated '
icon_url: 'https://spee.ch/2/pinkylbryheart.png', }
text: 'LBRY Desktop Updated ' }
};
if (inPrivate(msg)) {
msg.channel.send(message);
return;
}
if (hasPerms(msg) && suffix === 'android post' || 'desktop post') {
bot.channels.get(ChannelID).send(message);
} else {
msg.channel.send(msg.author + ' Release notes sent via DM');
msg.author.send(message);
}
} else {
message = releasemessage
.trim()
.split('###')
.filter(function(n) {
return n !== '';
});
let embedmessages = [];
for (let i = 0; i < message.length; i++) {
if (message[i]) {
embedmessages.push({
embed: {
description: message[i],
url: releaseurl,
color: 7976557,
timestamp: releasedate,
author: {
name: 'LBRY ' + releaseTypeName + ' release notes for ' + releasename,
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY ' + releaseTypeName + ' updated '
}
}
});
if (i === 0) embedmessages[i].embed.title = '*Download ' + releasename + ' here!*';
}
}
if (inPrivate(msg)) {
for (let i = 0; i < embedmessages.length; i++) {
msg.channel.send(embedmessages[i]);
}
return;
}
if (hasPerms(msg) && suffix === 'android post' || 'desktop post') {
for (let i = 0; i < embedmessages.length; i++) {
bot.channels.get(ChannelID).send(embedmessages[i]);
}
} else {
msg.channel.send(msg.author + ' Release notes sent via DM');
for (let i = 0; i < embedmessages.length; i++) {
msg.author.send(embedmessages[i]);
}
}
} }
} });
}; }
let message2 = {
embed: {
description: releasemessage2,
color: 7976557,
timestamp: releasedate,
author: {
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY Desktop Updated '
}
}
};
let message3 = {
embed: {
description: releasemessage3,
color: 7976557,
timestamp: releasedate,
author: {
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY Desktop Updated '
}
}
};
let message4 = {
embed: {
description: releasemessage4,
color: 7976557,
timestamp: releasedate,
author: {
icon_url: 'https://spee.ch/b/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY Desktop Updated '
}
}
};
let message5 = {
embed: {
description: releasemessage5,
color: 7976557,
timestamp: releasedate,
author: {
icon_url: 'http://www.pngall.com/wp-content/uploads/2016/04/Github-PNG-Image.png'
},
footer: {
icon_url: 'https://spee.ch/2/pinkylbryheart.png',
text: 'LBRY Desktop Updated '
}
}
};
if (inPrivate(msg)) {
msg.channel.send(message1);
msg.channel.send(message2);
msg.channel.send(message3);
msg.channel.send(message4);
msg.channel.send(message5);
return;
}
if (hasPerms(msg) && suffix === 'post') {
bot.channels.get(ChannelID).send(message1);
bot.channels.get(ChannelID).send(message2);
bot.channels.get(ChannelID).send(message3);
bot.channels.get(ChannelID).send(message4);
bot.channels.get(ChannelID).send(message5);
} else {
msg.channel.send(msg.author + ' Release notes sent via DM');
msg.author.send(message1);
msg.author.send(message2);
msg.author.send(message3);
msg.author.send(message4);
msg.author.send(message5);
}
}
});
}
}; };

View file

@ -13,93 +13,75 @@ exports.addrole = {
usage: '<role>', usage: '<role>',
description: 'Adds you to specified role', description: 'Adds you to specified role',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
//rolelist.allowedroles = rolelist.allowedroles.map(v => v.toLowerCase()); // Provide shortened syntax for the sake of code cleanliness
// Here the bot,msg and suffix is avaible, this function can be async if needed. let send = msgTxt => msg.channel.send(msgTxt);
let newrole = msg.guild.roles.find('name', suffix); // Checks if the user has messaged the bot via Direct Message
let baserole = msg.guild.roles.find('name', rolelist.baserole); if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
// Checks if the user put a role in the message.
if (inPrivate(msg)) { // Here the bot, msg and suffix is avaible, this function can be async if needed.
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.'); // Make sure to eliminate case sensitivity, do this here to only perform the sweep once.
return; let newrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase());
} else { // Baserole is assumed to already be case accurate as it's handled in the config itself.
if (suffix) { let baserole = msg.guild.roles.find(item => item.name === rolelist.baserole);
//suffix = suffix.toLowerCase();
// Checks if the role mentioned in the message is in the allowed roles listed in the wunderbot config. let rolecmd = botconfig.prefix + 'roles';
if (rolelist.allowedroles.includes(suffix) || rolelist.baserole.includes(suffix)) {
// Checks if the role even exists in the discord server // Checks if the user included a role in their message
if (newrole !== null) { if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may add yourself!');
// Checks if the member has the role that they are trying to add // Checks if there is a matching role found on the server
if (!msg.member.roles.find('name', suffix)) { if (!newrole) return send('The role specified `' + suffix + '` does not exist on this server!');
msg.member.addRole(newrole).then(msg.channel.send(msg.member + ' has been added to the ' + suffix + ' role!')); // Checks that the allowed roles and base role against the matched role's name, since this eliminates case sensitivity issues
if (rolelist.baserole !== ' ') { if (!rolelist.allowedroles.includes(newrole.name) && !rolelist.baserole.includes(newrole.name)) return send("That role isn't one you can add yourself to! Type " + rolecmd + ' command to find out which ones are allowed.');
if (baserole !== null) { // Use the matched name to check against the member's existing roles
// Checks if Member has the baserole, and also checks if they just added the baserole if (msg.member.roles.find(item => item.name === newrole.name)) return send('It seems you already have the ' + newrole.name + 'role');
if (!msg.member.roles.find('name', rolelist.baserole) && suffix !== rolelist.baserole) {
msg.member.addRole(baserole).then(msg.channel.send(msg.member + ' has been added to the ' + rolelist.baserole + ' role!')); // Assuming all these factors succeed, add the role
} msg.member.addRole(newrole).then(send(msg.member + ' has been added to the ' + newrole.name + ' role!'));
} else {
msg.channel.send('The ' + rolelist.baserole + " Role doesn't exist. Please add that role first!"); // Check if a baserole is actually set
} if (!rolelist.baserole) return;
} // Confirm that the role exists on the server and if not then be sure to send a nag message
} else { if (!baserole) return send('The base role of ' + rolelist.baserole + ' has been set in config but is missing from the server');
msg.channel.send('It seems that you already have that role! Try removing it first with the ' + botconfig.prefix + 'delrole command!'); // Confirm if the user has the baserole already, including if it was added just now
} if (msg.member.roles.find(item => item.name === baserole.name)) return;
} else { // Add the base role and avoid spamming the user by only mentioning them in the previous message
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!'); msg.member.addRole(baserole).then(send('We also added the base ' + rolelist.baserole + ' role for you!'));
}
} else {
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
}
} else {
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
}
}
} }
}; };
exports.delrole = { exports.delrole = {
usage: '<role>', usage: '<role>',
description: 'Deletes the specified role from your account', description: 'Deletes the specified role from your account',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
// Provide shortened syntax for the sake of code cleanliness
let send = msgTxt => msg.channel.send(msgTxt);
// Checks if the user has messaged the bot via Direct Message
if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
// Here in the bot, msg and suffix are available, this function can be async if needed. // Here in the bot, msg and suffix are available, this function can be async if needed.
let oldrole = msg.guild.roles.find('name', suffix); // Make sure to eliminate case sensitivity, do this here to only perform the sweep once.
// Checks if the user put a role in the message. let oldrole = msg.guild.roles.find(role => role.name.toLowerCase() === suffix.toLowerCase());
if (inPrivate(msg)) { let rolecmd = botconfig.prefix + 'roles';
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.'); // Checks if the user included a role in their message
return; if (!suffix) return send('Please specify a role. Type ' + rolecmd + ' to see which you may remove yourself!');
} else { // Checks if there is a matching role found on the server
if (suffix) { if (!oldrole) return send('The role specified `' + suffix + '` does not exist on this server!');
// Checks if the role mentioned in the message is in the allowed roles listed in the Wunderbot config. // Checks that the allowed roles against the matched role's name, since this eliminates case sensitivity issues
if (rolelist.allowedroles.includes(suffix)) { if (!rolelist.allowedroles.includes(oldrole.name)) return send("That role isn't one you can remove yourself! If you need it removed, please ask a moderator!");
// Checks if the role exists in the Discord server // Use the matched name to check against the member's existing roles
if (oldrole !== null) { if (!msg.member.roles.find(item => item.name === oldrole.name)) return send("It seems you don't actually have the " + oldrole.name + 'role! Mission accomplished!');
// Checks if the member has the role that they are trying to add
if (msg.member.roles.find('name', suffix)) { // Assuming all these factors succeed, add the role
msg.member.removeRole(oldrole).then(msg.channel.send(msg.member + ' has been removed from the ' + suffix + ' role!')); msg.member.removeRole(oldrole).then(send(msg.member + ' has been removed from the ' + oldrole.name + ' role!'));
} else {
msg.channel.send("You don't seem to have that role! Try adding it first with the " + botconfig.prefix + 'addrole command!');
}
} else {
msg.channel.send('The role ' + '`' + suffix + '`' + ' does not exist!');
}
} else {
msg.channel.send("That role isn't one you can add yourself to! Please run the " + botconfig.prefix + 'roles command to find out which ones are allowed.');
}
} else {
msg.channel.send('Please specify a role. Type ' + botconfig.prefix + 'roles to see which you may add!');
}
}
} }
}; };
exports.roles = { exports.roles = {
usage: '', usage: '',
description: 'displays roles you can give yourself', description: 'displays roles you can give yourself',
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
if (inPrivate(msg)) { let send = msgTxt => msg.channel.send(msgTxt);
msg.channel.send('You can not set roles in DMs! Please go to the Discord server to do this.'); if (inPrivate(msg)) return send('You can not set roles in DMs! Please go to the Discord server to do this.');
return; else {
} else {
// Here in the bot, msg and suffix are available, this function can be async if needed. // Here in the bot, msg and suffix are available, this function can be async if needed.
msg.channel.send({ send({
embed: { embed: {
color: 3447003, color: 3447003,
title: 'Wunderbot', title: 'Wunderbot',
@ -132,7 +114,6 @@ exports.roles = {
} }
} }
}); });
//msg.channel.send(JSON.stringify(rolelist.allowedroles));
} }
} }
}; };

View file

@ -1,107 +1,109 @@
let needle = require('needle'); let needle = require('needle');
let statsurl = 'https://coinmarketcap.com/currencies/library-credit/'; let statsurl = 'https://www.coingecko.com/en/coins/lbry-credits';
exports.commands = [ exports.commands = [
'stats' // command that is in this file, every command needs it own export as shown below 'stats' // command that is in this file, every command needs it own export as shown below
]; ];
exports.stats = { exports.stats = {
usage: '', usage: '',
description: 'Displays list of current Market stats', description: 'Displays list of Current Market Statistics',
process: function(bot, msg) { process: function(bot, msg) {
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=BTC', function(error, response) { needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=btc&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false&price_change_percentage=24h%2C1h%2C7d', function(error, response) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coingecko API is not available');
} else { } else {
let data = response.body.data; // console.log(response);
let rank = data.rank; // console.log(response.body[0]);
let price_usd = Number(data.quotes.USD.price); let data = response.body[0];
let price_btc = Number(data.quotes.BTC.price); let rank = data.market_cap_rank;
let market_cap_usd = Number(data.quotes.USD.market_cap); let price_btc = Number(data.current_price);
let circulating_supply = Number(data.circulating_supply); let circulating_supply = Number(data.circulating_supply);
let total_supply = Number(data.total_supply); let total_supply = Number(data.total_supply);
let percent_change_1h = Number(data.quotes.USD.percent_change_1h); let percent_change_1h = Number(data.price_change_percentage_1h_in_currency);
let percent_change_24h = Number(data.quotes.USD.percent_change_24h); let percent_change_24h = Number(data.price_change_percentage_24h_in_currency);
let volume24_usd = Number(data.quotes.USD.volume_24h); let dt = new Date();
let dt = new Date(); let timestamp = dt.toUTCString();
let timestamp = dt.toUTCString(); let hr_indicator = (percent_change_1h < 0) ? ':thumbsdown:' : ':thumbsup:';
let hr_indicator = ':thumbsup:'; let day_indicator = (percent_change_24h < 0) ? ':thumbsdown:' : ':thumbsup:';
let day_indicator = ':thumbsup:';
if (percent_change_1h < 0) {
hr_indicator = ':thumbsdown:';
}
if (percent_change_24h < 0) {
day_indicator = ':thumbsdown:';
}
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=GBP', function(error, response) { needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=gbp&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coingecko API is not available');
} else { } else {
data = response.body.data; data = response.body[0];
let price_gbp = Number(data.quotes.GBP.price); let price_gbp = Number(data.current_price);
needle.get('https://api.coinmarketcap.com/v2/ticker/1298/?convert=EUR', function(error, response) { needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=eur&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send('coingecko API is not available');
} else { } else {
data = response.body.data; data = response.body[0];
let price_eur = Number(data.quotes.EUR.price); let price_eur = Number(data.current_price);
let description = `**Rank: [${rank}](${statsurl})** needle.get('https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=lbry-credits&order=market_cap_desc&per_page=100&page=1&sparkline=false', function (error, response) {
**Data** if (error || response.statusCode !== 200) {
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl}) msg.channel.send('coingecko API is not available');
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl}) } else {
Circulating Supply: [${numberWithCommas(circulating_supply)} LBC](${statsurl}) data = response.body[0];
24 Hour Volume: [$${volume24_usd}](${statsurl}) let price_usd = Number(data.current_price);
let market_cap_usd = Number(data.market_cap);
let volume24_usd = Number(data.total_volume);
let description = `**Rank: [${rank}](${statsurl})**
**Data**
Market Cap: [$${numberWithCommas(market_cap_usd)}](${statsurl})
Total Supply: [${numberWithCommas(total_supply)} LBC](${statsurl})
Circulating Supply: [${numberWithCommas(circulating_supply.toFixed(0))} LBC](${statsurl})
24 Hour Volume: [$${numberWithCommas(volume24_usd)}](${statsurl})
**Price**
BTC: [${price_btc.toFixed(8)}](${statsurl})
USD: [$${price_usd.toFixed(5)}](${statsurl})
EUR: [${price_eur.toFixed(5)}](${statsurl})
GBP: [£${price_gbp.toFixed(5)}](${statsurl})
**% Change**
1 Hour: [${percent_change_1h.toFixed(2)}%](${statsurl}) ${hr_indicator}
1 Day: [${percent_change_24h.toFixed(2)}%](${statsurl}) ${day_indicator}`;
const embed = {
description: description,
color: 7976557,
footer: {
text: 'Last Updated: ' + timestamp
},
author: {
name: 'Coin Gecko Stats (LBC)',
url: statsurl,
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
}
};
msg.channel.send({embed});
}
});
}
});
}
});
**Price** function parse_obj(obj) {
BTC: [${price_btc.toFixed(8)}](${statsurl}) let array = [];
USD: [$${price_usd.toFixed(2)}](${statsurl}) let prop;
EUR: [${price_eur.toFixed(2)}](${statsurl}) for (prop in obj) {
GBP: [£${price_gbp.toFixed(2)}](${statsurl}) if (obj.hasOwnProperty(prop)) {
let key = parseInt(prop, 10);
let value = obj[prop];
if (typeof value == 'object') {
value = parse_obj(value);
}
array[key] = value;
}
}
return array;
}
**% Change** function numberWithCommas(x) {
1 Hour: [${percent_change_1h}](${statsurl}) ${hr_indicator} return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
1 Day: [${percent_change_24h}](${statsurl}) ${day_indicator} }
})
`;
const embed = {
description: description,
color: 7976557,
footer: {
text: 'Last Updated: ' + timestamp
},
author: {
name: 'Coin Market Cap Stats (LBC)',
url: statsurl,
icon_url: 'https://spee.ch/2/pinkylbryheart.png'
}
};
msg.channel.send({ embed });
}
});
}
});
}
});
function parse_obj(obj) {
let array = [];
let prop;
for (prop in obj) {
if (obj.hasOwnProperty(prop)) {
let key = parseInt(prop, 10);
let value = obj[prop];
if (typeof value == 'object') {
value = parse_obj(value);
}
array[key] = value;
}
}
return array;
} }
}
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
}
}
};

View file

@ -30,6 +30,22 @@
"icon_url": "https://spee.ch/2/pinkylbryheart.png" "icon_url": "https://spee.ch/2/pinkylbryheart.png"
} }
} }
},
"!whitepaper": {
"usage": "",
"description": "LBRY White Paper",
"operation": "send",
"bundle": {
"url": "https://spec.lbry.com/",
"title": "",
"description": "The [LBRY White Paper](https://spec.lbry.com/) defines the LBRY protocol, its components, and how they fit together. \nThis document assumes that the reader is familiar with distributed hash tables (DHTs), the BitTorrent protocol, Bitcoin, and blockchain technology in general. It does not attempt to document these technologies or explain how they work.",
"color": 16777215,
"author": {
"name": "LBRY White Paper",
"url": "https://spec.lbry.com/",
"icon_url": "https://spee.ch/0/info-white.png"
}
}
}, },
"!begging": { "!begging": {
"usage": "", "usage": "",
@ -39,11 +55,11 @@
"url": "", "url": "",
"title": "", "title": "",
"description": "Please don't request free coins or invites, we have a strict policy against begging. Further offenses will result in removal from the chat.", "description": "Please don't request free coins or invites, we have a strict policy against begging. Further offenses will result in removal from the chat.",
"color": 7976557, "color": 16718635,
"author": { "author": {
"name": "BEGGING!", "name": "BEGGING!",
"url": "", "url": "",
"icon_url": "https://spee.ch/7/LBRY-Discord-Warning.png" "icon_url": "https://spee.ch/8/caution-red.png"
} }
} }
}, },
@ -263,11 +279,11 @@
"url": "", "url": "",
"title": "", "title": "",
"description": "Please keep conversations on topic, or move random conversations to #random if you wish to continue", "description": "Please keep conversations on topic, or move random conversations to #random if you wish to continue",
"color": 7976557, "color": 16764237,
"author": { "author": {
"name": "Random", "name": "Random",
"url": "", "url": "",
"icon_url": "https://spee.ch/7/LBRY-Discord-Warning.png" "icon_url": "https://spee.ch/3/question-orange.png"
} }
} }
}, },
@ -383,22 +399,6 @@
} }
} }
}, },
"!rewardsapprove": {
"usage": "",
"description": "How to become Rewards approved",
"operation": "send",
"bundle": {
"url": "",
"title": "",
"description": "Please download the latest version from [HERE](https://lbry.com/get) Upon install, you'll be greeted with a welcome message. If you already had the app installed, please go to the wallet (bank icon in the top right) > Rewards - This should show your current status. New users will need to get their rewards approved in order to access Rewards. Type !cc or see the !rewardsapproval information below.",
"color": 7976557,
"author": {
"name": "How to become Rewards approved",
"url": "",
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
}
}
},
"!verify": { "!verify": {
"usage": "", "usage": "",
"description": "How to become Rewards approved", "description": "How to become Rewards approved",
@ -431,22 +431,6 @@
} }
} }
}, },
"!verification": {
"usage": "",
"description": "Rewards Approval Help Message",
"operation": "send",
"bundle": {
"url": "",
"title": "",
"description": "If you would like to be approved for rewards, please go to <#571001864271691805> and send a Direct Message to @RewardsBot#0287 \n You can do this by right clicking on the name, and selecting Message. . A LBRY mod will get back to you as soon as possible. We appreciate your patience. Only one account per household is allowed access to LBRY Rewards. Check out our [Rewards FAQ](https://lbry.io/faq/rewards) to know more about rewards.",
"color": 7976557,
"author": {
"name": "Applying for Rewards Approval",
"url": "",
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
}
}
},
"!logfile": { "!logfile": {
"usage": "", "usage": "",
"description": "How to Find LBRY App Log File?", "description": "How to Find LBRY App Log File?",
@ -913,7 +897,22 @@
} }
} }
}, },
"!why": {
"usage": "",
"description": "Why should I use LBRY?",
"operation": "send",
"bundle": {
"url": "",
"title": "",
"description": "LBRY is a new protocol which allows anyone to build apps that interact with digital content on the LBRY network. Apps built on the protocol allow creators to upload their work to the LBRY network of hosts (like BitTorrent), and set a price per stream or download (like iTunes) or give it away for free (like YouTube without ads). It benefits the consumer, because there's no ads, and you can often buy things cheaper on LBRY, and it benefits the creator, because there's no risk of demonetization, essentially no fees, and it's a lot harder to censor. You can find out more on the [FAQ](https://lbry.com/faq), or ask anyone here for their experience!",
"color": 7976557,
"author": {
"name": "Why should I use LBRY?",
"url": "https://lbry.com/faq",
"icon_url": "https://spee.ch/2/pinkylbryheart.png"
}
}
},
"!piratebay": { "!piratebay": {
"usage": "", "usage": "",
"description": "Why LBRY has piratebay.com", "description": "Why LBRY has piratebay.com",

View file

@ -55,7 +55,7 @@
}, },
"rolelist": { "rolelist": {
"baserole": "LBRYian", "baserole": "LBRYian",
"allowedroles": ["NSFW", "Traders", "Miners", "Off-Topic Chats", "International", "Dev"] "allowedroles": ["Off-Topic Chats", "Dev"]
}, },
"irc": { "irc": {
"enabled": false, "enabled": false,

24
package-lock.json generated
View file

@ -2599,9 +2599,9 @@
"integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
}, },
"mixin-deep": { "mixin-deep": {
"version": "1.3.1", "version": "1.3.2",
"resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.1.tgz", "resolved": "https://registry.npmjs.org/mixin-deep/-/mixin-deep-1.3.2.tgz",
"integrity": "sha512-8ZItLHeEgaqEvd5lYBXfm4EZSFCX29Jb9K+lAHhDKzReKBQKj3R+7NOF6tjqYi9t4oI8VUfaWITJQm86wnXGNQ==", "integrity": "sha512-WRoDn//mXBiJ1H40rqa3vH0toePwSsGb45iInWlTySa+Uu4k3tYUSxa2v1KqAiLtvlrSzaExqS1gtk96A9zvEA==",
"optional": true, "optional": true,
"requires": { "requires": {
"for-in": "^1.0.2", "for-in": "^1.0.2",
@ -2633,23 +2633,13 @@
"integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg==" "integrity": "sha512-bV7f+6l2QigeBBZSM/6yTNq4P2fNpSWj/0e7jQcy87A8e7o2nAfP/34/2ky5Vw4B9S446EtIhodAzkFCcR4dQg=="
}, },
"mongodb": { "mongodb": {
"version": "3.2.7", "version": "3.3.2",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.2.7.tgz", "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.3.2.tgz",
"integrity": "sha512-2YdWrdf1PJgxcCrT1tWoL6nHuk6hCxhddAAaEh8QJL231ci4+P9FLyqopbTm2Z2sAU6mhCri+wd9r1hOcHdoMw==", "integrity": "sha512-fqJt3iywelk4yKu/lfwQg163Bjpo5zDKhXiohycvon4iQHbrfflSAz9AIlRE6496Pm/dQKQK5bMigdVo2s6gBg==",
"requires": {
"mongodb-core": "3.2.7",
"safe-buffer": "^5.1.2"
}
},
"mongodb-core": {
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.7.tgz",
"integrity": "sha512-WypKdLxFNPOH/Jy6i9z47IjG2wIldA54iDZBmHMINcgKOUcWJh8og+Wix76oGd7EyYkHJKssQ2FAOw5Su/n4XQ==",
"requires": { "requires": {
"bson": "^1.1.1", "bson": "^1.1.1",
"require_optional": "^1.0.1", "require_optional": "^1.0.1",
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2"
"saslprep": "^1.0.0"
} }
}, },
"mongoose": { "mongoose": {