mirror of
https://github.com/LBRYFoundation/lbry-wunderbot.git
synced 2025-08-23 17:47:27 +00:00
replace var with let for price.js and purge.js
This commit is contained in:
parent
1411fb28c9
commit
13385b38df
2 changed files with 25 additions and 24 deletions
|
@ -14,7 +14,7 @@ exports.price = {
|
||||||
usage: '<currency> <amount>',
|
usage: '<currency> <amount>',
|
||||||
description: 'displays price of lbc',
|
description: 'displays price of lbc',
|
||||||
process: function(bot, msg, suffix) {
|
process: function(bot, msg, suffix) {
|
||||||
var options = {
|
let options = {
|
||||||
defaultCurrency: 'BTC',
|
defaultCurrency: 'BTC',
|
||||||
|
|
||||||
// supported currencies and api steps to arrive at the final value
|
// supported currencies and api steps to arrive at the final value
|
||||||
|
@ -503,22 +503,22 @@ exports.price = {
|
||||||
// refresh rate in milliseconds to retrieve a new price (default to 10 minutes)
|
// refresh rate in milliseconds to retrieve a new price (default to 10 minutes)
|
||||||
refreshTime: 100000
|
refreshTime: 100000
|
||||||
};
|
};
|
||||||
var words = suffix
|
let words = suffix
|
||||||
.trim()
|
.trim()
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.filter(function(n) {
|
.filter(function(n) {
|
||||||
return n !== '';
|
return n !== '';
|
||||||
});
|
});
|
||||||
|
|
||||||
var currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency;
|
let currency = words.length > 0 ? words[0].toUpperCase() : options.defaultCurrency;
|
||||||
var amount = words.length > 1 ? parseFloat(words[1], 10) : 1;
|
let amount = words.length > 1 ? parseFloat(words[1], 10) : 1;
|
||||||
var showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1;
|
let showHelp = isNaN(amount) || Object.keys(options.currencies).indexOf(currency) === -1;
|
||||||
// store the last retrieved rate
|
// store the last retrieved rate
|
||||||
var cachedRates = {};
|
let cachedRates = {};
|
||||||
var command = '!price';
|
let command = '!price';
|
||||||
|
|
||||||
var currencies = Object.keys(options.currencies);
|
let currencies = Object.keys(options.currencies);
|
||||||
for (var i = 0; i < currencies.length; i++) {
|
for (let i = 0; i < currencies.length; i++) {
|
||||||
cachedRates[currencies[i]] = {
|
cachedRates[currencies[i]] = {
|
||||||
rate: 0,
|
rate: 0,
|
||||||
time: null
|
time: null
|
||||||
|
@ -539,7 +539,7 @@ exports.price = {
|
||||||
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
|
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency}
|
let message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency}
|
||||||
**${command} help**: this message
|
**${command} help**: this message
|
||||||
**${command} CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below
|
**${command} CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below
|
||||||
**${command} CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY
|
**${command} CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY
|
||||||
|
@ -548,28 +548,28 @@ exports.price = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatMessage(amount, rate, option) {
|
function formatMessage(amount, rate, option) {
|
||||||
var cur = option.sign;
|
let cur = option.sign;
|
||||||
var value = numeral(rate.rate * amount).format(option.format);
|
let value = numeral(rate.rate * amount).format(option.format);
|
||||||
return `*${numeral(amount).format('0,0[.][00000000]')} LBC = ${cur} ${value}*
|
return `*${numeral(amount).format('0,0[.][00000000]')} LBC = ${cur} ${value}*
|
||||||
_last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
_last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doSteps(bot, currency, amount) {
|
function doSteps(bot, currency, amount) {
|
||||||
var option = options.currencies[currency];
|
let option = options.currencies[currency];
|
||||||
var shouldReload = true;
|
let shouldReload = true;
|
||||||
if (cachedRates[currency]) {
|
if (cachedRates[currency]) {
|
||||||
var cache = cachedRates[currency];
|
let cache = cachedRates[currency];
|
||||||
shouldReload = cache.time === null || moment().diff(cache.time) >= options.refreshTime;
|
shouldReload = cache.time === null || moment().diff(cache.time) >= options.refreshTime;
|
||||||
if (!shouldReload) {
|
if (!shouldReload) {
|
||||||
var message = formatMessage(amount, cache, option);
|
let message = formatMessage(amount, cache, option);
|
||||||
msg.channel.send(message);
|
msg.channel.send(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldReload) {
|
if (shouldReload) {
|
||||||
// copy the steps array
|
// copy the steps array
|
||||||
var steps = [];
|
let steps = [];
|
||||||
for (var i = 0; i < option.steps.length; i++) {
|
for (let i = 0; i < option.steps.length; i++) {
|
||||||
steps.push(option.steps[i]);
|
steps.push(option.steps[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -579,19 +579,19 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
||||||
|
|
||||||
function processSteps(bot, currency, rate, amount, steps, option) {
|
function processSteps(bot, currency, rate, amount, steps, option) {
|
||||||
if (steps.length > 0) {
|
if (steps.length > 0) {
|
||||||
var pairName = steps[0];
|
let pairName = steps[0];
|
||||||
if (!options.api[pairName]) {
|
if (!options.api[pairName]) {
|
||||||
msg.channel.send(`There was a configuration error. ${pairName} pair was not found.`);
|
msg.channel.send(`There was a configuration error. ${pairName} pair was not found.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var pair = options.api[pairName];
|
let pair = options.api[pairName];
|
||||||
request.get(pair.url, function(error, response, body) {
|
request.get(pair.url, function(error, response, body) {
|
||||||
if (error) {
|
if (error) {
|
||||||
msg.channel.send(err.message ? err.message : 'The request could not be completed at this time. Please try again later.');
|
msg.channel.send(err.message ? err.message : 'The request could not be completed at this time. Please try again later.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var pairRate = 0;
|
let pairRate = 0;
|
||||||
try {
|
try {
|
||||||
pairRate = jp.query(JSON.parse(body), pair.path);
|
pairRate = jp.query(JSON.parse(body), pair.path);
|
||||||
if (Array.isArray(pairRate) && pairRate.length > 0) {
|
if (Array.isArray(pairRate) && pairRate.length > 0) {
|
||||||
|
@ -610,7 +610,7 @@ _last updated ${rate.time.utc().format(options.dtFormat)}_`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// final step, cache and then response
|
// final step, cache and then response
|
||||||
var result = {
|
let result = {
|
||||||
rate: rate,
|
rate: rate,
|
||||||
time: moment()
|
time: moment()
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,12 +13,13 @@ exports.purge = {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hasPerms(msg)) {
|
if (hasPerms(msg)) {
|
||||||
|
let newamount = 0
|
||||||
if (!suffix) {
|
if (!suffix) {
|
||||||
var newamount = '2';
|
newamount = 2;
|
||||||
} else {
|
} else {
|
||||||
let amount = Number(suffix);
|
let amount = Number(suffix);
|
||||||
let adding = 1;
|
let adding = 1;
|
||||||
var newamount = amount + adding;
|
newamount = amount + adding;
|
||||||
}
|
}
|
||||||
let messagecount = newamount.toString();
|
let messagecount = newamount.toString();
|
||||||
msg.channel
|
msg.channel
|
||||||
|
|
Loading…
Add table
Reference in a new issue