コード例 #1
0
ファイル: un_ban_user.py プロジェクト: heroku11/JGN-PM
async def un_ban_command(client: Client, message: Message):
    user_id, reply_message_id = get_user_id(
        message.reply_to_message.message_id
    )
    if not user_id:
        return
    _, unban_reason = get_tle_mof_t(message.text)
    rem_user_from_bl(user_id)
    black_list_message = IS_UN_BANED_MESSAGE_TEXT.format(
        reason=unban_reason
    )
    if not unban_reason:
        black_list_message = black_list_message.split(
            REASON_DE_LIMIT_ER
        )[0]
    try:
        await client.send_message(
            chat_id=user_id,
            text=black_list_message,
            disable_web_page_preview=True,
            reply_markup=message.reply_markup,
            disable_notification=True,
            reply_to_message_id=reply_message_id
        )
    except UserIsBlocked:
        await message.reply_text(
            BOT_WS_BLOCKED_BY_USER
        )
    await message.reply_text(
        f"<a href='tg://user?id={user_id}'>"
        "user"
        "</a> <b>unbanned</b>."
    )
コード例 #2
0
async def on_pm_s(client: Client, message: Message):
    user_id, reply_message_id = get_user_id(
        message.reply_to_message.message_id
    )
    # 🥺 check two conditions 🤔🤔
    if message.media:
        _, file_id = get_file_id(message)
        caption = (
            message.caption and message.caption.html
        ) or ""
        await client.send_cached_media(
            chat_id=user_id,
            file_id=file_id,
            caption=caption,
            reply_markup=message.reply_markup,
            disable_notification=True,
            reply_to_message_id=reply_message_id
        )
    else:
        caption = (
            message.text and message.text.html
        ) or DERP_USER_S_TEXT
        await client.send_message(
            chat_id=user_id,
            text=caption,
            disable_web_page_preview=True,
            reply_markup=message.reply_markup,
            disable_notification=True,
            reply_to_message_id=reply_message_id
        )
コード例 #3
0
async def on_pm_s(client: Client, message: Message):
    user_id, reply_message_id = get_user_id(
        message.reply_to_message.message_id)
    if not user_id:
        return
    try:
        await send_message_to_user(client, message, user_id, reply_message_id)
    except UserIsBlocked:
        await message.reply_text(BOT_WS_BLOCKED_BY_USER)
コード例 #4
0
async def on_pm_s(client: Client, message: Message):
    user_id, reply_message_id = get_user_id(
        message.reply_to_message.message_id)
    recvd_text = ((message.text and message.text.html) or " ") + " "
    # TODO: investigate this wizardry

    cmnd_message, ban_un_reason = recvd_text.split(" ", 1)
    cmnd_message = cmnd_message.strip()
    ban_un_reason = ban_un_reason.strip()

    if cmnd_message == BAN_COMMAND:
        add_user_to_bl(user_id, ban_un_reason)

        black_list_message = IS_BLACK_LIST_ED_MESSAGE_TEXT.format(
            reason=ban_un_reason)
        if not ban_un_reason:
            black_list_message = black_list_message.split(
                REASON_DE_LIMIT_ER)[0]

        await client.send_message(chat_id=user_id,
                                  text=black_list_message,
                                  disable_web_page_preview=True,
                                  reply_markup=message.reply_markup,
                                  disable_notification=True,
                                  reply_to_message_id=reply_message_id)

        await message.reply_text(f"<a href='tg://user?id={user_id}'>"
                                 "user"
                                 "</a> <b>banned</b> <i>forever</i>.")

    elif cmnd_message == UN_BAN_COMMAND:
        rem_user_from_bl(user_id)

        black_list_message = IS_UN_BANED_MESSAGE_TEXT.format(
            reason=ban_un_reason)
        if not ban_un_reason:
            black_list_message = black_list_message.split(
                REASON_DE_LIMIT_ER)[0]

        await client.send_message(chat_id=user_id,
                                  text=black_list_message,
                                  disable_web_page_preview=True,
                                  reply_markup=message.reply_markup,
                                  disable_notification=True,
                                  reply_to_message_id=reply_message_id)

        await message.reply_text(f"<a href='tg://user?id={user_id}'>"
                                 "user"
                                 "</a> <b>unbanned</b>.")

    else:
        try:
            await send_message_to_user(client, message, user_id,
                                       reply_message_id)
        except UserIsBlocked:
            await message.reply_text(BOT_WS_BLOCKED_BY_USER)
コード例 #5
0
async def ban_command(client: Client, message: Message):
    user_id, reply_message_id = get_user_id(
        message.reply_to_message.message_id)
    _, ban_reason = get_tle_mof_t(message.text)
    add_user_to_bl(user_id, ban_reason)
    black_list_message = IS_BLACK_LIST_ED_MESSAGE_TEXT.format(
        reason=ban_reason)
    if not ban_reason:
        black_list_message = black_list_message.split(REASON_DE_LIMIT_ER)[0]
    try:
        await client.send_message(chat_id=user_id,
                                  text=black_list_message,
                                  disable_web_page_preview=True,
                                  reply_markup=message.reply_markup,
                                  disable_notification=True,
                                  reply_to_message_id=reply_message_id)
    except UserIsBlocked:
        await message.reply_text(BOT_WS_BLOCKED_BY_USER)
    await message.reply_text(f"<a href='tg://user?id={user_id}'>"
                             "user"
                             "</a> <b>banned</b> <i>forever</i>."
                             "<u>Reason</u>: <code>{reason}</code>")