prettified code once and for all

This commit is contained in:
Niko Storni 2017-11-17 22:47:17 +01:00
parent b5d144111e
commit 6fff099a62
8 changed files with 874 additions and 532 deletions

View file

@ -4,11 +4,13 @@
## Features: ## Features:
* Price bot displays price of lbc for currency given. Responds to `!price <cur> <amount>` * Price bot displays price of lbc for currency given. Responds to `!price <cur>
<amount>`
* Stats bot display current market stats of lbc. Responds to `!stats` * Stats bot display current market stats of lbc. Responds to `!stats`
* Hash bot displays current hashrate of network. Responds to `!hash` * Hash bot displays current hashrate of network. Responds to `!hash`
Also Includes `!hash power <MH/s>` to calculate given MH/s to LBC per hr, day, week, month. Also Includes `!hash power <MH/s>` to calculate given MH/s to LBC per hr, day,
week, month.
* Github Release Notes bot displays release notes for current lbry-app release. * Github Release Notes bot displays release notes for current lbry-app release.
@ -16,7 +18,8 @@
(moderator only) `!releasenotes post` to send to specified channel (moderator only) `!releasenotes post` to send to specified channel
* Purge Bot (moderator only) deletes X amount of messages. Responds to `!purge <X>` * Purge Bot (moderator only) deletes X amount of messages. Responds to `!purge
<X>`
* Speech bot displays top claim from provided image name(coming soon posting to * Speech bot displays top claim from provided image name(coming soon posting to
speech). speech).

View file

@ -7,7 +7,7 @@ let config = require("config");
config = config.get("bot"); config = config.get("bot");
//load modules //load modules
const claimbot = require('./modules/claimbot.js'); const claimbot = require("./modules/claimbot.js");
var aliases; var aliases;
try { try {

View file

@ -1,69 +1,94 @@
let needle = require('needle'); let needle = require("needle");
let hasPriceBotChannels = require('../helpers.js').hasPriceBotChannels; let hasPriceBotChannels = require("../helpers.js").hasPriceBotChannels;
let inPrivate = require('../helpers.js').inPrivate; let inPrivate = require("../helpers.js").inPrivate;
let config = require('config'); let config = require("config");
let ChannelID = config.get('pricebot').mainchannel; let ChannelID = config.get("pricebot").mainchannel;
exports.commands = [ exports.commands = ["altprice"];
"altprice"
]
exports.altprice = { exports.altprice = {
usage: "<coin> <fiat/coin> <amount>", usage: "<coin> <fiat/coin> <amount>",
description: 'display price of specified alt coin from crypto compare\n**Example:** *!altprice ETH USD 100*', description:
"display price of specified alt coin from crypto compare\n**Example:** *!altprice ETH USD 100*",
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
let dt = new Date(); let dt = new Date();
let timestamp = dt.toUTCString(); let timestamp = dt.toUTCString();
if (!hasPriceBotChannels(msg) && !inPrivate(msg)) { if (!hasPriceBotChannels(msg) && !inPrivate(msg)) {
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;
} }
if (suffix !== "") { if (suffix !== "") {
words = suffix.trim().split(" ").filter(function(n) {return n !== "";}); words = suffix
var currency1 = words[0].toUpperCase() .trim()
.split(" ")
.filter(function(n) {
return n !== "";
});
var currency1 = words[0].toUpperCase();
if (words[1] == undefined) { if (words[1] == undefined) {
var currency2 = "BTC" var currency2 = "BTC";
} else { } else {
var currency2 = words[1].toUpperCase() var currency2 = words[1].toUpperCase();
} }
if (words[2] == undefined) { if (words[2] == undefined) {
var amount = "1" var 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() var amount = words[2].toUpperCase();
} }
} else { } else {
var currency1 = "BTC" var currency1 = "BTC";
var currency2 = "USD" var currency2 = "USD";
var amount = "1" var 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) {
msg.channel.send('coinmarketcap API is not available'); msg.channel.send("coinmarketcap API is not available");
} else { } else {
if (!response.body.Data.hasOwnProperty(currency1)) { if (!response.body.Data.hasOwnProperty(currency1)) {
msg.channel.send("Invalid Alt Coin") msg.channel.send("Invalid Alt Coin");
return return;
} }
needle.get('https://min-api.cryptocompare.com/data/price?fsym='+currency1+'&tsyms='+currency2, function(error, response) { needle.get(
"https://min-api.cryptocompare.com/data/price?fsym=" +
currency1 +
"&tsyms=" +
currency2,
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 price = Number(response.body[currency2]) var price = Number(response.body[currency2]);
var newprice = price * amount var newprice = price * amount;
var message = amount+" "+currency1+" = "+newprice.toFixed(8)+" "+currency2+"\n" + var message =
"*Updated: "+timestamp+"*"; amount +
msg.channel.send(message) " " +
currency1 +
" = " +
newprice.toFixed(8) +
" " +
currency2 +
"\n" +
"*Updated: " +
timestamp +
"*";
msg.channel.send(message);
} }
})
} }
}) );
}
});
function getValidatedAmount(amount) { function getValidatedAmount(amount) {
amount = amount.trim(); amount = amount.trim();
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null; return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
} }
} }
} };

View file

@ -1,15 +1,13 @@
let needle = require('needle'); let needle = require("needle");
let config = require('config'); let config = require("config");
let hasHashBotChannels = require('../helpers.js').hasHashBotChannels; let hasHashBotChannels = require("../helpers.js").hasHashBotChannels;
let inPrivate = require('../helpers.js').inPrivate; let inPrivate = require("../helpers.js").inPrivate;
let ChannelID = config.get('hashbot').mainchannel; let ChannelID = config.get("hashbot").mainchannel;
exports.commands = [ exports.commands = [
"hash" // command that is in this file, every command needs it own export as shown below "hash" // command that is in this file, every command needs it own export as shown below
] ];
exports.custom = [ exports.custom = ["timedhash"];
"timedhash"
]
exports.timedhash = function(bot) { exports.timedhash = function(bot) {
setInterval(function() { setInterval(function() {
@ -17,40 +15,59 @@ exports.timedhash = function(bot) {
}, 6 * 60 * 60 * 1000); }, 6 * 60 * 60 * 1000);
function sendMiningInfo(bot) { function sendMiningInfo(bot) {
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) { needle.get("https://explorer.lbry.io/api/v1/status", function(
error,
response
) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('Explorer API is not available'); msg.channel.send("Explorer API is not available");
} else { } else {
var data = response.body; var data = response.body;
var height = Number(data.status.height); var height = Number(data.status.height);
var hashrate = data.status.hashrate; var hashrate = data.status.hashrate;
var difficulty = Number(data.status.difficulty); var difficulty = Number(data.status.difficulty);
needle.get('https://whattomine.com/coins/164.json', function(error, response) { needle.get("https://whattomine.com/coins/164.json", function(
error,
response
) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('whattomine API is not available'); msg.channel.send("whattomine API is not available");
} }
var data = response.body; var data = response.body;
var reward = Number(data.block_reward); var reward = Number(data.block_reward);
var block_time = Number(data.block_time); var block_time = Number(data.block_time);
var difficulty24 = Number(data.difficulty24); var difficulty24 = Number(data.difficulty24);
description = "Hashrate: "+numberWithCommas(hashrate)+"\n" + description =
"Difficulty: "+numberWithCommas(difficulty.toFixed(0))+"\n" + "Hashrate: " +
"Difficulty 24 Hour Average: "+numberWithCommas(difficulty24.toFixed(0))+"\n" + numberWithCommas(hashrate) +
"Current block: "+numberWithCommas(height.toFixed(0))+"\n" + "\n" +
"Block Time: "+numberWithCommas(block_time.toFixed(0))+" seconds \n" + "Difficulty: " +
"Block Reward: "+numberWithCommas(reward.toFixed(0))+" LBC \n" + numberWithCommas(difficulty.toFixed(0)) +
"\n" +
"Difficulty 24 Hour Average: " +
numberWithCommas(difficulty24.toFixed(0)) +
"\n" +
"Current block: " +
numberWithCommas(height.toFixed(0)) +
"\n" +
"Block Time: " +
numberWithCommas(block_time.toFixed(0)) +
" seconds \n" +
"Block Reward: " +
numberWithCommas(reward.toFixed(0)) +
" LBC \n" +
"Sources: https://explorer.lbry.io & \n" + "Sources: https://explorer.lbry.io & \n" +
"https://whattomine.com/coins/164-lbc-lbry"; "https://whattomine.com/coins/164-lbc-lbry";
const embed = { const embed = {
"description": description, description: description,
"color": 7976557, color: 7976557,
"author": { author: {
"name": "LBRY Network Stats", name: "LBRY Network Stats",
"icon_url": "https://i.imgur.com/yWf5USu.png" icon_url: "https://i.imgur.com/yWf5USu.png"
} }
}; };
bot.channels.get(ChannelID).send({ embed }) bot.channels.get(ChannelID).send({ embed });
return return;
}); });
} }
}); });
@ -58,101 +75,154 @@ exports.timedhash = function(bot) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
} }
} };
exports.hash = { exports.hash = {
usage: "", usage: "",
description: 'Displays current Hashrate of Network\n**!hash power <Mh/s>**\n Displays potential Earnings For Given Hashrate', description:
"Displays current Hashrate of Network\n**!hash power <Mh/s>**\n Displays potential Earnings For Given Hashrate",
process: function(bot, msg, suffix) { process: function(bot, msg, suffix) {
var command = '!hash'; var command = "!hash";
words = suffix.trim().split(' ').filter( function(n){return n !== "";} ); words = suffix
.trim()
.split(" ")
.filter(function(n) {
return n !== "";
});
profitcommand = words[0]; profitcommand = words[0];
myhashrate = words[1]; myhashrate = words[1];
if (profitcommand == "power") { if (profitcommand == "power") {
sendProfitInfo(bot, msg, suffix); sendProfitInfo(bot, msg, suffix);
return return;
} else { } else {
sendMiningInfo(bot, msg, suffix); sendMiningInfo(bot, msg, suffix);
return return;
} }
function sendMiningInfo(bot, msg, suffix) { function sendMiningInfo(bot, msg, suffix) {
if (!inPrivate(msg) && !hasHashBotChannels(msg)) { if (!inPrivate(msg) && !hasHashBotChannels(msg)) {
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to hash bot.'); msg.channel.send(
"Please use <#" + ChannelID + "> or DMs to talk to hash bot."
);
return; return;
} }
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) { needle.get("https://explorer.lbry.io/api/v1/status", function(
error,
response
) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('Explorer API is not available'); msg.channel.send("Explorer API is not available");
} else { } else {
var data = response.body; var data = response.body;
var height = Number(data.status.height); var height = Number(data.status.height);
var hashrate = data.status.hashrate; var hashrate = data.status.hashrate;
var difficulty = Number(data.status.difficulty); var difficulty = Number(data.status.difficulty);
needle.get('https://whattomine.com/coins/164.json', function(error, response) { needle.get("https://whattomine.com/coins/164.json", function(
error,
response
) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('whattomine API is not available'); msg.channel.send("whattomine API is not available");
} }
var data = response.body; var data = response.body;
var reward = Number(data.block_reward); var reward = Number(data.block_reward);
var block_time = Number(data.block_time); var block_time = Number(data.block_time);
var difficulty24 = Number(data.difficulty24); var difficulty24 = Number(data.difficulty24);
description = "Hashrate: "+numberWithCommas(hashrate)+"\n" + description =
"Difficulty: "+numberWithCommas(difficulty.toFixed(0))+"\n" + "Hashrate: " +
"Difficulty 24 Hour Average: "+numberWithCommas(difficulty24.toFixed(0))+"\n" + numberWithCommas(hashrate) +
"Current block: "+numberWithCommas(height.toFixed(0))+"\n" + "\n" +
"Block Time: "+numberWithCommas(block_time.toFixed(0))+" seconds \n" + "Difficulty: " +
"Block Reward: "+numberWithCommas(reward.toFixed(0))+" LBC \n" + numberWithCommas(difficulty.toFixed(0)) +
"\n" +
"Difficulty 24 Hour Average: " +
numberWithCommas(difficulty24.toFixed(0)) +
"\n" +
"Current block: " +
numberWithCommas(height.toFixed(0)) +
"\n" +
"Block Time: " +
numberWithCommas(block_time.toFixed(0)) +
" seconds \n" +
"Block Reward: " +
numberWithCommas(reward.toFixed(0)) +
" LBC \n" +
"Sources: https://explorer.lbry.io & \n" + "Sources: https://explorer.lbry.io & \n" +
"https://whattomine.com/coins/164-lbc-lbry"; "https://whattomine.com/coins/164-lbc-lbry";
const embed = { const embed = {
"description": description, description: description,
"color": 7976557, color: 7976557,
"author": { author: {
"name": "LBRY Network Stats", name: "LBRY Network Stats",
"icon_url": "https://i.imgur.com/yWf5USu.png" icon_url: "https://i.imgur.com/yWf5USu.png"
} }
}; };
msg.channel.send({ embed }); msg.channel.send({ embed });
return return;
}); });
} }
}); });
} }
function sendProfitInfo(bot, msg, suffix) { function sendProfitInfo(bot, msg, suffix) {
needle.get('https://whattomine.com/coins/164.json', function(error, response) { needle.get("https://whattomine.com/coins/164.json", function(
error,
response
) {
if (error || response.statusCode !== 200) { if (error || response.statusCode !== 200) {
msg.channel.send('whattomine API is not available'); msg.channel.send("whattomine API is not available");
} else { } else {
words = suffix.trim().split(' ').filter( function(n){return n !== "";} ); words = suffix
.trim()
.split(" ")
.filter(function(n) {
return n !== "";
});
var myhashrate = words[1]; var myhashrate = words[1];
if (myhashrate == "" || myhashrate == null || myhashrate == undefined || myhashrate == " ") { if (
myhashrate == "" ||
myhashrate == null ||
myhashrate == undefined ||
myhashrate == " "
) {
myhashrate = "100"; myhashrate = "100";
} }
var Diff = response.body.difficulty24; var Diff = response.body.difficulty24;
var Reward = response.body.block_reward; var Reward = response.body.block_reward;
var myHash = Number(myhashrate) var myHash = Number(myhashrate);
var LBC = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 3600 var LBC = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 3600;
var LBC24 = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 86400 var LBC24 = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 86400;
var LBC1w = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 604800 var LBC1w = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 604800;
var LBC1m = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 2628000 var LBC1m =
var message = "With **" + myHash + " Mh/s** and Average 24 hour Difficulty: **" + Diff.toFixed(0) + "**\n" + myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 2628000;
var message =
"With **" +
myHash +
" Mh/s** and Average 24 hour Difficulty: **" +
Diff.toFixed(0) +
"**\n" +
"You can potentially earn the following amounts of **LBC**: \n" + "You can potentially earn the following amounts of **LBC**: \n" +
"1 Hour = **" + LBC.toFixed(4) + "** \n" + "1 Hour = **" +
"1 Day = **" + LBC24.toFixed(2) + "** \n" + LBC.toFixed(4) +
"1 Week = **" + LBC1w.toFixed(4) + "** \n" + "** \n" +
"1 Month = **" + LBC1m.toFixed(4) + "** \n" "1 Day = **" +
LBC24.toFixed(2) +
"** \n" +
"1 Week = **" +
LBC1w.toFixed(4) +
"** \n" +
"1 Month = **" +
LBC1m.toFixed(4) +
"** \n";
const embed = { const embed = {
"description": message, description: message,
"color": 7976557, color: 7976557,
"author": { author: {
"name": "Hashing Power Calculator!", name: "Hashing Power Calculator!",
"icon_url": "https://i.imgur.com/nKHVQgq.png" icon_url: "https://i.imgur.com/nKHVQgq.png"
} }
}; };
msg.channel.send({ embed }) msg.channel.send({ embed });
return return;
} }
}); });
} }
@ -160,4 +230,4 @@ exports.hash = {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
} }
} };

View file

@ -2,56 +2,69 @@ let inPrivate = require("../helpers.js").inPrivate;
exports.custom = [ exports.custom = [
"lbrylink" //change this to your function name "lbrylink" //change this to your function name
] ];
exports.lbrylink = function(bot, msg, suffix) { exports.lbrylink = function(bot, msg, suffix) {
bot.on('message', msg => { bot.on("message", msg => {
if (inPrivate(msg)) { if (inPrivate(msg)) {
return; return;
} }
var link = msg.content.indexOf("lbry://") var link = msg.content.indexOf("lbry://");
if (link != -1) { if (link != -1) {
var text = msg.content.replace("lbry://", "https://open.lbry.io/"); var text = msg.content.replace("lbry://", "https://open.lbry.io/");
var message = GetWordByPos(text, link) var message = GetWordByPos(text, link);
if (text.search("<") != -1) { if (text.search("<") != -1) {
var name = "@" + msg.mentions.members.first().user.username var name = "@" + msg.mentions.members.first().user.username;
var trim = message.split("/").pop() var trim = message.split("/").pop();
var trim2 = trim.substr(2) var trim2 = trim.substr(2);
var id = trim2.substr(0, trim2.length - 1) var id = trim2.substr(0, trim2.length - 1);
if (message.indexOf("#") != -1) { if (message.indexOf("#") != -1) {
if (trim.indexOf("@") != -1) { if (trim.indexOf("@") != -1) {
var trim3 = message.split("#").pop() var trim3 = message.split("#").pop();
var message = "https://open.lbry.io/" + name + "#" + trim3 var message = "https://open.lbry.io/" + name + "#" + trim3;
var newname = name + "#" + trim3 var newname = name + "#" + trim3;
} else { } else {
var trim3 = message.split("/").pop() var trim3 = message.split("/").pop();
var done = trim3 var done = trim3;
var message = "https://open.lbry.io/" + name + "/" + done var message = "https://open.lbry.io/" + name + "/" + done;
var newname = name + "/" + done var newname = name + "/" + done;
} }
} else { } else {
if (msg.mentions.members.first().id != id) { if (msg.mentions.members.first().id != id) {
var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username + "/" + message.split("/").pop() var message =
var newname = name + "/" + message.split("/").pop() "https://open.lbry.io/@" +
msg.mentions.members.first().user.username +
"/" +
message.split("/").pop();
var newname = name + "/" + message.split("/").pop();
} else { } else {
var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username var message =
var newname = name "https://open.lbry.io/@" +
msg.mentions.members.first().user.username;
var newname = name;
} }
} }
} else { } else {
var newname = message.replace("https://open.lbry.io/", ""); var newname = message.replace("https://open.lbry.io/", "");
} }
const embed = { const embed = {
"description": msg.author + ", I see you tried to post a LBRY URL, here's a friendly hyperlink to share and for others to access your content with a single click: \n" + "[lbry://" + newname + "](" + message + ")", description:
"color": 7976557, msg.author +
"author": { ", I see you tried to post a LBRY URL, here's a friendly hyperlink to share and for others to access your content with a single click: \n" +
"name": "LBRY Linker", "[lbry://" +
"icon_url": "https://i.imgur.com/yWf5USu.png" newname +
"](" +
message +
")",
color: 7976557,
author: {
name: "LBRY Linker",
icon_url: "https://i.imgur.com/yWf5USu.png"
} }
}; };
msg.channel.send({ msg.channel.send({
embed embed
}) });
} }
function GetWordByPos(str, pos) { function GetWordByPos(str, pos) {
@ -63,5 +76,5 @@ exports.lbrylink = function(bot, msg, suffix) {
return left + right; return left + right;
} }
}) });
} };

View file

@ -1,106 +1,160 @@
let jp = require('jsonpath'); let jp = require("jsonpath");
let moment = require('moment'); let moment = require("moment");
let numeral = require('numeral'); let numeral = require("numeral");
let request = require('request'); let request = require("request");
let config = require('config'); let config = require("config");
let needle = require('needle'); let needle = require("needle");
let hasStatsBotChannels = require('../helpers.js').hasStatsBotChannels; let hasStatsBotChannels = require("../helpers.js").hasStatsBotChannels;
let inPrivate = require('../helpers.js').inPrivate; let inPrivate = require("../helpers.js").inPrivate;
let ChannelID = config.get('statsbot').mainchannel; let ChannelID = config.get("statsbot").mainchannel;
let statsurl = "https://coinmarketcap.com/currencies/library-credit/" let statsurl = "https://coinmarketcap.com/currencies/library-credit/";
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 stats",
process: function(bot, msg) { process: function(bot, msg) {
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/', function(error, response) { needle.get(
"https://api.coinmarketcap.com/v1/ticker/library-credit/",
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]; var data = response.body[0];
var rank = data.rank var rank = data.rank;
var price_usd = Number(data.price_usd) var price_usd = Number(data.price_usd);
var price_btc = Number(data.price_btc) var price_btc = Number(data.price_btc);
var market_cap_usd = Number(data.market_cap_usd) var market_cap_usd = Number(data.market_cap_usd);
var available_supply = Number(data.available_supply) var available_supply = Number(data.available_supply);
var total_supply = Number(data.total_supply) var total_supply = Number(data.total_supply);
var percent_change_1h = Number(data.percent_change_1h) var percent_change_1h = Number(data.percent_change_1h);
var percent_change_24h = Number(data.percent_change_24h) var percent_change_24h = Number(data.percent_change_24h);
var json = response.body[0]; var json = response.body[0];
var newjson = parse_obj(json) var newjson = parse_obj(json);
var parse = JSON.stringify(newjson) var parse = JSON.stringify(newjson);
var volume24_usd = parse.replace(/[^0-9]/g, ''); var volume24_usd = parse.replace(/[^0-9]/g, "");
var dt = new Date(); var dt = new Date();
var timestamp = dt.toUTCString(); var timestamp = dt.toUTCString();
var hr_indicator = ":thumbsup:" var hr_indicator = ":thumbsup:";
var day_indicator =":thumbsup:" var day_indicator = ":thumbsup:";
if (percent_change_1h < 0) { if (percent_change_1h < 0) {
hr_indicator = ":thumbsdown:" hr_indicator = ":thumbsdown:";
} }
if (percent_change_24h < 0) { if (percent_change_24h < 0) {
day_indicator = ":thumbsdown:" day_indicator = ":thumbsdown:";
} }
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=GBP', function(error, response) { needle.get(
"https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=GBP",
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]; var data = response.body[0];
var price_gbp = Number(data.price_gbp) var 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]; var data = response.body[0];
var price_eur = Number(data.price_eur) var price_eur = Number(data.price_eur);
description = "**Rank: ["+rank+"]("+statsurl+")**\n" + description =
"**Rank: [" +
rank +
"](" +
statsurl +
")**\n" +
"**Data**\n" + "**Data**\n" +
"Market Cap: [$"+numberWithCommas(market_cap_usd)+"]("+statsurl+") \n" + "Market Cap: [$" +
"Total Supply: ["+numberWithCommas(total_supply)+" LBC]("+statsurl+")\n" + numberWithCommas(market_cap_usd) +
"Circulating Supply: ["+numberWithCommas(available_supply)+" LBC]("+statsurl+")\n" + "](" +
"24 Hour Volume: [$"+volume24_usd+"]("+statsurl+") \n\n" + statsurl +
") \n" +
"Total Supply: [" +
numberWithCommas(total_supply) +
" LBC](" +
statsurl +
")\n" +
"Circulating Supply: [" +
numberWithCommas(available_supply) +
" LBC](" +
statsurl +
")\n" +
"24 Hour Volume: [$" +
volume24_usd +
"](" +
statsurl +
") \n\n" +
"**Price**\n" + "**Price**\n" +
"BTC: [₿"+price_btc.toFixed(8)+"]("+statsurl+")\n" + "BTC: [₿" +
"USD: [$"+price_usd.toFixed(2)+"]("+statsurl+") \n" + price_btc.toFixed(8) +
"EUR: [€"+price_eur.toFixed(2)+"]("+statsurl+") \n" + "](" +
"GBP: [£"+price_gbp.toFixed(2)+"]("+statsurl+") \n\n" + statsurl +
")\n" +
"USD: [$" +
price_usd.toFixed(2) +
"](" +
statsurl +
") \n" +
"EUR: [€" +
price_eur.toFixed(2) +
"](" +
statsurl +
") \n" +
"GBP: [£" +
price_gbp.toFixed(2) +
"](" +
statsurl +
") \n\n" +
"**% Change**\n" + "**% Change**\n" +
"1 Hour: ["+percent_change_1h+"]("+statsurl+") "+hr_indicator+" \n\n" + "1 Hour: [" +
"1 Day: ["+percent_change_24h+"]("+statsurl+") "+day_indicator+" \n\n" percent_change_1h +
"](" +
statsurl +
") " +
hr_indicator +
" \n\n" +
"1 Day: [" +
percent_change_24h +
"](" +
statsurl +
") " +
day_indicator +
" \n\n";
const embed = { const embed = {
"description": description, description: description,
"color": 7976557, color: 7976557,
"footer": { footer: {
"text": "Last Updated: "+timestamp text: "Last Updated: " + timestamp
}, },
"author": { author: {
"name": "Coin Market Cap Stats (LBC)", name: "Coin Market Cap Stats (LBC)",
"url": statsurl, url: statsurl,
"icon_url": "https://i.imgur.com/yWf5USu.png" icon_url: "https://i.imgur.com/yWf5USu.png"
} }
}; };
msg.channel.send({ embed }) msg.channel.send({ embed });
} }
})
} }
}) );
} }
}) }
function parse_obj(obj) );
{ }
}
);
function parse_obj(obj) {
var array = []; var array = [];
var prop; var prop;
for (prop in obj) for (prop in obj) {
{ if (obj.hasOwnProperty(prop)) {
if (obj.hasOwnProperty(prop))
{
var key = parseInt(prop, 10); var key = parseInt(prop, 10);
var value = obj[prop]; var value = obj[prop];
if (typeof value == "object") if (typeof value == "object") {
{
value = parse_obj(value); value = parse_obj(value);
} }
array[key] = value; array[key] = value;
@ -112,4 +166,4 @@ exports.stats = {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
} }
} };

531
package-lock.json generated

File diff suppressed because it is too large Load diff