mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
prettified code once and for all
This commit is contained in:
parent
b5d144111e
commit
6fff099a62
8 changed files with 874 additions and 532 deletions
15
README.md
15
README.md
|
@ -4,25 +4,28 @@
|
|||
|
||||
## 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`
|
||||
* 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.
|
||||
|
||||
Responds to `!releasenotes`
|
||||
|
||||
Responds to `!releasenotes`
|
||||
|
||||
(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).
|
||||
|
||||
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>`
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ let config = require("config");
|
|||
config = config.get("bot");
|
||||
|
||||
//load modules
|
||||
const claimbot = require('./modules/claimbot.js');
|
||||
const claimbot = require("./modules/claimbot.js");
|
||||
|
||||
var aliases;
|
||||
try {
|
||||
|
@ -199,4 +199,4 @@ exports.addCustomFunc = function(customFunc) {
|
|||
exports.commandCount = function() {
|
||||
return Object.keys(commands).length;
|
||||
};
|
||||
bot.login(config.token);
|
||||
bot.login(config.token);
|
||||
|
|
|
@ -1,69 +1,94 @@
|
|||
let needle = require('needle');
|
||||
let hasPriceBotChannels = require('../helpers.js').hasPriceBotChannels;
|
||||
let inPrivate = require('../helpers.js').inPrivate;
|
||||
let config = require('config');
|
||||
let ChannelID = config.get('pricebot').mainchannel;
|
||||
let needle = require("needle");
|
||||
let hasPriceBotChannels = require("../helpers.js").hasPriceBotChannels;
|
||||
let inPrivate = require("../helpers.js").inPrivate;
|
||||
let config = require("config");
|
||||
let ChannelID = config.get("pricebot").mainchannel;
|
||||
|
||||
exports.commands = [
|
||||
"altprice"
|
||||
]
|
||||
exports.commands = ["altprice"];
|
||||
|
||||
exports.altprice = {
|
||||
usage: "<coin> <fiat/coin> <amount>",
|
||||
description: 'display price of specified alt coin from crypto compare\n**Example:** *!altprice ETH USD 100*',
|
||||
process: function(bot,msg,suffix){
|
||||
description:
|
||||
"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 timestamp = dt.toUTCString();
|
||||
if(!hasPriceBotChannels(msg) && !inPrivate(msg)){
|
||||
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
|
||||
return;
|
||||
if (!hasPriceBotChannels(msg) && !inPrivate(msg)) {
|
||||
msg.channel.send(
|
||||
"Please use <#" + ChannelID + "> or DMs to talk to price bot."
|
||||
);
|
||||
return;
|
||||
}
|
||||
if (suffix !== "") {
|
||||
words = suffix.trim().split(" ").filter(function(n) {return n !== "";});
|
||||
var currency1 = words[0].toUpperCase()
|
||||
words = suffix
|
||||
.trim()
|
||||
.split(" ")
|
||||
.filter(function(n) {
|
||||
return n !== "";
|
||||
});
|
||||
var currency1 = words[0].toUpperCase();
|
||||
if (words[1] == undefined) {
|
||||
var currency2 = "BTC"
|
||||
var currency2 = "BTC";
|
||||
} else {
|
||||
var currency2 = words[1].toUpperCase()
|
||||
var currency2 = words[1].toUpperCase();
|
||||
}
|
||||
if (words[2] == undefined) {
|
||||
var amount = "1"
|
||||
var amount = "1";
|
||||
} else {
|
||||
if (getValidatedAmount(words[2]) === null) {
|
||||
msg.reply('Please specify a number for <amount>');
|
||||
return;
|
||||
}
|
||||
var amount = words[2].toUpperCase()
|
||||
if (getValidatedAmount(words[2]) === null) {
|
||||
msg.reply("Please specify a number for <amount>");
|
||||
return;
|
||||
}
|
||||
var amount = words[2].toUpperCase();
|
||||
}
|
||||
} else {
|
||||
var currency1 = "BTC"
|
||||
var currency2 = "USD"
|
||||
var amount = "1"
|
||||
var currency1 = "BTC";
|
||||
var currency2 = "USD";
|
||||
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) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
msg.channel.send("coinmarketcap API is not available");
|
||||
} else {
|
||||
if (!response.body.Data.hasOwnProperty(currency1)) {
|
||||
msg.channel.send("Invalid Alt Coin")
|
||||
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)
|
||||
}
|
||||
})
|
||||
if (!response.body.Data.hasOwnProperty(currency1)) {
|
||||
msg.channel.send("Invalid Alt Coin");
|
||||
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);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
function getValidatedAmount(amount) {
|
||||
amount = amount.trim();
|
||||
return amount.match(/^[0-9]+(\.[0-9]+)?$/) ? amount : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,163 +1,233 @@
|
|||
let needle = require('needle');
|
||||
let config = require('config');
|
||||
let hasHashBotChannels = require('../helpers.js').hasHashBotChannels;
|
||||
let inPrivate = require('../helpers.js').inPrivate;
|
||||
let ChannelID = config.get('hashbot').mainchannel;
|
||||
let needle = require("needle");
|
||||
let config = require("config");
|
||||
let hasHashBotChannels = require("../helpers.js").hasHashBotChannels;
|
||||
let inPrivate = require("../helpers.js").inPrivate;
|
||||
let ChannelID = config.get("hashbot").mainchannel;
|
||||
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 = [
|
||||
"timedhash"
|
||||
]
|
||||
exports.custom = ["timedhash"];
|
||||
|
||||
exports.timedhash = function(bot) {
|
||||
setInterval(function() {
|
||||
sendMiningInfo(bot);
|
||||
}, 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, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
setInterval(function() {
|
||||
sendMiningInfo(bot);
|
||||
}, 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, ",");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exports.hash = {
|
||||
usage: "",
|
||||
description: 'Displays current Hashrate of Network\n**!hash power <Mh/s>**\n Displays potential Earnings For Given Hashrate',
|
||||
process: function(bot,msg,suffix){
|
||||
var command = '!hash';
|
||||
words = suffix.trim().split(' ').filter( function(n){return n !== "";} );
|
||||
profitcommand = words[0];
|
||||
myhashrate = words[1];
|
||||
if (profitcommand == "power") {
|
||||
sendProfitInfo(bot, msg, suffix);
|
||||
return
|
||||
} else {
|
||||
sendMiningInfo(bot, msg, suffix);
|
||||
return
|
||||
}
|
||||
usage: "",
|
||||
description:
|
||||
"Displays current Hashrate of Network\n**!hash power <Mh/s>**\n Displays potential Earnings For Given Hashrate",
|
||||
process: function(bot, msg, suffix) {
|
||||
var command = "!hash";
|
||||
words = suffix
|
||||
.trim()
|
||||
.split(" ")
|
||||
.filter(function(n) {
|
||||
return n !== "";
|
||||
});
|
||||
profitcommand = words[0];
|
||||
myhashrate = words[1];
|
||||
if (profitcommand == "power") {
|
||||
sendProfitInfo(bot, msg, suffix);
|
||||
return;
|
||||
} else {
|
||||
sendMiningInfo(bot, msg, suffix);
|
||||
return;
|
||||
}
|
||||
|
||||
function sendMiningInfo(bot, msg, suffix) {
|
||||
if(!inPrivate(msg) && !hasHashBotChannels(msg)){
|
||||
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to hash bot.');
|
||||
return;
|
||||
}
|
||||
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"
|
||||
}
|
||||
};
|
||||
msg.channel.send({ embed });
|
||||
return
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function sendProfitInfo(bot, msg, suffix) {
|
||||
needle.get('https://whattomine.com/coins/164.json', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('whattomine API is not available');
|
||||
} else {
|
||||
words = suffix.trim().split(' ').filter( function(n){return n !== "";} );
|
||||
var myhashrate = words[1];
|
||||
if (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, ",");
|
||||
}
|
||||
}
|
||||
}
|
||||
function sendMiningInfo(bot, msg, suffix) {
|
||||
if (!inPrivate(msg) && !hasHashBotChannels(msg)) {
|
||||
msg.channel.send(
|
||||
"Please use <#" + ChannelID + "> or DMs to talk to hash bot."
|
||||
);
|
||||
return;
|
||||
}
|
||||
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"
|
||||
}
|
||||
};
|
||||
msg.channel.send({ embed });
|
||||
return;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
function sendProfitInfo(bot, msg, suffix) {
|
||||
needle.get("https://whattomine.com/coins/164.json", function(
|
||||
error,
|
||||
response
|
||||
) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send("whattomine API is not available");
|
||||
} else {
|
||||
words = suffix
|
||||
.trim()
|
||||
.split(" ")
|
||||
.filter(function(n) {
|
||||
return n !== "";
|
||||
});
|
||||
var myhashrate = words[1];
|
||||
if (
|
||||
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, ",");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,56 +2,69 @@ let inPrivate = require("../helpers.js").inPrivate;
|
|||
|
||||
exports.custom = [
|
||||
"lbrylink" //change this to your function name
|
||||
]
|
||||
];
|
||||
|
||||
exports.lbrylink = function(bot, msg, suffix) {
|
||||
bot.on('message', msg => {
|
||||
bot.on("message", msg => {
|
||||
if (inPrivate(msg)) {
|
||||
return;
|
||||
}
|
||||
var link = msg.content.indexOf("lbry://")
|
||||
var link = msg.content.indexOf("lbry://");
|
||||
if (link != -1) {
|
||||
var text = msg.content.replace("lbry://", "https://open.lbry.io/");
|
||||
var message = GetWordByPos(text, link)
|
||||
var message = GetWordByPos(text, link);
|
||||
if (text.search("<") != -1) {
|
||||
var name = "@" + msg.mentions.members.first().user.username
|
||||
var trim = message.split("/").pop()
|
||||
var trim2 = trim.substr(2)
|
||||
var id = trim2.substr(0, trim2.length - 1)
|
||||
var name = "@" + msg.mentions.members.first().user.username;
|
||||
var trim = message.split("/").pop();
|
||||
var trim2 = trim.substr(2);
|
||||
var id = trim2.substr(0, trim2.length - 1);
|
||||
if (message.indexOf("#") != -1) {
|
||||
if (trim.indexOf("@") != -1) {
|
||||
var trim3 = message.split("#").pop()
|
||||
var message = "https://open.lbry.io/" + name + "#" + trim3
|
||||
var newname = name + "#" + trim3
|
||||
var trim3 = message.split("#").pop();
|
||||
var message = "https://open.lbry.io/" + name + "#" + trim3;
|
||||
var newname = name + "#" + trim3;
|
||||
} else {
|
||||
var trim3 = message.split("/").pop()
|
||||
var done = trim3
|
||||
var message = "https://open.lbry.io/" + name + "/" + done
|
||||
var newname = name + "/" + done
|
||||
var trim3 = message.split("/").pop();
|
||||
var done = trim3;
|
||||
var message = "https://open.lbry.io/" + name + "/" + done;
|
||||
var newname = name + "/" + done;
|
||||
}
|
||||
} else {
|
||||
if (msg.mentions.members.first().id != id) {
|
||||
var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username + "/" + message.split("/").pop()
|
||||
var newname = name + "/" + message.split("/").pop()
|
||||
var message =
|
||||
"https://open.lbry.io/@" +
|
||||
msg.mentions.members.first().user.username +
|
||||
"/" +
|
||||
message.split("/").pop();
|
||||
var newname = name + "/" + message.split("/").pop();
|
||||
} else {
|
||||
var message = "https://open.lbry.io/@" + msg.mentions.members.first().user.username
|
||||
var newname = name
|
||||
var message =
|
||||
"https://open.lbry.io/@" +
|
||||
msg.mentions.members.first().user.username;
|
||||
var newname = name;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var newname = message.replace("https://open.lbry.io/", "");
|
||||
}
|
||||
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 + ")",
|
||||
"color": 7976557,
|
||||
"author": {
|
||||
"name": "LBRY Linker",
|
||||
"icon_url": "https://i.imgur.com/yWf5USu.png"
|
||||
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 +
|
||||
")",
|
||||
color: 7976557,
|
||||
author: {
|
||||
name: "LBRY Linker",
|
||||
icon_url: "https://i.imgur.com/yWf5USu.png"
|
||||
}
|
||||
};
|
||||
msg.channel.send({
|
||||
embed
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
function GetWordByPos(str, pos) {
|
||||
|
@ -63,5 +76,5 @@ exports.lbrylink = function(bot, msg, suffix) {
|
|||
|
||||
return left + right;
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -1,115 +1,169 @@
|
|||
let jp = require('jsonpath');
|
||||
let moment = require('moment');
|
||||
let numeral = require('numeral');
|
||||
let request = require('request');
|
||||
let config = require('config');
|
||||
let needle = require('needle');
|
||||
let hasStatsBotChannels = require('../helpers.js').hasStatsBotChannels;
|
||||
let inPrivate = require('../helpers.js').inPrivate;
|
||||
let ChannelID = config.get('statsbot').mainchannel;
|
||||
let statsurl = "https://coinmarketcap.com/currencies/library-credit/"
|
||||
let jp = require("jsonpath");
|
||||
let moment = require("moment");
|
||||
let numeral = require("numeral");
|
||||
let request = require("request");
|
||||
let config = require("config");
|
||||
let needle = require("needle");
|
||||
let hasStatsBotChannels = require("../helpers.js").hasStatsBotChannels;
|
||||
let inPrivate = require("../helpers.js").inPrivate;
|
||||
let ChannelID = config.get("statsbot").mainchannel;
|
||||
let statsurl = "https://coinmarketcap.com/currencies/library-credit/";
|
||||
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 = {
|
||||
usage: "",
|
||||
description: 'Displays list of current Market stats',
|
||||
process: function(bot,msg){
|
||||
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var rank = data.rank
|
||||
var price_usd = Number(data.price_usd)
|
||||
var price_btc = Number(data.price_btc)
|
||||
var market_cap_usd = Number(data.market_cap_usd)
|
||||
var available_supply = Number(data.available_supply)
|
||||
var total_supply = Number(data.total_supply)
|
||||
var percent_change_1h = Number(data.percent_change_1h)
|
||||
var percent_change_24h = Number(data.percent_change_24h)
|
||||
var json = response.body[0];
|
||||
var newjson = parse_obj(json)
|
||||
var parse = JSON.stringify(newjson)
|
||||
var volume24_usd = parse.replace(/[^0-9]/g, '');
|
||||
var dt = new Date();
|
||||
var timestamp = dt.toUTCString();
|
||||
var hr_indicator = ":thumbsup:"
|
||||
var day_indicator =":thumbsup:"
|
||||
if (percent_change_1h < 0) {
|
||||
hr_indicator = ":thumbsdown:"
|
||||
}
|
||||
if (percent_change_24h < 0) {
|
||||
day_indicator = ":thumbsdown:"
|
||||
}
|
||||
usage: "",
|
||||
description: "Displays list of current Market stats",
|
||||
process: function(bot, msg) {
|
||||
needle.get(
|
||||
"https://api.coinmarketcap.com/v1/ticker/library-credit/",
|
||||
function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send("coinmarketcap API is not available");
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var rank = data.rank;
|
||||
var price_usd = Number(data.price_usd);
|
||||
var price_btc = Number(data.price_btc);
|
||||
var market_cap_usd = Number(data.market_cap_usd);
|
||||
var available_supply = Number(data.available_supply);
|
||||
var total_supply = Number(data.total_supply);
|
||||
var percent_change_1h = Number(data.percent_change_1h);
|
||||
var percent_change_24h = Number(data.percent_change_24h);
|
||||
var json = response.body[0];
|
||||
var newjson = parse_obj(json);
|
||||
var parse = JSON.stringify(newjson);
|
||||
var volume24_usd = parse.replace(/[^0-9]/g, "");
|
||||
var dt = new Date();
|
||||
var timestamp = dt.toUTCString();
|
||||
var hr_indicator = ":thumbsup:";
|
||||
var day_indicator = ":thumbsup:";
|
||||
if (percent_change_1h < 0) {
|
||||
hr_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) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_gbp = Number(data.price_gbp)
|
||||
needle.get('https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR', function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send('coinmarketcap API is not available');
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_eur = Number(data.price_eur)
|
||||
description = "**Rank: ["+rank+"]("+statsurl+")**\n" +
|
||||
"**Data**\n" +
|
||||
"Market Cap: [$"+numberWithCommas(market_cap_usd)+"]("+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" +
|
||||
"BTC: [₿"+price_btc.toFixed(8)+"]("+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" +
|
||||
"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, ",");
|
||||
}
|
||||
needle.get(
|
||||
"https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=GBP",
|
||||
function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send("coinmarketcap API is not available");
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_gbp = Number(data.price_gbp);
|
||||
needle.get(
|
||||
"https://api.coinmarketcap.com/v1/ticker/library-credit/?convert=EUR",
|
||||
function(error, response) {
|
||||
if (error || response.statusCode !== 200) {
|
||||
msg.channel.send("coinmarketcap API is not available");
|
||||
} else {
|
||||
var data = response.body[0];
|
||||
var price_eur = Number(data.price_eur);
|
||||
description =
|
||||
"**Rank: [" +
|
||||
rank +
|
||||
"](" +
|
||||
statsurl +
|
||||
")**\n" +
|
||||
"**Data**\n" +
|
||||
"Market Cap: [$" +
|
||||
numberWithCommas(market_cap_usd) +
|
||||
"](" +
|
||||
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" +
|
||||
"BTC: [₿" +
|
||||
price_btc.toFixed(8) +
|
||||
"](" +
|
||||
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" +
|
||||
"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, ",");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
"use strict";
|
||||
exports.commands = ["tip"];
|
||||
exports.tip = {
|
||||
usage: "<subcommand>",
|
||||
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",
|
||||
process: function(bot) {
|
||||
return; // Tipping is now handled by the separate tipbot(in branch tipbot_dc), no need to to anything here...
|
||||
}
|
||||
};
|
||||
"use strict";
|
||||
exports.commands = ["tip"];
|
||||
exports.tip = {
|
||||
usage: "<subcommand>",
|
||||
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",
|
||||
process: function(bot) {
|
||||
return; // Tipping is now handled by the separate tipbot(in branch tipbot_dc), no need to to anything here...
|
||||
}
|
||||
};
|
||||
|
|
531
package-lock.json
generated
531
package-lock.json
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue