changeset 2393:ae44e3266486

s/search/searchform/, add a Search command (does nothing)
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 15 Jul 2007 05:38:11 +0200
parents ddb4c626062d
children 0f9b7b20fb9c
files jabberbot/commands.py jabberbot/xmppbot.py
diffstat 2 files changed, 34 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/commands.py	Sun Jul 15 05:14:06 2007 +0200
+++ b/jabberbot/commands.py	Sun Jul 15 05:38:11 2007 +0200
@@ -94,3 +94,13 @@
     def __init__(self, jid, pagename):
         BaseDataCommand.__init__(self, jid)
         self.pagename = pagename
+        
+class Search(BaseDataCommand):
+    
+    description = u"perform a wiki search"
+    parameter_list = u"{title|text} term"
+    
+    def __init__(self, jid, term, search_type):
+        BaseDataCommand.__init__(self, jid)
+        self.term = term
+        self.search_type = search_type
--- a/jabberbot/xmppbot.py	Sun Jul 15 05:14:06 2007 +0200
+++ b/jabberbot/xmppbot.py	Sun Jul 15 05:38:11 2007 +0200
@@ -132,8 +132,8 @@
         # A dictionary of contact objects, ordered by bare JID
         self.contacts = {}
 
-        self.known_xmlrpc_cmds = [cmd.GetPage, cmd.GetPageHTML, cmd.GetPageList, cmd.GetPageInfo]
-        self.internal_commands = ["ping", "help", "search"]
+        self.known_xmlrpc_cmds = [cmd.GetPage, cmd.GetPageHTML, cmd.GetPageList, cmd.GetPageInfo, cmd.Search]
+        self.internal_commands = ["ping", "help", "searchform"]
 
         self.xmlrpc_commands = {}
         for command, name in [(command, command.__name__) for command in self.known_xmlrpc_cmds]:
@@ -333,6 +333,8 @@
         """Handles internal commands, that can be completed by the XMPP bot itself
 
         @param command: list representing a command
+        @param sender: JID of sender
+        @type sender: pyxmpp.jid.JID
 
         """
         if command[0] == "ping":
@@ -342,16 +344,31 @@
                 return self.reply_help()
             else:
                 return self.help_on(command[1])
-        elif command[0] == "search":
+        elif command[0] == "searchform":
             jid = sender.bare().as_utf8()
             resource = sender.resource
             if self.contacts[jid].supports_forms(resource):
                 self.send_search_form(sender)
             else:
-                print "booo"
+                msg = u"This command requires a client supporting Data Forms"
+                self.send_message(sender, msg, u"Error")
         else:
             # For unknown command return a generic help message
             return self.reply_help()
+        
+    def do_search(self, jid, term, search_type):
+        """Performs a Wiki search of term
+        
+        @param jid: Jabber ID of user performing a search
+        @type jid: pyxmpp.jid.JID
+        @param term: term to search for
+        @type term: unicode
+        @param search_type: type of search; either "text" or "title"
+        @type search_type: unicode
+        
+        """
+        search = cmd.Search(jid, term, search_type)
+        self.from_commands.put_nowait(search)
 
     def help_on(self, command):
         """Returns a help message on a given topic
@@ -366,6 +383,9 @@
 
         elif command == "ping":
             return u"""The "ping" command returns a "pong" message as soon as it's received."""
+        
+        elif command == "searchform":
+            return u"""searchform - perform a wiki search using a form"""
 
         # Here we have to deal with help messages of external (xmlrpc) commands
         else:
@@ -376,7 +396,6 @@
             else:
                 return u"""Unknown command "%s" """ % (command,)
 
-
     def handle_xmlrpc_command(self, sender, command):
         """Creates a command object, and puts it the command queue