Begin of a /whois command. Also, ALSMO fixed 1710

parent 6796ebd9
......@@ -105,10 +105,11 @@ class Connection(threading.Thread):
"""
registers handlers from xmpppy signals
"""
self.client.RegisterHandler('iq', self.on_get_time, typ='get',
ns="urn:xmpp:time")
self.client.RegisterHandler('iq', self.on_get_version, typ='get',
ns=xmpp.NS_VERSION)
# self.client.RegisterHandler('iq', self.on_get_time, typ='get',
# ns="urn:xmpp:time")
self.client.RegisterHandler('iq', self.on_get_vcard)
# self.client.RegisterHandler('iq', self.on_get_version, typ='get',
# ns=xmpp.NS_VERSION)
self.client.RegisterHandler('presence', self.handler_presence)
self.client.RegisterHandler('message', self.handler_message)
......@@ -212,3 +213,11 @@ class Connection(threading.Thread):
if not connection:
return
self.handler.emit('send-time', iq_obj=iq)
def on_get_vcard(self, connection, iq):
"""
we received a vcard
"""
return
from common import debug
debug('\n====\n%s\n\n' % iq)
......@@ -97,6 +97,7 @@ class Gui(object):
'query': (self.command_query, _('Usage: /query <nick> [message]\nQuery: Open a private conversation with <nick>. This nick has to be present in the room you\'re currently in. If you specified a message after the nickname, it will immediately be sent to this user')),
'nick': (self.command_nick, _("Usage: /nick <nickname>\nNick: Change your nickname in the current room")),
'say': (self.command_say, _('Usage: /say <message>\nSay: Just send the message. Useful if you want your message to begin with a "/"')),
'whois': (self.command_whois, _('Usage: /whois <nickname>\nWhois: Request many informations about the user.')),
}
self.key_func = {
......@@ -157,6 +158,10 @@ class Gui(object):
while True:
doupdate()
char=read_char(stdscr)
try: # if this is not a valide utf-8 char, discard it
char.encode('utf-8')
except UnicodeDecodeError:
continue
# search for keyboard shortcut
if char in self.key_func.keys():
self.key_func[char]()
......@@ -646,6 +651,21 @@ class Gui(object):
msg = _('Unknown command: %s') % args[0]
self.add_message_to_room(room, msg)
def command_whois(self, arg):
"""
/whois <nickname>
"""
args = arg.split()
room = self.current_room()
if len(args) != 1:
self.add_message_to_room(room, _('whois command takes exactly one argument'))
return
# check if current room is a MUC
if room.jid or room.name == 'Info':
return
nickname = args[0]
self.muc.request_vcard(room.name, nickname)
def command_win(self, arg):
"""
/win <number>
......
......@@ -23,6 +23,8 @@ of the time ONE char, but may be longer if it's a keyboard
shortcut, like ^A, M-a or KEY_RESIZE)
"""
from common import debug
def get_next_byte(s):
"""
Read the next byte of the utf-8 char
......@@ -31,7 +33,7 @@ def get_next_byte(s):
c = s.getkey()
except:
return (None, "KEY_RESIZE")
if len(c) > 4:
if len(c) >= 4:
return (None, c)
return (ord(c), c)
......@@ -52,12 +54,15 @@ def read_char(s):
(first, c) = get_next_byte(s)
char = "M-"+c
if 194 <= first:
debug('1\n')
(code, c) = get_next_byte(s) # 2 bytes char
char += c
if 224 <= first:
debug('2\n')
(code, c) = get_next_byte(s) # 3 bytes char
char += c
if 240 <= first:
debug('3\n')
(code, c) = get_next_byte(s) # 4 bytes char
char += c
return char
......@@ -146,6 +146,14 @@ class MultiUserChat(object):
mes.setType('chat')
self.connection.send(mes)
def request_vcard(self, room_name, nickname):
"""
Request the vCard of an user, over a MUC or not
"""
request = Iq(typ='get', to='%s/%s'% (room_name, nickname))
vcard_tag = request.addChild(name='vCard', namespace='vcard-temp')
self.connection.send(request)
def join_room(self, room, nick, password=None):
"""Join a new room"""
pres = Presence(to='%s/%s' % (room, nick))
......@@ -161,8 +169,6 @@ class MultiUserChat(object):
history_tag.setAttr('maxchars', 0)
else:
history_tag.setAttr('maxstanzas', muc_history_length)
from common import debug
debug('%s\n'% pres)
self.connection.send(pres)
def quit_room(self, room, nick, msg=None):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment