slight fix up

This commit is contained in:
MSFTserver 2017-10-26 11:32:00 -07:00 committed by GitHub
parent 5e1d22b0e0
commit f421163d4e

View file

@ -14,31 +14,34 @@ 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 ChannelID = '369896313082478594'
var options = { var options = {
defaultCurrency: 'USD', defaultCurrency: 'USD',
// supported currencies and api steps to arrive at the final value // supported currencies and api steps to arrive at the final value
currencies: { currencies: {
USD: { steps: ['LBCBTC', 'BTCUSD'], format: '$0,0.00', sign: '' }, USD: { steps: ['LBCBTC', 'BTCUSD'], format: '$0,0.00', sign: 'USD $' },
GBP: { steps: ['LBCBTC', 'BTCGBP'], format: '£0,0.00', sign: '£' }, GBP: { steps: ['LBCBTC', 'BTCGBP'], format: '£0,0.00', sign: '£' },
AUD: { steps: ['LBCBTC', 'BTCAUD'], format: '$0,0.00', sign: '' }, AUD: { steps: ['LBCBTC', 'BTCAUD'], format: '$0,0.00', sign: 'AUD $' },
BRL: { steps: ['LBCBTC', 'BTCBRL'], format: 'R$0,0.00', sign: 'R$' }, BRL: { steps: ['LBCBTC', 'BTCBRL'], format: 'R$0,0.00', sign: 'R$' },
CAD: { steps: ['LBCBTC', 'BTCCAD'], format: '$0,0.00', sign: '' }, CAD: { steps: ['LBCBTC', 'BTCCAD'], format: '$0,0.00', sign: 'CAD $' },
CHF: { steps: ['LBCBTC', 'BTCCHF'], format: 'CHF 0,0.00', sign: 'CHF' }, CHF: { steps: ['LBCBTC', 'BTCCHF'], format: 'CHF 0,0.00', sign: 'CHF' },
CLP: { steps: ['LBCBTC', 'BTCCLP'], format: '$0,0.00', sign: '' }, CLP: { steps: ['LBCBTC', 'BTCCLP'], format: '$0,0.00', sign: 'CLP $' },
CNY: { steps: ['LBCBTC', 'BTCCNY'], format: '¥0,0.00', sign: '¥' }, CNY: { steps: ['LBCBTC', 'BTCCNY'], format: '¥0,0.00', sign: '¥' },
DKK: { steps: ['LBCBTC', 'BTCDKK'], format: 'kr 0,0.00', sign: 'kr' }, DKK: { steps: ['LBCBTC', 'BTCDKK'], format: 'kr 0,0.00', sign: 'kr' },
EUR: { steps: ['LBCBTC', 'BTCEUR'], format: '€0,0.00', sign: '€' }, EUR: { steps: ['LBCBTC', 'BTCEUR'], format: '€0,0.00', sign: '€' },
HKD: { steps: ['LBCBTC', 'BTCHKD'], format: '$0,0.00', sign: '' }, HKD: { steps: ['LBCBTC', 'BTCHKD'], format: '$0,0.00', sign: 'HKD $' },
INR: { steps: ['LBCBTC', 'BTCINR'], format: '₹0,0.00', sign: '₹' }, INR: { steps: ['LBCBTC', 'BTCINR'], format: '₹0,0.00', sign: '₹' },
ISK: { steps: ['LBCBTC', 'BTCISK'], format: 'kr 0,0.00', sign: 'kr' }, ISK: { steps: ['LBCBTC', 'BTCISK'], format: 'kr 0,0.00', sign: 'kr' },
JPY: { steps: ['LBCBTC', 'BTCJPY'], format: '¥0,0.00', sign: '¥' }, JPY: { steps: ['LBCBTC', 'BTCJPY'], format: '¥0,0.00', sign: '¥' },
KRW: { steps: ['LBCBTC', 'BTCKRW'], format: '₩0,0.00', sign: '₩' }, KRW: { steps: ['LBCBTC', 'BTCKRW'], format: '₩0,0.00', sign: '₩' },
NZD: { steps: ['LBCBTC', 'BTCNZD'], format: '$0,0.00', sign: '' }, NZD: { steps: ['LBCBTC', 'BTCNZD'], format: '$0,0.00', sign: 'NZD $' },
PLN: { steps: ['LBCBTC', 'BTCPLN'], format: 'zł 0,0.00', sign: 'zł' }, PLN: { steps: ['LBCBTC', 'BTCPLN'], format: 'zł 0,0.00', sign: 'zł' },
RUB: { steps: ['LBCBTC', 'BTCRUB'], format: 'RUB 0,0.00', sign: 'RUB' }, RUB: { steps: ['LBCBTC', 'BTCRUB'], format: 'RUB 0,0.00', sign: 'RUB' },
SEK: { steps: ['LBCBTC', 'BTCSEK'], format: 'kr 0,0.00', sign: 'kr' }, SEK: { steps: ['LBCBTC', 'BTCSEK'], format: 'kr 0,0.00', sign: 'kr' },
SGD: { steps: ['LBCBTC', 'BTCSGD'], format: '$0,0.00', sign: '' }, SGD: { steps: ['LBCBTC', 'BTCSGD'], format: '$0,0.00', sign: 'SGD $' },
THB: { steps: ['LBCBTC', 'BTCTHB'], format: '฿0,0.00', sign: '฿' }, THB: { steps: ['LBCBTC', 'BTCTHB'], format: '฿0,0.00', sign: '฿' },
TWD: { steps: ['LBCBTC', 'BTCTWD'], format: 'NT$0,0.00', sign: 'NT$' }, TWD: { steps: ['LBCBTC', 'BTCTWD'], format: 'NT$0,0.00', sign: 'NT$' },
IDR: { steps: ['LBCBTC', 'BTCIDR'], format: 'Rp0,0.00', sign: 'Rp' }, IDR: { steps: ['LBCBTC', 'BTCIDR'], format: 'Rp0,0.00', sign: 'Rp' },
@ -95,10 +98,18 @@ var command = "!price"
if (showHelp) { if (showHelp) {
doHelp(bot,msg,suffix); doHelp(bot,msg,suffix);
} else { } else {
if(!inPrivateOrBotSandbox(msg)){
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
return;
}
doSteps(bot, currency, amount); doSteps(bot, currency, amount);
} }
function doHelp(bot,msg,suffix) { function doHelp(bot,msg,suffix) {
if(!inPrivateOrBotSandbox(msg)){
msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.');
return;
}
var message = var message =
'**' + command + '**: show the price of 1 LBC in ' + options.defaultCurrency + '\n' + '**' + command + '**: show the price of 1 LBC in ' + options.defaultCurrency + '\n' +
'**' + command + ' help**: this message\n' + '**' + command + ' help**: this message\n' +
@ -111,7 +122,7 @@ function doHelp(bot,msg,suffix) {
function formatMessage(amount, rate, option) { function formatMessage(amount, rate, option) {
var cur = option.sign; var cur = option.sign;
var value = numeral(rate.rate * amount).format(option.format); var value = numeral(rate.rate * amount).format(option.format);
return '*' + numeral(amount).format('0,0[.][00000000]') + ' LBC = ' + cur +' ' + value + '*\n_last updated ' + rate.time.utc().format(options.dtFormat) + '_'; return '*' + numeral(amount).format('0,0[.][00000000]') + ' LBC = ' + cur +' ' + value + '*\n_last updated ' + rate.time.utc().format(options.dtFormat) + '_';
} }
function doSteps(bot, currency, amount) { function doSteps(bot, currency, amount) {
@ -179,5 +190,14 @@ function processSteps(bot, currency, rate, amount, steps, option) {
}); });
} }
} }
function inPrivateOrBotSandbox(msg){
if((msg.channel.type == 'dm') || (msg.channel.id === ChannelID)){
return true;
}else{
return false;
}
}
} }
} }