Add /word, /words

This commit is contained in:
Ceda EI 2019-02-12 03:32:53 +05:30
parent 1f6fc86faa
commit 4d2b2eb650
3 changed files with 27 additions and 3 deletions

3
bot.js
View File

@ -9,7 +9,8 @@ const data = [
"questions",
"kys",
"insults",
"commands_list"
"commands_list",
"words"
].map(file =>
fs.readFile(file + ".txt", "utf-8")
.then(list =>

View File

@ -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 `

21
commands/words.js Normal file
View File

@ -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.";
}
};