prout
This commit is contained in:
parent
c7e0fc1c25
commit
6298b4331a
2 changed files with 22 additions and 5 deletions
|
@ -49,7 +49,7 @@ class Connection(Thread):
|
|||
"""
|
||||
connect to server
|
||||
"""
|
||||
self.client = xmpp.Client(self.server)
|
||||
self.client = xmpp.Client(self.server, debug=[])
|
||||
if not self.connect_to_server(self.server, self.port):
|
||||
log.error('Could not connect to server')
|
||||
sys.exit(-1)
|
||||
|
@ -59,6 +59,9 @@ class Connection(Thread):
|
|||
self.client.sendInitPresence()
|
||||
self.online = 1 # 2 when confirmation of auth is received
|
||||
self.register_handlers()
|
||||
self.muc = MultiUserChat(self.client)
|
||||
while 1:
|
||||
self.process()
|
||||
|
||||
def connect_to_server(self, server, port):
|
||||
# TODO proxy stuff
|
||||
|
@ -102,6 +105,9 @@ class Connection(Thread):
|
|||
# print '[%s] in room {%s}. (%s - %s)'% (nick_from, room_from, affil, role)
|
||||
self.handler.emit('xmpp-presence-handler', presence=presence)
|
||||
|
||||
def send_join_room(self, room, nick):
|
||||
self.handler.emit('join-room', room=room, nick=nick)
|
||||
|
||||
def handler_iq(self, connection, iq):
|
||||
pass
|
||||
|
||||
|
@ -111,6 +117,7 @@ class Connection(Thread):
|
|||
else:
|
||||
log.warning('disconnecting...')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
resource = config.get('resource')
|
||||
server = config.get('server')
|
||||
|
@ -124,6 +131,3 @@ if __name__ == '__main__':
|
|||
for room in rooms:
|
||||
connection.send_join_room(room.split('/')[0], room.split('/')[1])
|
||||
i = 17
|
||||
while i:
|
||||
connection.process()
|
||||
i -= 1
|
||||
|
|
15
src/gui.py
15
src/gui.py
|
@ -23,6 +23,8 @@ from curses import textpad
|
|||
|
||||
import sys
|
||||
|
||||
from connection import *
|
||||
|
||||
class Win(object):
|
||||
def __init__(self, height, width, y, x, parent_win):
|
||||
self._resize(height, width, y, x, parent_win)
|
||||
|
@ -190,7 +192,7 @@ class Gui(object):
|
|||
self.handler = Handler()
|
||||
|
||||
self.handler.connect('on-muc-message-received', self.on_message)
|
||||
self.handler.connect('join-room', self.on_join_room)
|
||||
self.handler.connect('gui-join-room', self.on_join_room)
|
||||
self.handler.connect('on-muc-presence-changed', self.on_presence)
|
||||
|
||||
self.init_curses(stdscr)
|
||||
|
@ -234,4 +236,15 @@ def main(stdscr):
|
|||
gui.main_loop(stdscr)
|
||||
|
||||
if __name__ == '__main__':
|
||||
resource = config.get('resource')
|
||||
server = config.get('server')
|
||||
connection = Connection(server, resource)
|
||||
connection.start()
|
||||
rooms = config.get('rooms').split(':')
|
||||
from time import sleep
|
||||
print connection.online
|
||||
sleep(2)
|
||||
print connection.online
|
||||
for room in rooms:
|
||||
connection.send_join_room(room.split('/')[0], room.split('/')[1])
|
||||
curses.wrapper(main)
|
||||
|
|
Loading…
Reference in a new issue