diff options
author | John Smith <mrdoctorwho@helldev.net> | 2021-10-13 18:02:25 +0300 |
---|---|---|
committer | John Smith <mrdoctorwho@helldev.net> | 2021-10-13 18:02:25 +0300 |
commit | fcf43fd1dcbfdf1dfa96e1700ab8f70880db4da1 (patch) | |
tree | d2e55f442155c260d6d4b2aa8e433cc1e308c788 | |
parent | e62597d79c15cab2ba1d62457b5943e4ad30d542 (diff) |
Fix chatting with groups
-rw-r--r-- | extensions/user_nickname.py | 2 | ||||
-rw-r--r-- | gateway.py | 12 | ||||
-rw-r--r-- | library/longpoll.py | 6 | ||||
-rw-r--r-- | library/vkapi.py | 2 | ||||
-rw-r--r-- | modules/mod_iq_last.py | 2 | ||||
-rw-r--r-- | modules/mod_iq_vcard.py | 49 |
6 files changed, 22 insertions, 51 deletions
diff --git a/extensions/user_nickname.py b/extensions/user_nickname.py index 0eb7088..391778d 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).get(key, "Unknown User: %s" % uid) + name = user.vk.getData(uid).get(key, "Unknown User: %s" % uid) stanza.setTag("nick", namespace=xmpp.NS_NICK) stanza.setTagData("nick", name) @@ -258,7 +258,7 @@ class VK(object): def __init__(self, token=None, source=None): self.token = token self.source = source - self.pollConfig = {"mode": 66, "wait": 30, "act": "a_check"} + self.pollConfig = {"mode": 66, "wait": 30, "act": "a_check", "version": 3} self.pollServer = "" self.pollInitialized = False self.engine = None @@ -595,7 +595,6 @@ class VK(object): raise RuntimeError("Unable to get group data for %d" % gid) @utils.cache - @api.repeat(3, dict, RuntimeError) def getUserData(self, uid, fields=None): """ Gets user data. Such as name, photo, etc @@ -622,11 +621,14 @@ class VK(object): raise RuntimeError("Unable to get the user's name for %d" % uid) def getName(self, id_): + return self.getData(id_).get("name", "Unknown group (id: %s)" % id_) + + def getData(self, id_, fields=None): if id_ > 0: - name = self.getUserData(id_).get("name", "Unknown user (id: %s)" % id_) + data = self.getUserData(id_, fields) else: - name = self.getGroupData(id_).get("name", "Unknown group (id: %s)" % id_) - return name + data = self.getGroupData(id_, fields) + return data def sendMessage(self, body, id, mType="user_id", more={}): """ diff --git a/library/longpoll.py b/library/longpoll.py index e62b1e0..74cfcd9 100644 --- a/library/longpoll.py +++ b/library/longpoll.py @@ -107,7 +107,9 @@ def processPollResult(user, data): if typ == TYPE_MSG: # new message message = None - mid, flags, uid, date, subject, body, attachments = evt + mid, flags, uid, date, body, subject, attachments = evt + if subject: + subject = subject.get("title") out = flags & FLAG_OUT chat = (uid > MIN_CHAT_UID) # a groupchat always has uid > 2000000000 # there is no point to request messages if there's only a single emoji attachment @@ -121,7 +123,7 @@ def processPollResult(user, data): utils.runThread(user.sendMessages, (False, message, mid - 1, uid), "sendMessages-%s" % user.source) elif typ == TYPE_MSG_READ_OUT: - uid, mid = evt + uid, mid, _ = evt cache = user.msgCacheByUser.get(uid) if cache: xmppMID = cache["xmpp"] diff --git a/library/vkapi.py b/library/vkapi.py index 05188e0..867afe2 100644 --- a/library/vkapi.py +++ b/library/vkapi.py @@ -31,7 +31,7 @@ APP_ID = 3789129 # VK APP scope SCOPE = 69638 # VK API VERSION -API_VERSION = "5.120" +API_VERSION = "5.131" socket.setdefaulttimeout(SOCKET_TIMEOUT) diff --git a/modules/mod_iq_last.py b/modules/mod_iq_last.py index 4120585..fa9df5e 100644 --- a/modules/mod_iq_last.py +++ b/modules/mod_iq_last.py @@ -20,7 +20,7 @@ def last_handler(cl, iq): elif source in Users and id in Users[source].friends: last = Users[source].vk.method("execute.getLastTime", {"uid": id}) or 0 last = int(time.time() - last) - name = Users[source].vk.getUserData(id).get("name", "Unknown") + name = Users[source].vk.getName(id) else: raise xmpp.NodeProcessed() result = xmpp.Iq("result", to=jidFrom, frm=destination) diff --git a/modules/mod_iq_vcard.py b/modules/mod_iq_vcard.py index f0f8deb..21c87bc 100644 --- a/modules/mod_iq_vcard.py +++ b/modules/mod_iq_vcard.py @@ -9,7 +9,7 @@ VCARD_SEMAPHORE = threading.Semaphore() DESCRIPTION = "VK4XMPP Transport\n© simpleApps, 2013 — 2016." GITHUB_URL = "https://github.com/mrDoctorWho/vk4xmpp" -BIRTHDAY = "30.09.2013" +BIRTHDAY = "30.08.2013" KEY_NICKNAME = "NICKNAME" KEY_NAME = "FN" @@ -38,15 +38,14 @@ VCARD_TEMPLATE = {KEY_NICKNAME: IDENTIFIER["short"], KEY_DESC: DESCRIPTION, KEY_PHOTO: URL_VCARD_NO_IMAGE, KEY_URL: GITHUB_URL, - KEY_BDAY: None, + KEY_BDAY: BIRTHDAY, KEY_CTRY: "United States", # database.getCountriesById and database.getCitiesById KEY_PHONE_HOME: None, KEY_PHONE_MOBILE: None, - KEY_LOCALITY: "Los Angeles" # you'd love it here (yeah, here...) + KEY_LOCALITY: {"title": "Los Angeles"} # you'd love it here (yeah, here...) } - VCARD_FIELDS = {KEY_NICKNAME: "screen_name", KEY_NAME: "name", KEY_URL: "https://vk.com/id%(id)s", @@ -55,36 +54,12 @@ VCARD_FIELDS = {KEY_NICKNAME: "screen_name", KEY_LOCALITY: "city", KEY_PHONE_HOME: "home_phone", KEY_PHONE_MOBILE: "mobile_phone", -# KEY_URL: "site", + KEY_URL: "site", KEY_PHOTO: PhotoSize, KEY_DESC: None, } -def getLocationString(id, key, user): - """ - Get country or city name by id - Args: - id: the id to get string for - key: whether to get country or city name - user: the User object - Returns: - Country/city name, - """ - if user: - if key == KEY_CTRY: - method = "database.getCountriesById" - arg = "country_ids" - else: - method = "database.getCitiesById" - arg = "city_ids" - data = user.vk.method(method, {arg: id}) - if data: - data = data[0] - return data["name"] - return id - - def buildVcard(data, template=VCARD_TEMPLATE, fields=VCARD_FIELDS, user=None): """ Builds a vcard. @@ -102,16 +77,10 @@ def buildVcard(data, template=VCARD_TEMPLATE, fields=VCARD_FIELDS, user=None): if key == KEY_PHOTO: photo = vcard.setTag(KEY_PHOTO) photo.setTagData(KEY_BINVAL, utils.getLinkData(value)) - # todo: find a proper way to handle this - elif key == KEY_URL: - if user: - vcard.setTagData(key, fields[key] % data) - else: - vcard.setTagData(key, fields[key]) elif key in (KEY_CTRY, KEY_LOCALITY) and value: adr = vcard.getTag(KEY_ADR) or vcard.setTag(KEY_ADR) - adr.setTagData(key, getLocationString(value, key, user)) + adr.setTagData(key, value.get("title")) elif key == KEY_PHONE_MOBILE and value: tel = vcard.getTag(KEY_TEL) or vcard.setTag(KEY_TEL) @@ -127,7 +96,7 @@ def buildVcard(data, template=VCARD_TEMPLATE, fields=VCARD_FIELDS, user=None): value = time.strftime("%Y-%m-%d", time.strptime(value, "%d.%m.%Y")) vcard.setTagData(key, value) - elif value: + elif value and value != "None": vcard.setTagData(key, value) return vcard @@ -147,8 +116,6 @@ def vcard_handler(cl, iq): logger.debug("got vcard request to %s (jid: %s)", destination, source) if destination == TransportID: template = VCARD_TEMPLATE.copy() - template[KEY_URL] = GITHUB_URL - template[KEY_BDAY] = BIRTHDAY vcard = buildVcard(template, template, template) result.setPayload([vcard]) @@ -156,8 +123,8 @@ def vcard_handler(cl, iq): user = Users[source] if user.friends: id = vk2xmpp(destination) - args = ("screen_name", "bdate", "city", "country", "contacts", "home_town", PhotoSize) # todo: a feature to show the user's site instead of their URL? - data = user.vk.getUserData(id, args) + args = ("screen_name", "bdate", "city", "country", "contacts", "home_town", "site", PhotoSize) # todo: a feature to show the user's site instead of their URL? + data = user.vk.getData(id, args) data["id"] = id if not user.settings.use_nicknames: data["screen_name"] = data["name"] |