1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2007-2012 Thomas Perl <thp.io/about>
4 # Copyright (C) 2014 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 .plugin import Plugin, botcmd
22 def __init__(self, bot):
23 Plugin.__init__(self, bot)
24 bot.add_event_handler("groupchat_message", self.muc_message)
25 # The groupchat_presence event is triggered whenever a
26 # presence stanza is received from any chat room, including
27 # any presences you send yourself. To limit event handling
28 # to a single room, use the events muc::room@server::presence,
29 # muc::room@server::got_online, or muc::room@server::got_offline.
30 #bot.add_event_handler("muc::%s::got_online" % self.bot.room, self.muc_online)
32 def muc_message(self, msg):
34 Process incoming message stanzas from any chat room. Be aware
35 that if you also have any handlers for the 'message' event,
36 message stanzas may be processed by both handlers, so check
37 the 'type' attribute when using a 'message' event handler.
39 Whenever the bot's nickname is mentioned, respond to
42 IMPORTANT: Always check that a message is not from yourself,
43 otherwise you will create an infinite loop responding
46 This handler will reply to messages that mention
50 msg -- The received message stanza. See the documentation
51 for stanza objects and the Message stanza to see
54 if msg['mucnick'] != self.bot.nick and self.bot.nick in msg['body']:
55 self.bot.send_message(mto=msg['from'].bare,
56 mbody="I heard that, %s." % msg['mucnick'],
59 def muc_online(self, presence):
61 Process a presence stanza from a chat room. In this case,
62 presences from users that have just come online are
63 handled by sending a welcome message that includes
64 the user's nickname and role in the room.
67 presence -- The received presence stanza. See the
68 documentation for the Presence stanza
69 to see how else it may be used.
71 if presence['muc']['nick'] != self.bot.nick:
72 self.bot.send_message(mto=presence['from'].bare,
73 mbody="Hello, %s %s" % (presence['muc']['role'],
74 presence['muc']['nick']),
78 def tell(self, message, args):
82 # vim: ai ts=4 sw=4 sts=4 expandtab