From 4f3a3744e66d6bc52d38ae13b1b5d146e952349c Mon Sep 17 00:00:00 2001 From: hagb4rd Date: Tue, 16 Aug 2016 18:48:45 +0200 Subject: [PATCH] feeling ducky search Update: Registered a new command as an equivalent replacement for googles no more working lucky search. Returns a link to the first result of a duckduckgo.com search. Usage: !s text Annotation: Like in google, results can be restricted to a specified site adding site: to the query text - this way, eventually more shortcut-commands could be added. Greetz ;) --- ecmabot.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ecmabot.js b/ecmabot.js index b33f30b..a24d61e 100644 --- a/ecmabot.js +++ b/ecmabot.js @@ -69,16 +69,27 @@ JSBot.prototype.init = function() { this.register_command("forget", Shared.forget, { allow_intentions: false, help: "Remove factoid from bot. Usage: !forget foo"}); + + this.register_command("s", this.ducky, { help: "Feeling Ducky Search | Usage: !s " }); this.register_command("commands", Shared.commands); - + + this.on('command_not_found', this.command_not_found); this.load_ecma_ref(); }; - +JSBot.prototype.ducky = function(context, text) { + if (!text) { + context.channel.send_reply (context.sender, this.get_command_help("s")); + return; + } + var ducky = function ducky(query) { return " search: " + query + " => https://duckduckgo.com/?q=!ducky+%q".replace("%q", encodeURI(query.replace(" ", "+"))) + " "; }; + context.channel.send_reply (context.intent, ducky(text)); + +}; JSBot.prototype.google = function(context, text) { if (!text) {