fix-left-join

This commit is contained in:
2023-09-18 14:02:24 +03:00
parent 0abf216d87
commit 19d0984466
7 changed files with 40 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
from storage import Profile, scan
from api import get_member, send_message, get_chat_administrators
from api import get_member, send_message
from utils.mention import userdata_extract
import json
import logging
@@ -23,12 +23,10 @@ async def construct_unlink_buttons(actor):
async def handle_command_my(msg, state):
print("handle my command")
logger.info("handle my command")
from_id = str(msg["from"]["id"])
sender = Profile.get(from_id, msg)
await handle_command_owner_my(msg)
# генерируем кнопки для всех, за кого поручились
buttons = await construct_unlink_buttons(sender)
reply_markup = {
@@ -55,24 +53,3 @@ async def handle_command_my(msg, state):
r = await send_message(from_id, body, reply_markup=reply_markup)
print(r)
async def handle_command_owner_my(msg):
chat_id = msg["chat"]["id"]
if chat_id < 0: # is not private
r = await get_chat_administrators(chat_id)
logger.debug(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)