fix-owner-my

This commit is contained in:
Untone 2023-09-18 10:02:15 +03:00
parent bf4beaf59e
commit 467dbb6879

View File

@ -1,6 +1,7 @@
from storage import Profile, scan from storage import Profile, scan
from api import get_member, send_message, get_chat_administrators from api import get_member, send_message, get_chat_administrators
from utils.mention import userdata_extract from utils.mention import userdata_extract
import json
async def construct_unlink_buttons(actor): async def construct_unlink_buttons(actor):
@ -53,19 +54,20 @@ async def handle_command_my(msg, state):
async def handle_command_owner_my(msg): async def handle_command_owner_my(msg):
chat_id = msg["chat"]["id"] chat_id = msg["chat"]["id"]
r = await get_chat_administrators(chat_id) if chat_id < 0: # is not private
print(r) r = await get_chat_administrators(chat_id)
owner_id = "" print(r)
for admin in r["result"]: owner_id = ""
if admin["status"] == "creator": for admin in r["result"]:
owner_id = str(admin["user"]["id"]) if admin["status"] == "creator":
break owner_id = str(admin["user"]["id"])
if owner_id: break
owner = Profile.get(owner_id, msg) if owner_id:
_uids, members = scan() owner = Profile.get(owner_id, msg)
for mdata in members: _uids, members = scan()
m = json.loads(mdata.decode("utf-8")) for mdata in members:
if owner_id in m["parents"]: m = json.loads(mdata.decode("utf-8"))
if str(m["id"]) not in owner["children"]: if owner_id in m["parents"]:
owner["children"].append(str(m["id"])) if str(m["id"]) not in owner["children"]:
Profile.save(owner) owner["children"].append(str(m["id"]))
Profile.save(owner)