-
Notifications
You must be signed in to change notification settings - Fork 0
/
identiway.py
executable file
·72 lines (61 loc) · 2.49 KB
/
identiway.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging
import time
import sleekxmpp
from statusnet import StatusNet
if sys.version_info < (3, 0):
reload(sys)
sys.setdefaultencoding('utf8')
class IdentiWay(sleekxmpp.ClientXMPP):
"""
An XMPP client which acts as a simple gateway for Identica/StatusNet.
"""
def __init__(self, jid, password):
sleekxmpp.ClientXMPP.__init__(self, jid, password)
self.add_event_handler("session_start", self.start)
self.add_event_handler("message", self.message)
self.api_conns = {}
self.api_conns["reality@jabber.rootbash.com"] = StatusNet("http://identi.ca/api", "reality", "")
def start(self, event):
self.send_presence()
self.get_roster()
def message(self, msg):
from_root = str(msg['from']).split('/')[0]
if str(msg['body'])[0] == '/':
tokens = msg['body'][1:].split()
if tokens[0] == 'identify':
print 'eh'
elif tokens[0] == 'version':
msg.reply("You're currently talking to reality's super sexy xmpp bridge <3")
else:
try:
self.api_conns[from_root].statuses_update(msg['body'], "reality's super sexy xmpp bridge <3")
msg.reply("Message Sent.").send()
except:
msg.reply("You haven't registered your Identi.ca account. Type '/identify <api path> <username> <password>'.")
if __name__ == '__main__':
xmpp = IdentiWay("realibridge@jabber.rootbash.com", "")
xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0004') # Data Forms
xmpp.register_plugin('xep_0060') # PubSub
xmpp.register_plugin('xep_0199') # XMPP Ping
# If you are working with an OpenFire server, you may need
# to adjust the SSL version used:
# xmpp.ssl_version = ssl.PROTOCOL_SSLv3
# If you want to verify the SSL certificates offered by a server:
# xmpp.ca_certs = "path/to/ca/cert"
# Connect to the XMPP server and start processing XMPP stanzas.
if xmpp.connect():
# If you do not have the pydns library installed, you will need
# to manually specify the name of the server if it does not match
# the one in the JID. For example, to use Google Talk you would
# need to use:
#
# if xmpp.connect(('talk.google.com', 5222)):
# ...
xmpp.process(threaded=False)
print("Done")
else:
print("Unable to connect.")