Add /expand
This commit is contained in:
		
							
								
								
									
										32
									
								
								commands/expand.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								commands/expand.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,32 @@ | |||||||
|  | function expand(words, text) { | ||||||
|  |  | ||||||
|  | 	const letters = text.trim().toLowerCase().split(""); | ||||||
|  | 	return letters.map((letter) => { | ||||||
|  |  | ||||||
|  | 		const wordsWithLetter = words.filter(i => i.match(RegExp(`^${letter}`, "i"))); | ||||||
|  | 		const word = wordsWithLetter[Math.floor(Math.random() * wordsWithLetter.length)]; | ||||||
|  | 		return word; | ||||||
|  |  | ||||||
|  | 	}).reduce((acc, cur) => acc + " " + cur); | ||||||
|  |  | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | module.exports = (words = []) => (ctx) => { | ||||||
|  |  | ||||||
|  | 	const message = ctx.message.text.replace(/^[^ ]+/, ""); | ||||||
|  | 	if (message) { | ||||||
|  |  | ||||||
|  | 		return expand(words, message); | ||||||
|  |  | ||||||
|  | 	} else { | ||||||
|  |  | ||||||
|  | 		if (ctx.message.reply_to_message) | ||||||
|  | 			return expand(words, ctx.message.reply_to_message.text); | ||||||
|  | 		else | ||||||
|  | 			return "Need text to expand. Send /expand text or reply to a " | ||||||
|  | 			+ "message with /expand"; | ||||||
|  |  | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | }; | ||||||
| @@ -7,9 +7,9 @@ const absurdify = require("./absurdify"); | |||||||
| const feedback = require("./feedback"); | const feedback = require("./feedback"); | ||||||
| const media_wiki = require("./media_wiki"); | const media_wiki = require("./media_wiki"); | ||||||
| const info = require("./info"); | const info = require("./info"); | ||||||
|  | const expand = require("./expand"); | ||||||
|  |  | ||||||
| module.exports = (bot, [ questions, kys, insults, commands_list, words ], | module.exports = (bot, [ questions, kys, insults, commands_list, words ], feedback_id, axios) => { | ||||||
| 	feedback_id, axios) => { |  | ||||||
|  |  | ||||||
| 	bot.command("question", (ctx) => ctx.reply(random(questions)())); | 	bot.command("question", (ctx) => ctx.reply(random(questions)())); | ||||||
| 	bot.command("word", (ctx) => ctx.reply(random(words)())); | 	bot.command("word", (ctx) => ctx.reply(random(words)())); | ||||||
| @@ -60,6 +60,7 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words ], | |||||||
| 		"https://wiki.archlinux.org/api.php")(ctx).then(x => ctx.reply(x, | 		"https://wiki.archlinux.org/api.php")(ctx).then(x => ctx.reply(x, | ||||||
| 		{parse_mode: "HTML"}))); | 		{parse_mode: "HTML"}))); | ||||||
| 	bot.command("info", (ctx) => ctx.reply(info()(ctx), {parse_mode: "Markdown"})); | 	bot.command("info", (ctx) => ctx.reply(info()(ctx), {parse_mode: "Markdown"})); | ||||||
|  | 	bot.command("expand", (ctx) => ctx.reply(expand(words)(ctx))); | ||||||
| 	bot.command("start", (ctx) => ctx.reply("Hi, I am Quadnite. If you are " | 	bot.command("start", (ctx) => ctx.reply("Hi, I am Quadnite. If you are " | ||||||
| 		+ "chatting with me in private, you are most likely doing it wrong. " | 		+ "chatting with me in private, you are most likely doing it wrong. " | ||||||
| 		+ "Add me to a group for fun. To give feedback, use /feedback")); | 		+ "Add me to a group for fun. To give feedback, use /feedback")); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user