1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2010, 2011 Anaƫl Verrier <elghinn@free.fr>
4 # Copyright (C) 2014, 2020 kaliko <kaliko@azylum.org>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, version 3 only.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from .sid import botcmd
23 Simple Plugin object to derive from:
25 * Exposes the bot object and its logger
26 * Provides send helpers
28 :param sid.sid.MUCBot bot: bot the plugin is load from
31 def __init__(self, bot):
33 self.log = bot.log.getChild(self.__class__.__name__)
35 def send(self, dest, msg, mtype='chat'):
38 :param str dest: Message recipient
39 :param dict,str msg: Message to send (use dict for xhtml-im)
42 if **msg** is a :py:obj:`dict` to provide xhmlt-im massages::
46 mhtml: '<b>text</b>, # optional'
49 if isinstance(msg, str):
51 msg.setdefault('mhtml', None)
52 self.bot.send_message(mto=dest,
56 def reply(self, rcv, msg):
57 """Smart reply to message received.
59 Replies ``msg`` in private or on the muc depending on ``rcv``
61 :param rcv: The received message (slixmpp object)
62 :param dict,str msg: The message to reply, refer to :py:obj:`sid.plugin.Plugin.send` for ``msg`` format
65 if rcv['type'] == 'groupchat':
67 self.send(to, msg, mtype=rcv['type'])