]> kaliko git repositories - sid.git/blobdiff - sid/plugin.py
Now handles private msg in MUC
[sid.git] / sid / plugin.py
index 2b49bc9da22c9d3a57f1c02a6793da770a3c1221..447e7033647ba6ffe5dc1e89f9f47488f4b1d05e 100644 (file)
 
 from .sid import botcmd
 
-class Plugin(object):
+class Plugin:
+    """Simple Plugin object to derive from:
+        Exposes the bot object and its logger
+        Provides some send helpers
+    """
 
     def __init__(self, bot):
         self.bot = bot
         self.log = bot.log
 
-    def send(self, msg):
-        """
-        Send msg to the current groupchat defined in self.bot.room
+    def send(self, dest, msg, mtype='chat'):
+        """Send msg to dest
             msg = {
                 mbody: 'text',
                 mhtml: '<b>text</b>,  # optional'
@@ -34,9 +37,18 @@ class Plugin(object):
         if isinstance(msg, str):
             msg = {'mbody':msg}
         msg.setdefault('mhtml', None)
-        self.bot.send_message(mto=self.bot.room,
-                              mtype='groupchat',
+        self.bot.send_message(mto=dest,
+                              mtype=mtype,
                               **msg)
 
+    def reply(self, rcv, msg):
+        """Smart reply to message received.
+        Replies <msg> in private or on the muc depending on <rcv>
+        """
+        to = rcv['from']
+        if rcv['type'] == 'groupchat':
+            to = rcv['mucroom']
+        self.send(to, msg, mtype=rcv['type'])
+
     def shutdown(self):
         pass