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,25 +4,28 @@
## 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.
Responds to `!releasenotes` Responds to `!releasenotes`
(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).
Responds to `!speech <imagename>` Responds to `!speech <imagename>`
* Welcome bot sends Direct Message when new users join, * Welcome bot sends Direct Message when new users join,
(moderator only) Responds to `!welcome <@username>` (moderator only) Responds to `!welcome <@username>`

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 {
@ -199,4 +199,4 @@ exports.addCustomFunc = function(customFunc) {
exports.commandCount = function() { exports.commandCount = function() {
return Object.keys(commands).length; return Object.keys(commands).length;
}; };
bot.login(config.token); bot.login(config.token);

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:
process: function(bot,msg,suffix){ "display price of specified alt coin from crypto compare\n**Example:** *!altprice ETH USD 100*",
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(
return; "Please use <#" + ChannelID + "> or DMs to talk to price bot."
);
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) {
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+"*";
msg.channel.send(message)
}
})
} }
}) needle.get(
"https://min-api.cryptocompare.com/data/price?fsym=" +
currency1 +
"&tsyms=" +
currency2,
function(error, response) {
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 +
"*";
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,163 +1,233 @@
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() {
sendMiningInfo(bot); sendMiningInfo(bot);
}, 6 * 60 * 60 * 1000); }, 6 * 60 * 60 * 1000);
function sendMiningInfo(bot) {
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) {
if (error || response.statusCode !== 200) {
msg.channel.send('Explorer API is not available');
} else {
var data = response.body;
var height = Number(data.status.height);
var hashrate = data.status.hashrate;
var difficulty = Number(data.status.difficulty);
needle.get('https://whattomine.com/coins/164.json', function(error, response) {
if (error || response.statusCode !== 200) {
msg.channel.send('whattomine API is not available');
}
var data = response.body;
var reward = Number(data.block_reward);
var block_time = Number(data.block_time);
var difficulty24 = Number(data.difficulty24);
description = "Hashrate: "+numberWithCommas(hashrate)+"\n" +
"Difficulty: "+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" +
"https://whattomine.com/coins/164-lbc-lbry";
const embed = {
"description": description,
"color": 7976557,
"author": {
"name": "LBRY Network Stats",
"icon_url": "https://i.imgur.com/yWf5USu.png"
}
};
bot.channels.get(ChannelID).send({ embed })
return
});
}
});
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
}
function sendMiningInfo(bot) {
needle.get("https://explorer.lbry.io/api/v1/status", function(
error,
response
) {
if (error || response.statusCode !== 200) {
msg.channel.send("Explorer API is not available");
} else {
var data = response.body;
var height = Number(data.status.height);
var hashrate = data.status.hashrate;
var difficulty = Number(data.status.difficulty);
needle.get("https://whattomine.com/coins/164.json", function(
error,
response
) {
if (error || response.statusCode !== 200) {
msg.channel.send("whattomine API is not available");
}
var data = response.body;
var reward = Number(data.block_reward);
var block_time = Number(data.block_time);
var difficulty24 = Number(data.difficulty24);
description =
"Hashrate: " +
numberWithCommas(hashrate) +
"\n" +
"Difficulty: " +
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" +
"https://whattomine.com/coins/164-lbc-lbry";
const embed = {
description: description,
color: 7976557,
author: {
name: "LBRY Network Stats",
icon_url: "https://i.imgur.com/yWf5USu.png"
}
};
bot.channels.get(ChannelID).send({ embed });
return;
});
}
});
function numberWithCommas(x) {
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:
process: function(bot,msg,suffix){ "Displays current Hashrate of Network\n**!hash power <Mh/s>**\n Displays potential Earnings For Given Hashrate",
var command = '!hash'; process: function(bot, msg, suffix) {
words = suffix.trim().split(' ').filter( function(n){return n !== "";} ); var command = "!hash";
profitcommand = words[0]; words = suffix
myhashrate = words[1]; .trim()
if (profitcommand == "power") { .split(" ")
sendProfitInfo(bot, msg, suffix); .filter(function(n) {
return return n !== "";
} else { });
sendMiningInfo(bot, msg, suffix); profitcommand = words[0];
return myhashrate = words[1];
} if (profitcommand == "power") {
sendProfitInfo(bot, msg, suffix);
return;
} else {
sendMiningInfo(bot, msg, suffix);
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(
return; "Please use <#" + ChannelID + "> or DMs to talk to hash bot."
} );
needle.get('https://explorer.lbry.io/api/v1/status', function(error, response) { return;
if (error || response.statusCode !== 200) { }
msg.channel.send('Explorer API is not available'); needle.get("https://explorer.lbry.io/api/v1/status", function(
} else { error,
var data = response.body; response
var height = Number(data.status.height); ) {
var hashrate = data.status.hashrate; if (error || response.statusCode !== 200) {
var difficulty = Number(data.status.difficulty); msg.channel.send("Explorer API is not available");
needle.get('https://whattomine.com/coins/164.json', function(error, response) { } else {
if (error || response.statusCode !== 200) { var data = response.body;
msg.channel.send('whattomine API is not available'); var height = Number(data.status.height);
} var hashrate = data.status.hashrate;
var data = response.body; var difficulty = Number(data.status.difficulty);
var reward = Number(data.block_reward); needle.get("https://whattomine.com/coins/164.json", function(
var block_time = Number(data.block_time); error,
var difficulty24 = Number(data.difficulty24); response
description = "Hashrate: "+numberWithCommas(hashrate)+"\n" + ) {
"Difficulty: "+numberWithCommas(difficulty.toFixed(0))+"\n" + if (error || response.statusCode !== 200) {
"Difficulty 24 Hour Average: "+numberWithCommas(difficulty24.toFixed(0))+"\n" + msg.channel.send("whattomine API is not available");
"Current block: "+numberWithCommas(height.toFixed(0))+"\n" + }
"Block Time: "+numberWithCommas(block_time.toFixed(0))+" seconds \n" + var data = response.body;
"Block Reward: "+numberWithCommas(reward.toFixed(0))+" LBC \n" + var reward = Number(data.block_reward);
"Sources: https://explorer.lbry.io & \n" + var block_time = Number(data.block_time);
"https://whattomine.com/coins/164-lbc-lbry"; var difficulty24 = Number(data.difficulty24);
const embed = { description =
"description": description, "Hashrate: " +
"color": 7976557, numberWithCommas(hashrate) +
"author": { "\n" +
"name": "LBRY Network Stats", "Difficulty: " +
"icon_url": "https://i.imgur.com/yWf5USu.png" numberWithCommas(difficulty.toFixed(0)) +
} "\n" +
}; "Difficulty 24 Hour Average: " +
msg.channel.send({ embed }); numberWithCommas(difficulty24.toFixed(0)) +
return "\n" +
}); "Current block: " +
} numberWithCommas(height.toFixed(0)) +
}); "\n" +
} "Block Time: " +
function sendProfitInfo(bot, msg, suffix) { numberWithCommas(block_time.toFixed(0)) +
needle.get('https://whattomine.com/coins/164.json', function(error, response) { " seconds \n" +
if (error || response.statusCode !== 200) { "Block Reward: " +
msg.channel.send('whattomine API is not available'); numberWithCommas(reward.toFixed(0)) +
} else { " LBC \n" +
words = suffix.trim().split(' ').filter( function(n){return n !== "";} ); "Sources: https://explorer.lbry.io & \n" +
var myhashrate = words[1]; "https://whattomine.com/coins/164-lbc-lbry";
if (myhashrate == "" || myhashrate == null || myhashrate == undefined || myhashrate == " ") { const embed = {
myhashrate = "100"; description: description,
} color: 7976557,
var Diff = response.body.difficulty24; author: {
var Reward = response.body.block_reward; name: "LBRY Network Stats",
var myHash = Number(myhashrate) icon_url: "https://i.imgur.com/yWf5USu.png"
var LBC = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 3600 }
var LBC24 = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 86400 };
var LBC1w = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 604800 msg.channel.send({ embed });
var LBC1m = myHash / 2000 * (1 / (Diff * 2^32) * Reward) * 2628000 return;
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" + }
"1 Hour = **" + LBC.toFixed(4) + "** \n" + });
"1 Day = **" + LBC24.toFixed(2) + "** \n" + }
"1 Week = **" + LBC1w.toFixed(4) + "** \n" + function sendProfitInfo(bot, msg, suffix) {
"1 Month = **" + LBC1m.toFixed(4) + "** \n" needle.get("https://whattomine.com/coins/164.json", function(
const embed = { error,
"description": message, response
"color": 7976557, ) {
"author": { if (error || response.statusCode !== 200) {
"name": "Hashing Power Calculator!", msg.channel.send("whattomine API is not available");
"icon_url": "https://i.imgur.com/nKHVQgq.png" } else {
} words = suffix
}; .trim()
msg.channel.send({ embed }) .split(" ")
return .filter(function(n) {
} return n !== "";
}); });
} var myhashrate = words[1];
function numberWithCommas(x) { if (
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); myhashrate == "" ||
} myhashrate == null ||
} myhashrate == undefined ||
} myhashrate == " "
) {
myhashrate = "100";
}
var Diff = response.body.difficulty24;
var Reward = response.body.block_reward;
var myHash = Number(myhashrate);
var LBC = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 3600;
var LBC24 = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 86400;
var LBC1w = myHash / 2000 * (1 / ((Diff * 2) ^ 32) * Reward) * 604800;
var LBC1m =
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" +
"1 Hour = **" +
LBC.toFixed(4) +
"** \n" +
"1 Day = **" +
LBC24.toFixed(2) +
"** \n" +
"1 Week = **" +
LBC1w.toFixed(4) +
"** \n" +
"1 Month = **" +
LBC1m.toFixed(4) +
"** \n";
const embed = {
description: message,
color: 7976557,
author: {
name: "Hashing Power Calculator!",
icon_url: "https://i.imgur.com/nKHVQgq.png"
}
};
msg.channel.send({ embed });
return;
}
});
}
function numberWithCommas(x) {
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,115 +1,169 @@
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(
if (error || response.statusCode !== 200) { "https://api.coinmarketcap.com/v1/ticker/library-credit/",
msg.channel.send('coinmarketcap API is not available'); function(error, response) {
} else { if (error || response.statusCode !== 200) {
var data = response.body[0]; msg.channel.send("coinmarketcap API is not available");
var rank = data.rank } else {
var price_usd = Number(data.price_usd) var data = response.body[0];
var price_btc = Number(data.price_btc) var rank = data.rank;
var market_cap_usd = Number(data.market_cap_usd) var price_usd = Number(data.price_usd);
var available_supply = Number(data.available_supply) var price_btc = Number(data.price_btc);
var total_supply = Number(data.total_supply) var market_cap_usd = Number(data.market_cap_usd);
var percent_change_1h = Number(data.percent_change_1h) var available_supply = Number(data.available_supply);
var percent_change_24h = Number(data.percent_change_24h) var total_supply = Number(data.total_supply);
var json = response.body[0]; var percent_change_1h = Number(data.percent_change_1h);
var newjson = parse_obj(json) var percent_change_24h = Number(data.percent_change_24h);
var parse = JSON.stringify(newjson) var json = response.body[0];
var volume24_usd = parse.replace(/[^0-9]/g, ''); var newjson = parse_obj(json);
var dt = new Date(); var parse = JSON.stringify(newjson);
var timestamp = dt.toUTCString(); var volume24_usd = parse.replace(/[^0-9]/g, "");
var hr_indicator = ":thumbsup:" var dt = new Date();
var day_indicator =":thumbsup:" var timestamp = dt.toUTCString();
if (percent_change_1h < 0) { var hr_indicator = ":thumbsup:";
hr_indicator = ":thumbsdown:" var day_indicator = ":thumbsup:";
} if (percent_change_1h < 0) {
if (percent_change_24h < 0) { hr_indicator = ":thumbsdown:";
day_indicator = ":thumbsdown:" }
} if (percent_change_24h < 0) {
day_indicator = ":thumbsdown:";
}
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=GBP', function(error, response) { needle.get(
if (error || response.statusCode !== 200) { "https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=GBP",
msg.channel.send('coinmarketcap API is not available'); function(error, response) {
} else { if (error || response.statusCode !== 200) {
var data = response.body[0]; msg.channel.send("coinmarketcap API is not available");
var price_gbp = Number(data.price_gbp) } else {
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR', function(error, response) { var data = response.body[0];
if (error || response.statusCode !== 200) { var price_gbp = Number(data.price_gbp);
msg.channel.send('coinmarketcap API is not available'); needle.get(
} else { "https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR",
var data = response.body[0]; function(error, response) {
var price_eur = Number(data.price_eur) if (error || response.statusCode !== 200) {
description = "**Rank: ["+rank+"]("+statsurl+")**\n" + msg.channel.send("coinmarketcap API is not available");
"**Data**\n" + } else {
"Market Cap: [$"+numberWithCommas(market_cap_usd)+"]("+statsurl+") \n" + var data = response.body[0];
"Total Supply: ["+numberWithCommas(total_supply)+" LBC]("+statsurl+")\n" + var price_eur = Number(data.price_eur);
"Circulating Supply: ["+numberWithCommas(available_supply)+" LBC]("+statsurl+")\n" + description =
"24 Hour Volume: [$"+volume24_usd+"]("+statsurl+") \n\n" + "**Rank: [" +
"**Price**\n" + rank +
"BTC: [₿"+price_btc.toFixed(8)+"]("+statsurl+")\n" + "](" +
"USD: [$"+price_usd.toFixed(2)+"]("+statsurl+") \n" + statsurl +
"EUR: [€"+price_eur.toFixed(2)+"]("+statsurl+") \n" + ")**\n" +
"GBP: [£"+price_gbp.toFixed(2)+"]("+statsurl+") \n\n" + "**Data**\n" +
"**% Change**\n" + "Market Cap: [$" +
"1 Hour: ["+percent_change_1h+"]("+statsurl+") "+hr_indicator+" \n\n" + numberWithCommas(market_cap_usd) +
"1 Day: ["+percent_change_24h+"]("+statsurl+") "+day_indicator+" \n\n" "](" +
const embed = { statsurl +
"description": description, ") \n" +
"color": 7976557, "Total Supply: [" +
"footer": { numberWithCommas(total_supply) +
"text": "Last Updated: "+timestamp " LBC](" +
}, statsurl +
"author": { ")\n" +
"name": "Coin Market Cap Stats (LBC)", "Circulating Supply: [" +
"url": statsurl, numberWithCommas(available_supply) +
"icon_url": "https://i.imgur.com/yWf5USu.png" " LBC](" +
} statsurl +
}; ")\n" +
msg.channel.send({ embed }) "24 Hour Volume: [$" +
} volume24_usd +
}) "](" +
} statsurl +
}) ") \n\n" +
} "**Price**\n" +
}) "BTC: [₿" +
function parse_obj(obj) price_btc.toFixed(8) +
{ "](" +
var array = []; statsurl +
var prop; ")\n" +
for (prop in obj) "USD: [$" +
{ price_usd.toFixed(2) +
if (obj.hasOwnProperty(prop)) "](" +
{ statsurl +
var key = parseInt(prop, 10); ") \n" +
var value = obj[prop]; "EUR: [€" +
if (typeof value == "object") price_eur.toFixed(2) +
{ "](" +
value = parse_obj(value); statsurl +
} ") \n" +
array[key] = value; "GBP: [£" +
} price_gbp.toFixed(2) +
} "](" +
return array; statsurl +
} ") \n\n" +
function numberWithCommas(x) { "**% Change**\n" +
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); "1 Hour: [" +
} percent_change_1h +
"](" +
statsurl +
") " +
hr_indicator +
" \n\n" +
"1 Day: [" +
percent_change_24h +
"](" +
statsurl +
") " +
day_indicator +
" \n\n";
const embed = {
description: description,
color: 7976557,
footer: {
text: "Last Updated: " + timestamp
},
author: {
name: "Coin Market Cap Stats (LBC)",
url: statsurl,
icon_url: "https://i.imgur.com/yWf5USu.png"
}
};
msg.channel.send({ embed });
}
}
);
}
}
);
}
}
);
function parse_obj(obj) {
var array = [];
var prop;
for (prop in obj) {
if (obj.hasOwnProperty(prop)) {
var key = parseInt(prop, 10);
var 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

@ -1,10 +1,10 @@
"use strict"; "use strict";
exports.commands = ["tip"]; exports.commands = ["tip"];
exports.tip = { exports.tip = {
usage: "<subcommand>", usage: "<subcommand>",
description: description:
"balance: get your balance\n deposit: get address for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n <user> <amount>: mention a user with @ and then the amount to tip them", "balance: get your balance\n deposit: get address for your deposits\n withdraw ADDRESS AMOUNT: withdraw AMOUNT credits to ADDRESS\n <user> <amount>: mention a user with @ and then the amount to tip them",
process: function(bot) { process: function(bot) {
return; // Tipping is now handled by the separate tipbot(in branch tipbot_dc), no need to to anything here... return; // Tipping is now handled by the separate tipbot(in branch tipbot_dc), no need to to anything here...
} }
}; };

531
package-lock.json generated

File diff suppressed because it is too large Load diff