From e8c4d095e1abf3a64583e5395f6d5a48922b0dd2 Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 19 Oct 2020 21:27:48 +0700 Subject: Fix RuntimeError in groupchats; Add limit to groupchats' users count --- extensions/groupchats.README.md | 7 +++++-- extensions/groupchats.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/extensions/groupchats.README.md b/extensions/groupchats.README.md index b08124e..8463702 100644 --- a/extensions/groupchats.README.md +++ b/extensions/groupchats.README.md @@ -1,13 +1,16 @@ Installation ==== -The extension “groupchats” requires up to 2 fields in the main config: +The extension “groupchats” requires up to 3 fields in the main config: 1. ConferenceServer — the address of your (or not your?) conference server Bear in mind that there can be limits on the jabber server for conference per jid. Read the wiki for more details. -2. CHAT_LIFETIME_LIMIT — the limit of the time after that chat considered inactive and will be removed. Time must be formatted as text and contain the time measurement variables after the digits. +2. CHAT_USERS_LIMIT — the limit of users per chat. 50 is the default. + +3. CHAT_LIFETIME_LIMIT — the limit of the time after that chat considered inactive and will be removed. Time must be formatted as text and contain the time measurement variables after the digits. + For example: diff --git a/extensions/groupchats.py b/extensions/groupchats.py index 86611ed..aa4fff1 100644 --- a/extensions/groupchats.py +++ b/extensions/groupchats.py @@ -30,6 +30,7 @@ CHAT_CLEANUP_DELAY = 86400 # 24 hours MIN_CHAT_ID = 2000000000 OWNER_FALLBACK = 210700286 + if not require("attachments") or not require("forwarded_messages"): raise RuntimeError("extension 'groupchats' requires 'forwarded_messages' and 'attachments'") @@ -406,6 +407,8 @@ class Chat(object): Get vk chat by id """ chat = user.vk.method("messages.getChat", {"chat_id": id}) + users = chat.get("users", []) + users = sorted(users[:CHAT_USERS_LIMIT]) if not chat: raise RuntimeError("Unable to get a chat!") return chat @@ -448,7 +451,7 @@ class Chat(object): @staticmethod def getUserByID(id): - for jid, user in Users.iteritems(): + for user in Users.values(): if hasattr(user, "vk"): if user.vk.getUserPreferences()[0] == id: return user @@ -556,6 +559,8 @@ def initChatExtension(): cleanTheChatsUp() else: logger.warning("not starting chats cleaner because CHAT_LIFETIME_LIMIT is not set") + if not isdef("CHAT_USERS_LIMIT"): + CHAT_USERS_LIMIT = 50 if isdef("ConferenceServer") and ConferenceServer: -- cgit v1.2.3