From 467dbb6879c3b534dbf95ee3d22917ab5525bc30 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 18 Sep 2023 10:02:15 +0300 Subject: [PATCH] fix-owner-my --- bot/handlers/command_my.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/bot/handlers/command_my.py b/bot/handlers/command_my.py index 1ce13e9..dd9541d 100644 --- a/bot/handlers/command_my.py +++ b/bot/handlers/command_my.py @@ -1,6 +1,7 @@ from storage import Profile, scan from api import get_member, send_message, get_chat_administrators from utils.mention import userdata_extract +import json async def construct_unlink_buttons(actor): @@ -53,19 +54,20 @@ async def handle_command_my(msg, state): async def handle_command_owner_my(msg): chat_id = msg["chat"]["id"] - r = await get_chat_administrators(chat_id) - print(r) - owner_id = "" - for admin in r["result"]: - if admin["status"] == "creator": - owner_id = str(admin["user"]["id"]) - break - if owner_id: - owner = Profile.get(owner_id, msg) - _uids, members = scan() - for mdata in members: - m = json.loads(mdata.decode("utf-8")) - if owner_id in m["parents"]: - if str(m["id"]) not in owner["children"]: - owner["children"].append(str(m["id"])) - Profile.save(owner) + if chat_id < 0: # is not private + r = await get_chat_administrators(chat_id) + print(r) + owner_id = "" + for admin in r["result"]: + if admin["status"] == "creator": + owner_id = str(admin["user"]["id"]) + break + if owner_id: + owner = Profile.get(owner_id, msg) + _uids, members = scan() + for mdata in members: + m = json.loads(mdata.decode("utf-8")) + if owner_id in m["parents"]: + if str(m["id"]) not in owner["children"]: + owner["children"].append(str(m["id"])) + Profile.save(owner)