]> git.aero2k.de Git - urlbot-v3.git/commitdiff
ability to drop a searx
authorThorsten S <mail@aero2k.de>
Fri, 3 Jan 2020 15:09:24 +0000 (16:09 +0100)
committerThorsten S <mail@aero2k.de>
Fri, 3 Jan 2020 15:09:24 +0000 (16:09 +0100)
distbot/plugins/searx.py

index 802d0ba2841ceb953c890af12f2b29ae48600d59..1f4cdbc11662e1c3d4902cc89325adac06918282 100644 (file)
@@ -29,9 +29,9 @@ class RateLimitingError(HTTPError):
 
 
 class Searx(Worker):
-    binding_keys = ["nick.search.#"]
+    binding_keys = ["nick.search.#", "nick.next-searx"]
     description = "search the web (using searx)"
-    usage = "bot: search <terms>"
+    usage = "bot: search <terms> or bot: next-searx (to drop current searx engine)"
 
     search_list = []
 
@@ -100,18 +100,22 @@ class Searx(Worker):
         return [(r.get('content', ''), r['url'], url) for r in response['results']][0]
 
     def parse_body(self, msg):
-
-        result = self.searx(' '.join(get_words(msg)[1:]))
-        if not result:
-            return Action(msg='Sorry, no results.')
-        else:
-            abstract, url, provider = result
-
-        if len(abstract) > 150:
-            suffix = '…'
+        words = get_words(msg)
+        if words[1] == "next-searx":
+            searx_provider = self.search_list.pop(0)
+            return Action(msg='Ok. There goes {}'.format(searx_provider))
         else:
-            suffix = ''
-        return Action(msg='{}{} ({}) - powered by {}'.format(abstract[:150], suffix, url, provider))
+            result = self.searx(' '.join(words[1:]))
+            if not result:
+                return Action(msg='Sorry, no results.')
+            else:
+                abstract, url, provider = result
+
+            if len(abstract) > 150:
+                suffix = '…'
+            else:
+                suffix = ''
+            return Action(msg='{}{} ({}) - powered by {}'.format(abstract[:150], suffix, url, provider))
 
 
 ALL = [Searx]