]> git.aero2k.de Git - urlbot-v3.git/commitdiff
searx that
authorThorsten <mail@aero2k.de>
Thu, 18 Mar 2021 18:33:01 +0000 (19:33 +0100)
committerThorsten <mail@aero2k.de>
Thu, 18 Mar 2021 18:33:01 +0000 (19:33 +0100)
distbot/plugins/searx.py

index 6382e77f5277ffd961a3fd6d1de1c73ea9792ed1..96e2725e7622697443f3939df396f3c095e34121 100644 (file)
@@ -27,9 +27,10 @@ class RateLimitingError(HTTPError):
 
 
 class Searx(Worker):
-    binding_keys = ["nick.search.#", "nick.next-searx"]
+    binding_keys = ["nick.search.#", "nick.search.that", "nick.next-searx", "nick.next.searx"] + Worker.CATCH_ALL
+    uses_history = True
     description = "search the web (using searx)"
-    usage = "bot: search <terms> or bot: next-searx (to drop current searx engine)"
+    usage = "bot: search <terms|that> or bot: next searx (to drop current searx engine)"
 
     search_list = []
 
@@ -99,21 +100,26 @@ class Searx(Worker):
 
     def parse_body(self, msg):
         words = get_words(msg)
-        if words[0] == "next-searx":
+        if words[0] == "next-searx" or words[0:2] == ["next", "searx"]:
             searx_provider = self.search_list.pop(0)
             return Action(msg='Ok. There goes {}'.format(searx_provider))
-        else:
+        elif words == ["search", "that"]:
+            result = self.searx(self.history[-1]['body'])
+        elif words[0] == "search":
             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))
+        else:
+            return
+
+        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]