Building Slack Bots by Paul Asjes

Building Slack Bots by Paul Asjes

Author:Paul Asjes
Language: eng
Format: epub, pdf
Publisher: Packt Publishing


To store the user's win, we use the Redis client's zincrby method, which will increment the winner's score by one. Note how we can specify how much to increment by in the second argument. If the key (the winner's name here) doesn't exist in the set, it is automatically created with the score 0 and then incremented by the specified amount.

To retrieve the scoreboard, lets add the following:

bot.respondTo('scoreboard', (message, channel) => { client.zrevrange('rollscores', 0, -1, 'withscores', (err, set) => { if (err) { channel.send('Oops, something went wrong! Please try again later'); return; } let scores = []; // format the set into something a bit easier to use for (let i = 0; i < set.length; i++) { scores.push([set[i], set[i + 1]]); i++; } channel.send('The current scoreboard is:'); scores.forEach((score, index) => { channel.send(`${index + 1}. ${score[0]} with ${score[1]} points.`); }); }); }, true);



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.