annotate MoinMoin/jabber/xmppbot.py @ 2088:a99ed13fec1e

Introduce a shared secret for wiki-bot communication + some code style fixes.
author Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
date Sun, 03 Jun 2007 19:44:56 +0200
parents d72f126157f7
children 4ec961fd40d9
rev   line source
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
2 """
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
3 MoinMoin - a XMPP bot
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
4
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
5 This is a bot for notification and simple editing
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
6 operations. Developed as a Google Summer of Code
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
7 project.
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
8
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
9 @copyright: 2007 by Karol Nowak <grywacz@gmail.com>
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
10 @license: GNU GPL, see COPYING for details.
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
11 """
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
12
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
13 import time
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
14 import Queue
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
15 from threading import Thread
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
16
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
17 from pyxmpp.client import Client
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
18 from pyxmpp.jid import JID
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
19 from pyxmpp.streamtls import TLSSettings
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
20 from pyxmpp.message import Message
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
21
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
22 from xmlrpcbot import NotificationCommand
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
23
2088
a99ed13fec1e Introduce a shared secret for wiki-bot communication + some code style fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2085
diff changeset
24
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
25 class Contact:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
26 """Abstraction of a roster item / contact
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
27
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
28 This class handles some logic related to keeping track of
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
29 contact availability, status, etc."""
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
30
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
31 def __init__(self, jid, resource, priority, show):
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
32 self.jid = jid
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
33 self.resources = { resource: {'show': show, 'priority': priority} }
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
34
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
35 # Queued messages, waiting for contact to change its "show"
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
36 # status to something different than "dnd". The messages should
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
37 # also be sent when contact becomes "unavailable" directly from
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
38 # "dnd", as we can't guarantee, that the bot will be up and running
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
39 # the next time she becomes "available".
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
40 self.messages = []
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
41
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
42 def add_resource(self, resource, show, priority):
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
43 """Adds information about a connected resource"""
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
44 self.resources[resource] = {'show': show, 'priority': priority}
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
45
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
46 def remove_resource(self, resource):
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
47 """Removes information about a connected resource"""
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
48
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
49 if self.resources.has_key(resource):
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
50 del self.resources[resource]
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
51 else:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
52 raise ValueError("No such resource!")
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
53
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
54 def is_dnd(self):
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
55 """Checks if contact is DoNotDisturb
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
56
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
57 The contact is DND if its resource with the highest priority is DND
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
58 """
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
59
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
60 # Priority can't be lower than -128
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
61 max_prio = -129
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
62 max_prio_show = u"dnd"
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
63
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
64 for resource in self.resources.itervalues():
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
65 # TODO: check RFC for behaviour of 2 resources with the same priority
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
66 if resource['priority'] > max_prio:
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
67 max_prio = resource['priority']
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
68 max_prio_show = resource['show']
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
69
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
70 if max_prio_show == u'dnd':
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
71 return True
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
72 else:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
73 return False
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
74
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
75 def set_show(self, resource, show):
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
76 """Sets show property for a given resource
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
77
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
78 @param resource: resource to alter
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
79 @param show: new value of the show property
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
80 @raise ValueError: no resource with given name has been found
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
81 """
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
82 if self.resources.has_key(resource):
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
83 self.resources[resource]['show'] = show
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
84 else:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
85 raise ValueError("There's no such resource")
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
86
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
87 def uses_resource(self, resource):
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
88 """Checks if contact uses a given resource"""
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
89 return self.resources.has_key(resource)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
90
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
91 def __str__(self):
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
92 retval = "%s (%s) has %d queued messages"
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
93 res = ", ".join([name + " is " + res['show'] for name, res in self.resources.items()])
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
94 return retval % (self.jid.as_utf8(), res, len(self.messages))
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
95
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
96
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
97 class XMPPBot(Client, Thread):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
98 """A simple XMPP bot"""
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
99
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
100 def __init__(self, config, from_commands, to_commands):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
101 """A constructor.
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
102
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
103 @param from_commands: a Queue object used to send commands to other (xmlrpc) threads
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
104 @param to_commands: a Queue object used to receive commands from other threads
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
105 """
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
106
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
107 Thread.__init__(self)
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
108
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
109 self.from_commands = from_commands
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
110 self.to_commands = to_commands
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
111 jid = u"%s@%s/%s" % (config.xmpp_node, config.xmpp_server, config.xmpp_resource)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
112
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
113 self.config = config
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
114 self.jid = JID(node_or_jid=jid, domain=config.xmpp_server, resource=config.xmpp_resource)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
115 self.tlsconfig = TLSSettings(require = True, verify_peer = False)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
116
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
117 # A dictionary of contact objects, ordered by bare JID
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
118 self.contacts = { }
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
119
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
120 Client.__init__(self, self.jid, config.xmpp_password, config.xmpp_server, tls_settings = self.tlsconfig)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
121
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
122 def run(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
123 """Start the bot - enter the event loop"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
124
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
125 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
126 self.log("Starting the jabber bot.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
127
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
128 self.connect()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
129 self.loop()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
130
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
131 def loop(self, timeout=1):
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
132 """Main event loop - stream and command handling"""
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
133
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
134 while 1:
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
135 stream = self.get_stream()
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
136 if not stream:
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
137 break
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
138
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
139 act = stream.loop_iter(timeout)
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
140 if not act:
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
141 # Process all available commands
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
142 while self.poll_commands(): pass
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
143 self.idle()
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
144
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
145 def poll_commands(self):
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
146 """Checks for new commands in the input queue and executes them
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
147
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
148 @return: True if any command has been executed, False otherwise."""
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
149
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
150 try:
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
151 command = self.to_commands.get_nowait()
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
152 self.handle_command(command)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
153 return True
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
154 except Queue.Empty:
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
155 return False
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
156
2081
6c3ae1a407a0 Fix message delivery to contacts that become unavailable directly from dnd.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
157 def handle_command(self, command, ignore_dnd = False):
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
158 """Excecutes commands from other components"""
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
159
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
160 if isinstance(command, NotificationCommand):
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
161 jid = JID(node_or_jid=command.jid)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
162 jid_text = jid.bare().as_utf8()
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
163 text = command.text
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
164
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
165 # Check if contact is DoNotDisturb.
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
166 # If so, queue the message for delayed delivery.
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
167 try:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
168 contact = self.contacts[jid_text]
2081
6c3ae1a407a0 Fix message delivery to contacts that become unavailable directly from dnd.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
169 if contact.is_dnd() and not ignore_dnd:
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
170 contact.messages.append(command)
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
171 return
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
172 except KeyError:
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
173 pass
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
174
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
175 self.send_message(jid, text)
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
176
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
177 def send_message(self, jid, text, msg_type=u"chat"):
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
178 """Sends a message
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
179
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
180 @param jid: JID to send the message to
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
181 @param text: message's body
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
182 @param type: message type, as defined in RFC"""
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
183
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
184 message = Message(to_jid = jid, body = text, stanza_type=msg_type)
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
185 self.get_stream().send(message)
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
186
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
187 def handle_message(self, message):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
188 """Handles incoming messages"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
189
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
190 if self.config.verbose:
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
191 msg = "Message from %s." % (message.get_from_jid().as_utf8(),)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
192 self.log(msg)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
193
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
194 text = message.get_body()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
195 sender = message.get_from_jid()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
196 command = text.split()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
197
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
198 # Ignore empty commands
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
199 if len(command) == 0:
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
200 return
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
201
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
202 response = self.reply_help()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
203
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
204 if not response == u"":
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
205 self.send_message(sender, response)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
206
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
207 def handle_unavailable_presence(self, stanza):
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
208 """Handles unavailable presence stanzas"""
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
209
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
210 if self.config.verbose:
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
211 self.log("Handling unavailable presence.")
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
212
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
213 jid = stanza.get_from_jid()
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
214 bare_jid = jid.bare().as_utf8()
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
215
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
216 # If we get presence, this contact should already be known
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
217 if bare_jid in self.contacts:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
218 contact = self.contacts[bare_jid]
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
219
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
220 if self.config.verbose:
2088
a99ed13fec1e Introduce a shared secret for wiki-bot communication + some code style fixes.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2085
diff changeset
221 self.log("%s, going OFFLINE." % contact)
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
222
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
223 try:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
224 # Send queued messages now, as we can't guarantee to be
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
225 # alive the next time this contact becomes available.
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
226 if len(contact.resources) == 1:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
227 self.send_queued_messages(contact, ignore_dnd=True)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
228 del self.contacts[bare_jid]
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
229 else:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
230 contact.remove_resource(jid.resource)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
231
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
232 # The highest-priority resource, which used to be DnD might
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
233 # have gone offline. If so, try to deliver messages now.
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
234 if not contact.is_dnd():
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
235 self.send_queued_messages(contact)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
236
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
237 except ValueError:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
238 self.log("Unknown contact (resource) going offline...")
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
239
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
240 else:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
241 self.log("Unavailable presence from unknown contact.")
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
242
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
243 # Confirm that we've handled this stanza
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
244 return True
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
245
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
246 def handle_available_presence(self, presence):
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
247 """Handles available presence stanzas"""
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
248 if self.config.verbose:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
249 self.log("Handling available presence.")
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
250
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
251 show = presence.get_show()
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
252 priority = presence.get_priority()
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
253 jid = presence.get_from_jid()
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
254 bare_jid = jid.bare().as_utf8()
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
255
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
256 if bare_jid in self.contacts:
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
257 contact = self.contacts[bare_jid]
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
258
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
259 # The resource is already known, so update it
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
260 if contact.uses_resource(jid.resource):
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
261 contact.set_show(jid.resource, show)
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
262
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
263 # Unknown resource, add it to the list
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
264 else:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
265 contact.add_resource(jid.resource, show, priority)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
266
2085
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
267 if self.config.verbose:
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
268 self.log(contact)
d72f126157f7 Make Contact.resources a dictionary, fix a bug in updating of show property
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2083
diff changeset
269
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
270 # Either way check, if we can deliver queued messages now
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
271 if not contact.is_dnd():
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
272 self.send_queued_messages(contact)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
273
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
274 else:
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
275 self.contacts[bare_jid] = Contact(jid, jid.resource, priority, show)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
276
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
277 if self.config.verbose:
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
278 self.log(self.contacts[bare_jid])
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
279
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
280 # Confirm that we've handled this stanza
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
281 return True
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
282
2081
6c3ae1a407a0 Fix message delivery to contacts that become unavailable directly from dnd.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
283 def send_queued_messages(self, contact, ignore_dnd = False):
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
284 """Sends messages queued for the contact"""
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
285 for command in contact.messages:
2081
6c3ae1a407a0 Fix message delivery to contacts that become unavailable directly from dnd.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2077
diff changeset
286 self.handle_command(command, ignore_dnd)
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
287
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
288 def reply_help(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
289 """Constructs a generic help message
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
290
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
291 It's sent in response to an uknown message or the "help" command."""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
292
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
293 return u"""Hello there! I'm a MoinMoin Notification Bot. Too bad I can't say anything more (yet!)."""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
294
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
295 def log(self, message):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
296 """Logs a message and its timestamp"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
297
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
298 t = time.localtime( time.time() )
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
299 print time.strftime("%H:%M:%S", t), message
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
300
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
301 def authenticated(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
302 """Called when authentication succeedes"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
303
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
304 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
305 self.log("Authenticated.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
306
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
307 def authorized(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
308 """Called when authorization succeedes"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
309
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
310 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
311 self.log("Authorized.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
312
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
313 stream = self.get_stream()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
314 stream.set_message_handler("normal", self.handle_message)
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
315 stream.set_presence_handler("available", self.handle_available_presence)
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
316 stream.set_presence_handler("unavailable", self.handle_unavailable_presence)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
317
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
318 self.request_session()
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
319
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
320 def connected(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
321 """Called when connections has been established"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
322
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
323 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
324 self.log("Connected.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
325
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
326 def disconnected(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
327 """Called when disconnection occurs"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
328
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
329 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
330 self.log("Disconnected.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
331
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
332 def roster_updated(self, item = None):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
333 """Called when roster gets updated"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
334
2076
0128bbaf0172 Add newlines at the end of files, fix some overzealous deletion.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2070
diff changeset
335 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
336 self.log("Updating roster.")
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
337
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
338 contacts = [ str(c) for c in self.roster.get_items() ]
2077
636e646f909b Make jabber bot aware of contacts' presence.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2076
diff changeset
339 print "Groups:", self.roster.get_groups()
2083
9c66c85a6a70 Fix some reasonable stuff suggested by pylint.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2082
diff changeset
340 print "Contacts:", " ".join(contacts)
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
341
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
342 # def session_started(self):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
343 # """Called when session has been successfully started"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
344 #
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
345 # if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
346 # self.log("Session started.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
347
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
348 def stream_closed(self, stream):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
349 """Called when stream closes"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
350
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
351 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
352 self.log("Stream closed.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
353
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
354 def stream_created(self, stream):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
355 """Called when stream gets created"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
356
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
357 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
358 self.log("Stream created.")
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
359
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
360 def stream_error(self, error):
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
361 """Called when stream error gets received"""
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
362
2070
4e123eb32380 Handle inbound xmlrpc traffic, send notifications. This is only a beginning. ;)
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents: 2067
diff changeset
363 if self.config.verbose:
2067
3ca2b7065a05 Jabber bot - the beginning.
Karol 'grzywacz' Nowak <grzywacz@sul.uni.lodz.pl>
parents:
diff changeset
364 self.log("Received a stream error.")