# -*- coding: utf-8 -*-
# Copyright (C) 2010, 2011 Anaƫl Verrier <elghinn@free.fr>
-# Copyright (C) 2014 kaliko <kaliko@azylum.org>
+# Copyright (C) 2014, 2020 kaliko <kaliko@azylum.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
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
+ self.log = bot.log.getChild(self.__class__.__name__)
+
+ def send(self, dest, msg, mtype='chat'):
+ """Send msg to dest
+ msg = {
+ mbody: 'text',
+ mhtml: '<b>text</b>, # 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 <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