mirror of
http://aero2k.de/t/repos/urlbot-native.git
synced 2017-09-06 15:25:38 +02:00
rewrite of get_nick_from_object()
This commit is contained in:
24
common.py
24
common.py
@@ -5,6 +5,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import requests
|
import requests
|
||||||
from urllib.error import URLError
|
from urllib.error import URLError
|
||||||
|
import sleekxmpp
|
||||||
|
|
||||||
BUFSIZ = 8192
|
BUFSIZ = 8192
|
||||||
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) ' \
|
USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) ' \
|
||||||
@@ -96,11 +97,24 @@ def giphy(subject, api_key):
|
|||||||
|
|
||||||
|
|
||||||
def get_nick_from_object(message_obj):
|
def get_nick_from_object(message_obj):
|
||||||
"""
|
|
||||||
not quite correct yet, also the private property access isn't nice.
|
if isinstance(message_obj, sleekxmpp.Message):
|
||||||
"""
|
msg_type = message_obj.getType()
|
||||||
nick = message_obj['mucnick'] or message_obj['from']._jid[2]
|
|
||||||
return nick
|
if msg_type == "groupchat":
|
||||||
|
return message_obj.getMucnick()
|
||||||
|
elif msg_type == "chat":
|
||||||
|
jid = message_obj.getFrom()
|
||||||
|
return jid.resource
|
||||||
|
else:
|
||||||
|
raise Exception("Message, but not groupchat/chat")
|
||||||
|
|
||||||
|
elif isinstance(message_obj, sleekxmpp.Presence):
|
||||||
|
jid = message_obj.getFrom()
|
||||||
|
return jid.resource
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise Exception("Message type is: " + str(type(message_obj)))
|
||||||
|
|
||||||
|
|
||||||
def else_command(args):
|
def else_command(args):
|
||||||
|
|||||||
Reference in New Issue
Block a user