0.0.11 refactor, fixes unlink

This commit is contained in:
2023-05-01 19:31:17 +03:00
parent 730725a924
commit 41882595b1
8 changed files with 54 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
from tgbot.storage import Profile
from tgbot.storage import Profile, scan
from tgbot.api import get_member, send_message
from tgbot.utils.mention import userdata_extract
@@ -21,6 +21,9 @@ def handle_command_my(msg):
print(f'handle my command')
from_id = str(msg['from']['id'])
sender = Profile.get(from_id, msg)
handle_command_owner_my(msg)
# генерируем кнопки для всех, за кого поручились
reply_markup = construct_unlink_buttons(sender)
@@ -30,4 +33,24 @@ def handle_command_my(msg):
body = 'Unlink your connections pressing the buttons below'
r = send_message(from_id, body, reply_markup=reply_markup)
print(r)
print(r)
def handle_command_owner_my(msg):
chat_id = msg['chat']['id']
r = 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)