summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-07 00:28:47 +0000
committerlouiz@4325f9fc-e183-4c21-96ce-0ab188b42d13 <louiz@4325f9fc-e183-4c21-96ce-0ab188b42d13>2010-08-07 00:28:47 +0000
commit6b92b3cffd9b976018b7c68f2a2b3d0b5880e9e6 (patch)
tree61eee9cbaf39670abbe758fa10793f80fe6dd082
parent6796ebd99867bae16dd4bbaa23ec23a6105b0abc (diff)
downloadpoezio-6b92b3cffd9b976018b7c68f2a2b3d0b5880e9e6.tar.gz
poezio-6b92b3cffd9b976018b7c68f2a2b3d0b5880e9e6.tar.bz2
poezio-6b92b3cffd9b976018b7c68f2a2b3d0b5880e9e6.tar.xz
poezio-6b92b3cffd9b976018b7c68f2a2b3d0b5880e9e6.zip
Begin of a /whois command. Also, ALSMO fixed 1710
-rw-r--r--src/connection.py17
-rw-r--r--src/gui.py20
-rw-r--r--src/keyboard.py7
-rw-r--r--src/multiuserchat.py10
4 files changed, 47 insertions, 7 deletions
diff --git a/src/connection.py b/src/connection.py
index c2af4446..224b7632 100644
--- a/src/connection.py
+++ b/src/connection.py
@@ -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)
diff --git a/src/gui.py b/src/gui.py
index da3f066a..21d69a0a 100644
--- a/src/gui.py
+++ b/src/gui.py
@@ -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>
diff --git a/src/keyboard.py b/src/keyboard.py
index 8e341bc6..90bd79ef 100644
--- a/src/keyboard.py
+++ b/src/keyboard.py
@@ -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
diff --git a/src/multiuserchat.py b/src/multiuserchat.py
index 0fbedd72..7429d2bd 100644
--- a/src/multiuserchat.py
+++ b/src/multiuserchat.py
@@ -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):