Skip to content

Commit

Permalink
bot provides help;say how many tacos you have left
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinleiba committed Apr 9, 2019
1 parent e635e86 commit 0fddc3a
Showing 1 changed file with 48 additions and 10 deletions.
58 changes: 48 additions & 10 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,59 @@ const forTaco = controller => {
};

const forScore = controller => {
controller.hears("score", "direct_mention", (bot, message) => {
const users = DB.getUsers();
const ranked = users.sort((a, b) => b.tacos - a.tacos);
const firsts = ranked.slice(0, 5).filter(u => u.tacos > 0);
const sentences = firsts.map(
(user, index) =>
`<@${user.id}> is n°${index + 1} with *${user.tacos}* tacos`
);
bot.reply(message, sentences.join("\n"));
});
controller.hears(
["score", "ranking"],
["direct_mention", "direct_message"],
(bot, message) => {
const users = DB.getUsers();
const ranked = users.sort((a, b) => b.tacos - a.tacos);
const firsts = ranked.slice(0, 5).filter(u => u.tacos > 0);
const sentences = firsts.map(
(user, index) =>
`<@${user.id}> is n°${index + 1} with *${user.tacos}* tacos`
);
bot.reply(message, sentences.join("\n"));
}
);
};

const forLeft = controller => {
controller.hears(
["left", "combien", "how much", "how many"],
"direct_message",
(bot, message) => {
const ids = DB.getIDs();
const userIndex = ids.indexOf(message.user);
const user = DB.getUser(userIndex);
bot.reply(message, `You have ${user.left} tacos left for today`);
}
);
};

const forHelp = controller => {
controller.hears(
["help", "aide", "commandes", "commande"],
["direct_message", "direct_mention"],
(bot, message) => {
bot.reply(
message,
`
In public channels, just ping someone and add the :taco: emoji next to his name.
You can ask me how many :taco: you have left but in direct message:
Just ask me \`left\` (or \`how many\`; \`how much\`)
If you want to know the ranking, ask me \`score\` or \`ranking\`
`
);
}
);
};

const listens = controller => {
forTaco(controller);
forScore(controller);
forLeft(controller);
forHelp(controller);
};

module.exports = {
Expand Down

0 comments on commit 0fddc3a

Please sign in to comment.