diff --git a/bot/modules/claimbot.js b/bot/modules/claimbot.js index bae2d93..8b50c9f 100644 --- a/bot/modules/claimbot.js +++ b/bot/modules/claimbot.js @@ -20,9 +20,7 @@ function init(discordBot_) { discordBot = discordBot_; console.log('Activating claimbot'); discordBot.channels.get(channels[0]).send('activating claimbot'); - setInterval(function() { - announceClaimsV2(); - }, 60 * 1000); + setInterval(announceClaimsV2, 60 * 1000); announceClaimsV2(); } @@ -32,8 +30,7 @@ function announceClaimsV2() { let currentBlock = lastProcessedBlock; claims.forEach(c => { if (c.height <= lastProcessedBlock) return; - currentBlock = c.height; - console.log(JSON.stringify(c, null, 4)); + currentBlock = Math.max(currentBlock, c.height); //filter claims that we don't want to announce if (c.bid_state === 'Expired' || c.bid_state === 'Spent') return; @@ -99,8 +96,15 @@ function embedFromClaim(claim) { */ function getClaimsForLastBlock() { return new Promise((resolve, reject) => { + let blockSelectQuery = 'SELECT height FROM block where height > ' + lastProcessedBlock; + if (lastProcessedBlock === 0) { + blockSelectQuery = 'SELECT MAX(height) AS height FROM block'; + } let query = - 'SELECT t1.*, t3.name AS channel_name, t4.value AS bid_amount FROM claim t1 INNER JOIN (SELECT MAX(height) AS height FROM block) t2 ON t1.height = t2.height LEFT JOIN claim t3 ON t1.publisher_id = t3.claim_id LEFT JOIN output t4 ON (t1.transaction_hash_id = t4.transaction_hash AND t1.vout = t4.vout)'; + 'SELECT t1.*, t3.name AS channel_name, t4.value AS bid_amount FROM claim t1 INNER JOIN (' + + blockSelectQuery + + ') t2 ON t1.height = t2.height ' + + 'LEFT JOIN claim t3 ON t1.publisher_id = t3.claim_id LEFT JOIN output t4 ON (t1.transaction_hash_id = t4.transaction_hash AND t1.vout = t4.vout)'; let options = { method: 'GET', url: 'https://chainquery.lbry.io/api/sql', diff --git a/bot/modules/commandsV2.js b/bot/modules/commandsV2.js index b35965a..3c0243a 100644 --- a/bot/modules/commandsV2.js +++ b/bot/modules/commandsV2.js @@ -32,19 +32,20 @@ let checkForCommand = function(message) { } //for each message go through all the commands and check if there are any matches Object.keys(commands).forEach(command => { - //during the first run also build the cache - if (firstRun) commandsList += command + ', '; - //if a command is found if (!message.author.bot && message.content.toLowerCase().indexOf(command.toLowerCase()) >= 0 && commands[command].operation === 'send') { //send a message to the channel according to the config message.channel.send('', new Discord.RichEmbed(commands[command].bundle)); } }); + if (firstRun) { + commandsList = Object.keys(commands) + .sort() + .join(', '); + } //if the user is requesting the list of commands, then print it if (!message.author.bot && message.content.toLowerCase().indexOf('!helpcommands') >= 0) { let bundle = commands['!helpcommands'].bundle; - commandsList = commandsList.replace(/,\s$/g, ''); bundle.description = '**' + commandsList + '**'; message.channel.send('', new Discord.RichEmbed(bundle)); } diff --git a/bot/modules/example.js b/bot/modules/example.js deleted file mode 100644 index 2f57332..0000000 --- a/bot/modules/example.js +++ /dev/null @@ -1,24 +0,0 @@ -/* -// Example #1 Command(use this to make your Commands with triggers like !demo) - exports.commands = [ - "demo" // command name that will be used for next lines of code below - ] - - exports.demo = { - usage: "", //command usage like !demo <@username>, exclude !demo - description: 'description of command', //the description of command for !help command - process: function(bot,msg,suffix){ - // Here the bot,msg and suffix is available, this function can be async if needed. - } - } - -// Example #2 Function(use this to make your Functions that dont need trigger words unlike !demo) - exports.custom = [ - "myFunction" //change this to your function name - ] - - exports.myFunction = function(bot) { - // Other functions that need to be ran once on bootup! - // For example a timed function and or some init stuff.. - } -*/ diff --git a/bot/modules/moderation.js b/bot/modules/moderation.js deleted file mode 100644 index 004f6a3..0000000 --- a/bot/modules/moderation.js +++ /dev/null @@ -1,15 +0,0 @@ -/*'use strict'; -// Moderation module, handles banning and kicking and more... -let hasPerms = require('../helpers.js').hasPerms; - -exports.commands = [ - "m" -] - -exports.m = { - usage: " ", - description: 'ban: bans the user with the reason\n kick: get adress for your deposits\n', - process: function(bot,msg,suffix){ - console.log(msg.member.user); - } -}*/ diff --git a/bot/modules/price.js b/bot/modules/price.js index 1931fe5..5928a7e 100644 --- a/bot/modules/price.js +++ b/bot/modules/price.js @@ -99,11 +99,6 @@ exports.price = { format: '$0,0.00', sign: 'NZD ' }, - PLN: { - steps: ['LBCBTC', 'BTCPLN'], - format: 'zł 0,0.00', - sign: 'zł' - }, RUB: { steps: ['LBCBTC', 'BTCRUB'], format: 'RUB 0,0.00', @@ -229,11 +224,6 @@ exports.price = { format: 'KM 0,0.00', sign: 'KM' }, - BAM: { - steps: ['LBCBTC', 'BTCBAM'], - format: 'KM 0,0.00', - sign: 'KM' - }, AZN: { steps: ['LBCBTC', 'BTCAZN'], format: '₼ 0,0.00', @@ -365,10 +355,6 @@ exports.price = { url: 'https://blockchain.info/ticker', path: '$.NZD.buy' }, - BTCPLN: { - url: 'https://blockchain.info/ticker', - path: '$.PLN.buy' - }, BTCRUB: { url: 'https://blockchain.info/ticker', path: '$.RUB.buy' @@ -553,29 +539,19 @@ exports.price = { msg.channel.send('Please use <#' + ChannelID + '> or DMs to talk to price bot.'); return; } - var message = - '**' + - command + - '**: show the price of 1 LBC in ' + - options.defaultCurrency + - '\n' + - '**' + - command + - ' help**: this message\n' + - '**' + - command + - ' CURRENCY**: show the price of 1 LBC in CURRENCY. Supported values for CURRENCY are Listed Below\n' + - '**' + - command + - ' CURRENCY AMOUNT**: show the price of AMOUNT LBC in CURRENCY\n' + - '**Supported Currencies:** *usd*, *gbp*, *eur*, *aud*, *brl*, *cad*, *chf*, *clp*, *cny*, *dkk*, *hkd*, *inr*, *isk*, *jpy*, *krw*, *nzd*, *pln* ,*rub*, *sek*, *sgd*, *thb*, *twd*, *myr*, *bnd*,*vnd*, *php*, *sar*, *mxn*, *try*, *mmk*, *khr*, *aed*, *zar*, *pgk*, *egp*,*nok*, *hrk*, *huf*, *all*, *gel*, *mdl*, *bam* ,*kzt*, *azn*, *amd*, *byn*, *btn*, *npr*, *bdt*, *pkr*, *ars*, *pln*, *idr* and *btc* (case-insensitive)'; + var message = `**${command}**: show the price of 1 LBC in ${options.defaultCurrency} +**${command} help**: this message +**${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 +**Supported Currencies:** *usd*, *gbp*, *eur*, *aud*, *brl*, *cad*, *chf*, *clp*, *cny*, *dkk*, *hkd*, *inr*, *isk*, *jpy*, *krw*, *nzd*, *pln* ,*rub*, *sek*, *sgd*, *thb*, *twd*, *myr*, *bnd*,*vnd*, *php*, *sar*, *mxn*, *try*, *mmk*, *khr*, *aed*, *zar*, *pgk*, *egp*,*nok*, *hrk*, *huf*, *all*, *gel*, *mdl*, *bam* ,*kzt*, *azn*, *amd*, *byn*, *btn*, *npr*, *bdt*, *pkr*, *ars*, *pln*, *idr* and *btc* (case-insensitive)`; msg.channel.send(message); } function formatMessage(amount, rate, option) { var cur = option.sign; 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}* +_last updated ${rate.time.utc().format(options.dtFormat)}_`; } function doSteps(bot, currency, amount) { @@ -605,7 +581,7 @@ exports.price = { if (steps.length > 0) { var pairName = steps[0]; 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; } @@ -641,7 +617,7 @@ exports.price = { cachedRates[currency] = result; msg.channel.send(formatMessage(amount, result, option)); } else { - msg.channel.send('The rate returned for the ' + pairName + ' pair was invalid.'); + msg.channel.send(`The rate returned for the ${pairName} pair was invalid.`); } }); } diff --git a/bot/modules/purge.js b/bot/modules/purge.js index a287ae5..e43cd56 100644 --- a/bot/modules/purge.js +++ b/bot/modules/purge.js @@ -1,6 +1,5 @@ let hasPerms = require('../helpers.js').hasPerms; let inPrivate = require('../helpers.js').inPrivate; - exports.commands = [ 'purge' // command that is in this file, every command needs it own export as shown below ]; diff --git a/bot/modules/reminder.js b/bot/modules/reminder.js deleted file mode 100644 index 45e44ee..0000000 --- a/bot/modules/reminder.js +++ /dev/null @@ -1,21 +0,0 @@ -/*exports.commands = [ - "remind" // command that is in this file, every command needs it own export as shown below -] - -exports.custom = [ - "checkReminders" -] - -exports.remind = { - usage: "