Ejemplo n.º 1
0
def can_give_tokens(user_id: int) -> Tuple[bool, bool, bool]:
    res_tup: Tuple[bool, bool, bool] = (
        len(permission_courses(user_id, (None, None, 1, None, None))) > 0,
        len(permission_courses(user_id, (None, None, None, 1, None))) > 0,
        len(permission_courses(user_id, (None, None, None, None, 1))) > 0,
    )

    return res_tup
Ejemplo n.º 2
0
def all_admined_courses(user_id: int) -> List[str]:
    res_set = (
        set(permission_courses(user_id, (None, None, True, None, None)))
        | set(permission_courses(user_id, (None, None, None, True, None)))
        | set(permission_courses(user_id, (None, None, None, None, True)))
    )

    return list(res_set)
Ejemplo n.º 3
0
def handle_send(update, context):
    user_id = update.effective_chat.id
    send_courses = permission_courses(user_id, (True, None, None, None, None))

    if len(send_courses) == 0:
        context.bot.send_message(
            chat_id=user_id, text="Извините, у вас нет права отправлять сообщения."
        )
        return

    if len(send_courses) == 1:
        mew_msg_records[user_id]["group"] = send_courses[
            0
        ].title  # TODO: Олег, так нужно?
        mew_msg_records[user_id]["step"] += 2
        context.bot.send_message(
            chat_id=user_id,
            text="Если хотите обозначить дедлайн, напишите его в формате\
         ГГ.ММ.ДД ЧЧ:ММ. Если нет, просто поставьте '-'.",
        )
Ejemplo n.º 4
0
def ask_group(update, context):
    user_id = update.effective_chat.id
    send_courses = permission_courses(user_id, (True, None, None, None, None))

    if len(send_courses) == 1:
        mew_msg_records[user_id]["group"] = send_courses[
            0
        ].title  # TODO: Олег, так нужно?
        mew_msg_records[user_id]["step"] += 2
        context.bot.send_message(
            chat_id=user_id,
            text="Если хотите обозначить дедлайн, напишите его в формате\
         ГГ.ММ.ДД ЧЧ:ММ. Если нет, просто поставьте '-'.",
        )
        return

    mew_msg_records[user_id]["step"] += 1
    context.bot.send_message(
        chat_id=user_id, text="Укажите группу, в которую хотите отправить сообщение."
    )
Ejemplo n.º 5
0
def handle_tk_group(update, context):
    user_id = update.effective_chat.id
    group = context.args[0]
    context.bot.send_message(chat_id=user_id, text="groups:{}".format(permission_courses(user_id, (None, None, None, None))))
    context.bot.send_message(chat_id=user_id, text="requested group:{}".format(group))
    context.bot.send_message(chat_id=user_id, text="groups:{}".format(all_admined_courses(user_id)))
    if group in all_admined_courses(user_id):
        token = secrets.token_hex(18)
        add_token(token, group, new_token_records[user_id]["perm"])
        del new_token_records[user_id]
        context.bot.send_message(
            chat_id=user_id,
            text=f"Токен успешно создан. Не рекомендуется выкладывать его в открытый доступ.",
        )
        context.bot.send_message(chat_id=user_id, text=token)
    else:
        context.bot.send_message(
            chat_id=user_id,
            text="У вас нет разрешения выдавать такие токены для этой группы. Попробуйте ещё раз",
        )