dokku-comp

This commit is contained in:
2023-09-11 23:04:53 +03:00
parent 4be2dc3a45
commit b9a98f1e56
25 changed files with 646 additions and 460 deletions

View File

@@ -3,64 +3,69 @@ from bot.api import get_member, send_message, get_chat_administrators
from bot.utils.mention import userdata_extract
def construct_unlink_buttons(actor):
async def construct_unlink_buttons(actor):
buttons = []
for vouch in actor['children']:
for chat_id in actor['chats']:
r = get_member(chat_id, vouch)
member = r['result']['user']
uid, identity, username = userdata_extract(member)
buttons.append({
'text': f'{identity} {username}',
'callback_data': 'unlink' + vouch
})
for vouch in actor["children"]:
for chat_id in actor["chats"]:
r = await get_member(chat_id, vouch)
member = r["result"]["user"]
_uid, identity, username = userdata_extract(member)
buttons.append(
{"text": f"{identity} {username}", "callback_data": "unlink" + vouch}
)
return buttons
def handle_command_my(msg, state):
print('handle my command')
from_id = str(msg['from']['id'])
async def handle_command_my(msg, state):
print("handle my command")
from_id = str(msg["from"]["id"])
sender = Profile.get(from_id, msg)
handle_command_owner_my(msg)
await handle_command_owner_my(msg)
# генерируем кнопки для всех, за кого поручились
buttons = construct_unlink_buttons(sender)
reply_markup = { "inline_keyboard": [ buttons, ] }
buttons = await construct_unlink_buttons(sender)
reply_markup = {
"inline_keyboard": [
buttons,
]
}
if len(buttons) == 0:
if msg['from'].get('language_code', 'ru') == 'ru':
body = 'Вас ещё никто не узнал? Напишите, я передам нашему кругу'
if msg["from"].get("language_code", "ru") == "ru":
body = "Вас ещё никто не узнал? Напишите, я передам нашему кругу"
else:
body = 'Nobody recognized you? Speak, I will pass your message to the circle'
r = send_message(from_id, body)
body = (
"Nobody recognized you? Speak, I will pass your message to the circle"
)
r = await send_message(from_id, body)
print(r)
chat_id = msg['chat']['id']
chat_id = msg["chat"]["id"]
state.make_talking(from_id, chat_id)
else:
if msg['from'].get('language_code', 'ru') == 'ru':
body = 'Нажмите кнопки ниже, чтобы удалить ваши связи'
if msg["from"].get("language_code", "ru") == "ru":
body = "Нажмите кнопки ниже, чтобы удалить ваши связи"
else:
body = 'Unlink your connections pressing the buttons below'
body = "Unlink your connections pressing the buttons below"
r = send_message(from_id, body, reply_markup=reply_markup)
r = await send_message(from_id, body, reply_markup=reply_markup)
print(r)
def handle_command_owner_my(msg):
chat_id = msg['chat']['id']
r = get_chat_administrators(chat_id)
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'])
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)
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)