From 4d2b2eb650a50de630a5ad031730282c0f74aa8d Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 12 Feb 2019 03:32:53 +0530 Subject: [PATCH] Add /word, /words --- bot.js | 3 ++- commands/index.js | 6 ++++-- commands/words.js | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 commands/words.js diff --git a/bot.js b/bot.js index 52c0fc7..e7d5511 100644 --- a/bot.js +++ b/bot.js @@ -9,7 +9,8 @@ const data = [ "questions", "kys", "insults", - "commands_list" + "commands_list", + "words" ].map(file => fs.readFile(file + ".txt", "utf-8") .then(list => diff --git a/commands/index.js b/commands/index.js index a3636e1..2b88e7a 100644 --- a/commands/index.js +++ b/commands/index.js @@ -1,13 +1,15 @@ const random = require("./random"); const insults_fun = require("./insult"); +const words_fun = require("./words"); const is = require("./is"); -module.exports = (bot, [ questions, kys, insults, commands_list ]) => { +module.exports = (bot, [ questions, kys, insults, commands_list, words ]) => { bot.command("question", (ctx) => ctx.reply(random(questions)())); + bot.command("word", (ctx) => ctx.reply(random(words)())); + bot.command("words", (ctx) => ctx.reply(words_fun(random, words)(ctx))); bot.telegram.getMe() .then(bot_user => { - console.log(bot_user); const default_text = (command, text) => `Do you want to ${text} ` + `yourself?\nIf no, reply to someone with /${command} to kill` + ` them or run /${command} username/name.\nYou can suggest ` diff --git a/commands/words.js b/commands/words.js new file mode 100644 index 0000000..d7f6005 --- /dev/null +++ b/commands/words.js @@ -0,0 +1,21 @@ +module.exports = (random, words) => (ctx) => { + + const text_array = ctx.message.text.split(" "); + if (text_array.length == 1) { + + return random(words)(10); + + } else { + + const input = parseInt(text_array[1]); + if (input && input > 0) + if (input < 50) + return random(words)(input); + else + return "Too many words."; + else + return "Not a valid number."; + + } + +};