Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@helldev.net>2019-01-03 07:36:46 +0300
committerJohn Smith <mrdoctorwho@helldev.net>2019-01-03 07:36:46 +0300
commit137e36b111f77e653b4eb09314d77f902a7c57cc (patch)
treebb232f28c0eae762be0e788d4c64557b08bf2fc7
parenta84c6f3d64a874dca61b414bb8502701bdd36099 (diff)
attempt to fix errors with not receiving user names
-rw-r--r--extensions/attachments.py4
-rw-r--r--extensions/groupchats.py2
-rw-r--r--extensions/user_nickname.py2
-rw-r--r--gateway.py6
-rw-r--r--library/vkapi.py6
5 files changed, 11 insertions, 9 deletions
diff --git a/extensions/attachments.py b/extensions/attachments.py
index 164041a..7fd30cf 100644
--- a/extensions/attachments.py
+++ b/extensions/attachments.py
@@ -53,9 +53,9 @@ def parseAttachments(self, msg, spacer=""):
if self.settings.parse_wall:
tid = current.get("to_id", 1)
if tid > 0:
- name = "%s's" % self.vk.getUserData(tid)["name"]
+ name = "%s's" % self.vk.getUserData(tid).get("name", "Unknown User (%s)" % tid)
else:
- name = "ā€œ%sā€" % self.vk.getGroupData(tid)["name"]
+ name = "ā€œ%sā€" % self.vk.getGroupData(tid).get("name", "Unknown Group (%s)" % tid)
body += "Post on %s wall:\n" % name
if current.get("text") or current.get("copy_text"):
body += spacer + uhtml(compile_eol.sub("\n" + spacer, current["text"] or current.get("copy_text"))) + "\n"
diff --git a/extensions/groupchats.py b/extensions/groupchats.py
index ddeaa80..851c25f 100644
--- a/extensions/groupchats.py
+++ b/extensions/groupchats.py
@@ -397,7 +397,7 @@ class Chat(object):
return False
@staticmethod
- @api.attemptTo(3, dict, RuntimeError)
+ @api.repeat(3, dict, RuntimeError)
def getVKChat(user, id):
"""
Get vk chat by id
diff --git a/extensions/user_nickname.py b/extensions/user_nickname.py
index 2d160db..0eb7088 100644
--- a/extensions/user_nickname.py
+++ b/extensions/user_nickname.py
@@ -16,7 +16,7 @@ def add_username(stanza, user, uid):
key = "name"
if user.settings.use_nicknames:
key = "screen_name"
- name = user.vk.getUserData(uid)[key]
+ name = user.vk.getUserData(uid).get(key, "Unknown User: %s" % uid)
stanza.setTag("nick", namespace=xmpp.NS_NICK)
stanza.setTagData("nick", name)
diff --git a/gateway.py b/gateway.py
index 1430ae5..1ee3c44 100644
--- a/gateway.py
+++ b/gateway.py
@@ -575,6 +575,7 @@ class VK(object):
return data
@utils.cache
+ @api.repeat(3, dict, RuntimeError)
def getUserData(self, uid, fields=None):
"""
Gets user data. Such as name, photo, etc
@@ -595,7 +596,8 @@ class VK(object):
if data:
data = data[0]
data["name"] = self.formatName(data)
- return data
+ return data
+ raise RuntimeError("Unable to get the user's name")
def sendMessage(self, body, id, mType="user_id", more={}):
"""
@@ -1215,7 +1217,7 @@ def loop():
"""
while ALIVE:
try:
- Component.iter(6)
+ Component.iter(1)
except Exception:
logger.critical("disconnected")
crashLog("component.iter")
diff --git a/library/vkapi.py b/library/vkapi.py
index 20ff06c..6c54116 100644
--- a/library/vkapi.py
+++ b/library/vkapi.py
@@ -53,7 +53,7 @@ except ImportError:
logger.warning("vkapi: ujson wasn't loaded, using simplejson instead")
-def attemptTo(maxRetries, resultType, *errors):
+def repeat(maxRetries, resultType, *errors):
"""
Tries to execute function ignoring specified errors specified number of
times and returns specified result type on try limit.
@@ -110,7 +110,7 @@ class AsyncHTTPRequest(httplib.HTTPSConnection):
self.headers = headers or {}
self.created = time.time()
- @attemptTo(REQUEST_RETRIES, None, *ERRORS)
+ @repeat(REQUEST_RETRIES, None, *ERRORS)
def open(self):
self.connect()
self.request(("POST" if self.data else "GET"), self.url, self.data,
@@ -193,7 +193,7 @@ class RequestProcessor(object):
request = urllib2.Request(url, data, headers)
return request
- @attemptTo(REQUEST_RETRIES, tuple, *ERRORS)
+ @repeat(REQUEST_RETRIES, tuple, *ERRORS)
def post(self, url, data=None, urlencode=True):
"""
POST request