-
Notifications
You must be signed in to change notification settings - Fork 0
/
issue
executable file
·94 lines (65 loc) · 2.43 KB
/
issue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
import email.Parser, re, sys
from twisted.internet import reactor
from twisted.words.protocols.jabber import client, jid, xmlstream
from twisted.words.xish import domish
def rawDataIn(data):
print 'RECV: ' + data
def rawDataOut(data):
print 'SEND: ' + data
class Jabber:
def initFailed(self, failure):
self.xmlstream.sendFooter()
def presence(self, element):
parser = email.Parser.Parser()
message = parser.parse(sys.stdin)
match = re.search('^Issue (\\d+)', message['subject'])
issue = match.group(1)
match = re.search('^(?:New|Comment #(?:\\d+) on) issue ' + issue + ' by (.+?):.*?\n\n(.+?)\n\n--', message.get_payload(), re.M | re.S)
author = match.group(1)
comment = match.group(2)
if 80 < len(comment):
comment = comment[:77] + '...'
message = domish.Element((None, 'message'))
message['to'] = element['from']
body = message.addElement('body')
body.addContent(author)
body.addContent(' ')
body.addContent(issue)
body.addContent(' ')
body.addContent(comment)
html = message.addElement(('http://jabber.org/protocol/xhtml-im', 'html'))
body = html.addElement('body')
body.addContent(author)
body.addContent(' ')
a = body.addElement('a')
a['href'] = 'http://code.google.com/p/qubit-toolkit/issues/detail?id=' + issue
a.addContent(issue)
body.addContent(' ')
body.addContent(comment)
self.xmlstream.send(message)
self.xmlstream.sendFooter()
def authd(self, xmlstream):
self.xmlstream = xmlstream
self.xmlstream.addObserver('/presence', self.presence)
presence = domish.Element((None, 'presence'))
self.xmlstream.send(presence)
# Timeout
reactor.callLater(5, self.xmlstream.sendFooter)
def connected(self, xmlstream):
self.xmlstream = xmlstream
self.xmlstream.rawDataInFn = rawDataIn
self.xmlstream.rawDataOutFn = rawDataOut
def end(self, xmlstream):
self.xmlstream = xmlstream
reactor.stop()
jabber = Jabber()
jid = jid.JID('[email protected]')
password = 'example'
factory = client.XMPPClientFactory(jid, password)
factory.addBootstrap(xmlstream.INIT_FAILED_EVENT, jabber.initFailed)
factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, jabber.authd)
factory.addBootstrap(xmlstream.STREAM_CONNECTED_EVENT, jabber.connected)
factory.addBootstrap(xmlstream.STREAM_END_EVENT, jabber.end)
reactor.connectTCP('talk.google.com', 5222, factory)
reactor.run()