X-Git-Url: https://git.kaliko.me/?a=blobdiff_plain;f=sid%2Fplugin.py;h=3e7c87e63714e57e4bd9775b249239dea9a8a2d3;hb=bb9811987721c5443ec1b8f23a3bc47ac1604823;hp=671df850cdd73ea3edf7420fcfcd0cfa21b4442b;hpb=8050b8698ff1f6294abceb8b022a4aecdbe8375e;p=sid.git
diff --git a/sid/plugin.py b/sid/plugin.py
index 671df85..3e7c87e 100644
--- a/sid/plugin.py
+++ b/sid/plugin.py
@@ -17,10 +17,38 @@
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.getChild(self.__class__.__name__)
+
+ def send(self, dest, msg, mtype='chat'):
+ """Send msg to dest
+ msg = {
+ mbody: 'text',
+ mhtml: 'text, # optional'
+ }
+ """
+ if isinstance(msg, str):
+ msg = {'mbody':msg}
+ msg.setdefault('mhtml', None)
+ self.bot.send_message(mto=dest,
+ mtype=mtype,
+ **msg)
+
+ def reply(self, rcv, msg):
+ """Smart reply to message received.
+ Replies in private or on the muc depending on
+ """
+ to = rcv['from']
+ if rcv['type'] == 'groupchat':
+ to = rcv['mucroom']
+ self.send(to, msg, mtype=rcv['type'])
def shutdown(self):
pass