changeset 2319:10ec0e8d35e1

Make send_notification accept a list of JIDs, instead of one.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sat, 23 Jun 2007 00:03:56 +0200
parents 062b76cf8d48
children 55196f5e7000
files jabberbot/commands.py jabberbot/xmlrpcbot.py jabberbot/xmppbot.py
diffstat 3 files changed, 34 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/jabberbot/commands.py	Sat Jun 23 00:01:56 2007 +0200
+++ b/jabberbot/commands.py	Sat Jun 23 00:03:56 2007 +0200
@@ -12,8 +12,8 @@
 # First, XML RPC -> XMPP commands
 class NotificationCommand:
     """Class representing a notification request"""
-    def __init__(self, jid, text):
-        self.jid = jid
+    def __init__(self, jids, text):
+        self.jids = jids
         self.text = text
         
 class AddJIDToRosterCommand:
--- a/jabberbot/xmlrpcbot.py	Sat Jun 23 00:01:56 2007 +0200
+++ b/jabberbot/xmlrpcbot.py	Sat Jun 23 00:03:56 2007 +0200
@@ -15,6 +15,9 @@
 import jabberbot.commands as cmd
 from jabberbot.multicall import MultiCall
 
+class ConfigurationError(Exception):
+    def __init__(self, message):
+        self.message = message
 
 class XMLRPCClient(Thread):
     """XMLRPC Client
@@ -28,6 +31,10 @@
         @param commands: an output command queue
         """
         Thread.__init__(self)
+        
+        if not config.secret:
+            raise ConfigurationError("You must set a (long) secret string!")
+        
         self.commands_in = commands_in
         self.commands_out = commands_out
         self.config = config
@@ -202,7 +209,12 @@
         Thread.__init__(self)
         self.commands = commands
         self.verbose = config.verbose
-        self.secret = config.secret
+        
+        if config.secret:
+            self.secret = config.secret
+        else:
+            raise ConfigurationError("You must set a (long) secret string")
+        
         self.server = SimpleXMLRPCServer((config.xmlrpc_host, config.xmlrpc_port))
         
     def run(self):
@@ -240,7 +252,7 @@
         return protected_func
     
     
-    def send_notification(self, jid, text):
+    def send_notification(self, jids, text):
         """Instructs the XMPP component to send a notification
         
         @param jid: a jid to send a message to (bare jid)
@@ -249,7 +261,7 @@
         @type text: unicode
         
         """
-        command = cmd.NotificationCommand(jid, text)
+        command = cmd.NotificationCommand(jids, text)
         self.commands.put_nowait(command)
         return True
     send_notification.export = True
--- a/jabberbot/xmppbot.py	Sat Jun 23 00:01:56 2007 +0200
+++ b/jabberbot/xmppbot.py	Sat Jun 23 00:03:56 2007 +0200
@@ -174,27 +174,28 @@
         
         """
         
-        if not command.jid:
+        if not command.jids:
             self.log("Received a command with empty jid, looks like a bug!")
             return
         
         # Handle normal notifications
         if isinstance(command, cmd.NotificationCommand):
-            jid = JID(node_or_jid=command.jid)
-            jid_text = jid.bare().as_utf8()
-            text = command.text
-            
-            # Check if contact is DoNotDisturb. 
-            # If so, queue the message for delayed delivery.
-            try:
-                contact = self.contacts[jid_text]
-                if contact.is_dnd() and not ignore_dnd:
-                    contact.messages.append(command)
-                    return
-            except KeyError:
-                pass
-            
-            self.send_message(jid, text)
+            for recipient in command.jids:
+                jid = JID(recipient)
+                jid_text = jid.bare().as_utf8()
+                text = command.text
+                
+                # Check if contact is DoNotDisturb. 
+                # If so, queue the message for delayed delivery.
+                try:
+                    contact = self.contacts[jid_text]
+                    if contact.is_dnd() and not ignore_dnd:
+                        contact.messages.append(command)
+                        return
+                except KeyError:
+                    pass
+                
+                self.send_message(jid, text)
             
         # Handle subscribtion management commands
         if isinstance(command, cmd.AddJIDToRosterCommand):