Exemple #1
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("Mən bir bot gördüm, və mənə buyurdular ki, qoşulmağı dayandırım... "
                                               "amma mən admin deyiləm!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("Sadəcə adminlər qrupa bot əlavə edə bilər! Yəni rədd ol!")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #2
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "Ben bir bot görmek ve onları katılmadan durdurmak için söylendi ... "
                                "ama ben yönetici değilim.!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Sadece yöneticiler bu sohbet e botlar eklemek için izin verilir! Buradan çık.."
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #3
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "I see a bot, and I've been told to stop them joining... "
                                "but I'm not admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Only admins are allowed to add bots to this chat! Get outta here."
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #4
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "Bir bot görüyorum ve onları durdurma talimatı aldım  "
                                "Gel gör ki yönetici değilim, nasıl olacak!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Bu sohbete yalnızca yöneticiler bot ekleyebilir! Üzgünüm kardeş."
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #5
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("Vedo un bot, mi è stato detto di non permettergli di unirsi... "
                                               "ma non sono un admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("Solo gli admin sono autorizzati ad aggiungere bot a questo gruppo! Fuori di qui.")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #6
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("I see a bot, and I've been told to stop them joining... "
                                               "but I'm not admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("da chekka ivide njan und.😡 ene pole oru kidilan bot vere undo..? 😌. nee konduvanna ee botinem kondu vanna vazhiye pokkonam. 😠 allenkil nine cherth ividunnu chavitty porathakkum kettodaa pattii.. 🤬 ")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("මට බොට් එකක් පෙනේ, ඔවුන් මට සම්බන්ධ වීම නවත්වන ලෙස මට පවසා ඇත ... "
                                               "නමුත් මම පරිපාලක නොවේ!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("මෙම කතාබහට බොට්ස් එක් කිරීමට පරිපාලකයින්ට පමණක් අවසර ඇත! මෙතනින් යන්න.")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "මැකීමට පණිවිඩය හමු නොවීය":
                        pass
                    else:
                        LOGGER.exception("අගුළු දැමීමේ දෝෂයකි")

            break
Exemple #8
0
def del_lockables(update: Update, context: CallbackContext):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, context.bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, context.bot.id):
                            message.reply_text(
                                "다른 봇이 들어오려고 하네요... 들어오지 말라고 하고 싶지만... "
                                "전 관리자가 아니에요!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("관리자만 이 채팅에서 봇을 추가할 수 있어요. 나가세요!")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("잠금 모듈의 오류")

            break
Exemple #9
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "ربات":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("اگه کسی رباتی بیاره من اجازه ادد کردن بهش نمیدم ولی "
                                               "هنوز ادمین نیستم!")
                            return

                        chat.kick_member(new_mem.id)
                        
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #10
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "Bir bot görürəm adminlərə onu dayandırmalı olduğumu deməliyəm "
                                "amma admin deyiləm!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Bu qrupa bot atmaq olmaz... Çıx get burdan!!!")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Silinəcək mesaj tapılmadı":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #11
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "मुझे एक बॉट दिखाई देता है, और मुझे उनसे जुड़ने से रोकने के लिए कहा गया है ... लेकिन मैं एडमिन नहीं हूँ!"
                            )
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "इस चैट में केवल एडमिन को बॉट्स जोड़ने की अनुमति है।"
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "हटाने के लिए मैसेज नहीं मिला":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #12
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat
    message = update.effective_message

    for lockable, filter in LOCK_TYPES.items():
        if (
            filter(message)
            and sql.is_locked(chat.id, lockable)
            and can_delete(chat, bot.id)
        ):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "Saya melihat bot, dan saya telah diberitahu untuk menghentikan mereka bergabung... "
                                "tapi saya bukan admin!"
                            )
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Hanya admin yang diizinkan untuk menambahkan bot ke obrolan ini! Berperilaku atau aku akan memukulmu."
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Pesan untuk dihapus tidak ditemukan":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #13
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]
    user = update.effective_user
    if int(user.id)==777000 or int(user.id)==1087968824: #777000 is the telegram notification service bot ID.
        return #Group channel notifications are sent via this bot. This adds exception to this userid
        # newer id is that 108_something

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("I see a bot, and I've been told to stop them joining... "
                                               "but I'm not admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("Only admins are allowed to add bots to this chat! Get outta here.")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #14
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(
                chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "أرى بوت، وقيل لي أن أوقفهم عن الانضمام ... "
                                "لكنني لست المسؤول!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "يسمح للمحادثات فقط بإضافة روبوتات إلى هذه الدردشة! الحصول على outta هنا"
                        )
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id, lockable) and can_delete(chat, bot.id):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text("Widzę bota i powiedzieli mi żebym zapobiegał ich dołączeniu... "
                                               "ale nie jestem administratorem!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text("Tylko administracja jest uprawniona do dodawania botów do tego czatu! Wypad stąd.")
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("BŁĄD w blokadach")

            break
Exemple #16
0
def remove_bot(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    if sql.is_locked(chat.id, "bots") and is_bot_admin(chat, bot.id):
        new_members = update.effective_message.new_chat_members
        for new_mem in new_members:
            if new_mem.is_bot:
                chat.kick_member(new_mem.id)
                update.effective_message.reply_text("Only admins are allowed to add bots to this chat! Get outta here.")
Exemple #17
0
def del_lockables(bot: Bot, update: Update):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    _can_delete = can_delete(chat, bot.id)

    for lockable, filter in LOCK_TYPES.items():
        if filter(message) and sql.is_locked(chat.id,
                                             lockable) and _can_delete:
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, bot.id):
                            message.reply_text(
                                "I see a bot, and I've been told to stop them joining... "
                                "but I'm not admin!")
                            return

                        chat.kick_member(new_mem.id)
                        message.reply_text(
                            "Only admins are allowed to add bots to this chat!"
                        )
            else:
                # allow whitelisted URLs
                if lockable == 'url':
                    entities = set(url for url in message.parse_entities(
                        MessageEntity.URL).values())
                    # MessageEntity.TEXT_LINK could be added in the filter above, but would return the text, not the
                    # url, so add all entities that have a 'url' field instead
                    entities = entities | set(entity.url
                                              for entity in message.entities
                                              if entity.url)
                    # if all URLs are any of the whitelisted ones, accept the message
                    if all(
                            any(
                                regexp.search(text) for regexp in
                                sql.get_whitelist(chat.id).values())
                            for text in entities):
                        continue
                    else:
                        # forward me the message for review so I can add the sender to a scammer repository
                        message.forward(Config.OWNER_ID,
                                        disable_notification=True)
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

            break
Exemple #18
0
def rban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't restrict people there! Make sure I'm admin and can ban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("I really wish I could ban admins...")
        return

    if user_id == bot.id:
        message.reply_text("I'm not gonna BAN myself, are you crazy?")
        return

    try:
        chat.kick_member(user_id)
        message.reply_text("Banned from chat!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banned!', quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't ban that user.")
Exemple #19
0
def runmute(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't unrestrict people there! Make sure I'm admin and can unban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user there")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        if member.can_send_messages and member.can_send_media_messages \
           and member.can_send_other_messages and member.can_add_web_page_previews:
            message.reply_text(
                "This user already has the right to speak in that chat.")
            return

    if user_id == bot.id:
        message.reply_text("I'm not gonna UNMUTE myself, I'm an admin there!")
        return

    try:
        bot.restrict_chat_member(chat.id,
                                 int(user_id),
                                 can_send_messages=True,
                                 can_send_media_messages=True,
                                 can_send_other_messages=True,
                                 can_add_web_page_previews=True)
        message.reply_text("Yep, this user can talk in that chat!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Unmuted!', quote=False)
        elif excp.message in RUNMUTE_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id,
                chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't unmute that user.")
Exemple #20
0
def runban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't unrestrict people there! Make sure I'm admin and can unban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user there")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Why are you trying to remotely unban someone that's already in that chat?"
        )
        return

    if user_id == bot.id:
        message.reply_text("I'm not gonna UNBAN myself, I'm an admin there!")
        return

    try:
        chat.unban_member(user_id)
        message.reply_text("Yep, this user can join that chat!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Unbanned!', quote=False)
        elif excp.message in RUNBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unbanning user %s in chat %s (%s) due to %s", user_id,
                chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't unban that user.")
Exemple #21
0
def rban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text(
            "Görünüşe göre bir sohbetten/kullanıcıdan bahsetmiyorsunuz.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Bu Bir Geçerli Kullanıcı Değil!")
        return
    elif not chat_id:
        message.reply_text("Bu Bir Geçerli Sohbet Değil!")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Sohbet Bulunamadı! Geçerli Bir Sohbet Kimliği Girdiğinizden Emin Olun Veya Beni Oraya Ekleyin"
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("Üzgünüm ama bu özel bir sohbet!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "Oradaki insanları kısıtlayamam! Yönetici olduğumdan ve kullanıcıları yasaklayabileceğimden emin olun."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("Kullanıcıyı Bulamadım!")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("Gerçekten Sahibimi Banlayacağımı mı düşündün?")
        return

    if user_id == bot.id:
        message.reply_text("Hadi Ama Dostum Kendimi Neden Banlayayım?")
        return

    try:
        chat.kick_member(user_id)
        keyboard = []
        reply = """{} Yasaklandı!""".format(
            mention_html(user_id, member.user.first_name))
        message.reply_text(reply,
                           reply_markup=keyboard,
                           parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('{} Yasaklandı!'.format(user_id), quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Kahretsin onu yasaklayamıyorum")
Exemple #22
0
def rban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Kaha milega ye? ")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't restrict people there! Make sure I'm admin and can ban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("Kaha milega ye? ")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("ye user admin h group me ban nhi ho sakta......")
        return

    if user_id == bot.id:
        message.reply_text(
            "Arey bewde itna kyu pitey ho ki mujme aur jisse ban karna h usme farak bhul jao"
        )
        return

    try:
        chat.kick_member(user_id)
        message.reply_text("Banned!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banned!', quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Well damn, kuch to gadbad h daya")
Exemple #23
0
def rban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text(
            "Wygląda na to, że nie odnosisz się do czatu/futrzaka.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Wygląda na to, że nie odnosisz się do futrzaka.")
        return
    elif not chat_id:
        message.reply_text("Wygląda na to, że nie odnosisz się do czatu.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Czat nie znaleziony! Sprawdź czy podałeś poprawny chat ID oraz czy w nim jestem"
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("Przepraszam, ale to jest prywatny czat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "Nie mogę tutaj ograniczać futrzaków! Sprawdź czy mam prawa administratora i czy mogę banować."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("Nie mogę znaleźć tego futrzaka")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("Naprawdę chciałbym móc banować administratorów...")
        return

    if user_id == bot.id:
        message.reply_text("Nie zamierzam BANOWAĆ siebie, oszalałeś?")
        return

    try:
        chat.kick_member(user_id)
        message.reply_text("Zbanowano!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Zbanowany!', quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "BŁĄD podczas banowania futrzaka %s na chacie %s (%s) z powodu %s",
                user_id, chat.title, chat.id, excp.message)
            message.reply_text("Cholera, nie mogę zbanować tego futrzaka.")
Exemple #24
0
def runban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text(
            "Wygląda na to, że nie odnosisz się do czatu/futrzaka.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Wygląda na to, że nie odnosisz się do futrzaka.")
        return
    elif not chat_id:
        message.reply_text("Wygląda na to, że nie odnosisz się do czatu.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Czat nie znaleziony! Sprawdź czy podałeś poprawny chat ID oraz czy w nim jestem"
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("Przepraszam, ale to jest prywatny czat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "Nie mogę tutaj odgraniczać futrzaków! Sprawdź czy mam prawa administratora i czy mogę odbanować."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("Nie mogę znaleźć tego futrzaka")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Dlaczego próbujesz zdalnie futrzaka który jest już na chacie?")
        return ""

    if user_id == bot.id:
        message.reply_text(
            "Nie będę ODBANOWYWAŁ siebie, jestem tutaj administratorem!")
        return

    try:
        chat.unban_member(user_id)
        message.reply_text("Yup, ten futrzak może wrócić!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Odbanowany!', quote=False)
        elif excp.message in RUNBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "BŁĄD podczas odbanowania futrzaka %s na chacie %s (%s) z powodu %s",
                user_id, chat.title, chat.id, excp.message)
            message.reply_text("Cholera, nie mogę odbanować tego futrzaka.")
Exemple #25
0
def rban(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message
    #chat_name = chat.title or chat.first or chat.username
    chat = update.effective_chat  # type: Optional[Chat]
    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't restrict people there! Make sure I'm admin and can ban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("I really wish I could ban admins...")
        return

    if user_id == bot.id:
        message.reply_text("I'm not gonna BAN myself, are you crazy?")
        return

    try:
        chat.kick_member(user_id)
        rbanning = "Hunting again in the wild!\n{} has been remotely banned from {}! \n".format(
            mention_html(member.user.id, member.user.first_name),
            (chat.title or chat.first or chat.username))
        bot.send_sticker(update.effective_chat.id, BAN_STICKER)
        message.reply_text(rbanning, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banned!', quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't ban that user.")
Exemple #26
0
def runmute(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't unrestrict people there! Make sure I'm admin and can unban users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user there")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        if member.can_send_messages and member.can_send_media_messages \
           and member.can_send_other_messages and member.can_add_web_page_previews:
            message.reply_text(
                "This user already has the right to speak in that chat.")
            return

    if user_id == bot.id:
        message.reply_text("I'm not gonna UNMUTE myself, I'm an admin there!")
        return

    try:
        bot.restrict_chat_member(chat.id,
                                 int(user_id),
                                 permissions=ChatPermissions(
                                     can_send_messages=True,
                                     can_send_media_messages=True,
                                     can_send_other_messages=True,
                                     can_add_web_page_previews=True))
        runmuting = "Well, I will let {} speak on {}!".format(
            mention_html(member.user.id, member.user.first_name),
            (chat.title or chat.first or chat.username))
        message.reply_text(runmuting, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Unmuted!', quote=False)
        elif excp.message in RUNMUTE_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unmnuting user %s in chat %s (%s) due to %s", user_id,
                chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't unmute that user.")
Exemple #27
0
def rban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text(
            "Görünür mənə bir söhbət və ya istifadəçi vermədin.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Görünür bu bir istifadəçi deyil.")
        return
    elif not chat_id:
        message.reply_text("Görünür bu bir söhbət deyil.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Söhbət tapılmadı! Düzgün bir söhbət İD verdiyindən əmin ol və mən də o söhbətdə olmalıyam."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("Təəssüf ki, o bir gizli qrupdur!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "Mən oradakı istifadəçilərlə bağlı tədbir görə bilmərəm! Orada admin olduğumdan əmin ol."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("Bu istifadəçini tapa bilmədim")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text(
            "ehh adminləri ban etməyi arzulayuram amma təəssüf...")
        return

    if user_id == bot.id:
        message.reply_text("Sən dəlisən? Özümü ban etməyəcəm?")
        return

    try:
        chat.kick_member(user_id)
        message.reply_text("Banlandı!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banlandı!', quote=False)
        elif excp.message in RBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("pü. Bu istifadəçini ban edə bilmirəm.")
Exemple #28
0
def runban(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message

    if not args:
        message.reply_text(
            "Görünür mənə bir söhbət və ya istifadəçi vermədin.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Görünür mənə bir istifadəçi vermədin.")
        return
    elif not chat_id:
        message.reply_text("Görünür mənə bir söhbət vermədin.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Söhbət tapılmadı! Düzgün bir söhbət İD verdiyindən əmin ol və mən də o söhbətdə olmalıyam."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("Təəssüf ki, o bir gizli qrupdur!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "Mən oradakı istifadəçilərlə bağlı tədbir görə bilmərəm! Orada admin olduğumdan əmin ol."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("İstidəçi tapılmadı")
            return
        else:
            raise

    if is_user_in_chat(chat, user_id):
        message.reply_text(
            "Sən niyə onsuzda söhbətdə olan birinin banını silməyə çalışırsan?"
        )
        return

    if user_id == bot.id:
        message.reply_text("Öz banımı necə silə bilərəm? Bu mümkün deyil!")
        return

    try:
        chat.unban_member(user_id)
        message.reply_text("Yep, İstifadəçi artıq qoşula bilər!")
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banı silindi!', quote=False)
        elif excp.message in RUNBAN_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception(
                "ERROR unbanning user %s in chat %s (%s) due to %s", user_id,
                chat.title, chat.id, excp.message)
            message.reply_text("Hah? Edə bilmirəm.")
Exemple #29
0
def del_lockables(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    message = update.effective_message  # type: Optional[Message]

    for lockable, filter in LOCK_TYPES.items():
        if lockable == "rtl":
            if sql.is_locked(chat.id, lockable) and can_delete(
                    chat, context.bot.id):
                if message.caption:
                    check = ad.detect_alphabet(u"{}".format(message.caption))
                    if "ARABIC" in check:
                        try:
                            message.delete()
                        except BadRequest as excp:
                            if excp.message == "Message to delete not found":
                                pass
                            else:
                                LOGGER.exception("ERROR in lockables")
                        break
                if message.text:
                    check = ad.detect_alphabet(u"{}".format(message.text))
                    if "ARABIC" in check:
                        try:
                            message.delete()
                        except BadRequest as excp:
                            if excp.message == "Message to delete not found":
                                pass
                            else:
                                LOGGER.exception("ERROR in lockables")
                        break
            continue
        if lockable == "button":
            if sql.is_locked(chat.id, lockable) and can_delete(
                    chat, context.bot.id):
                if message.reply_markup and message.reply_markup.inline_keyboard:
                    try:
                        message.delete()
                    except BadRequest as excp:
                        if excp.message == "Message to delete not found":
                            pass
                        else:
                            LOGGER.exception("ERROR in lockables")
                    break
            continue
        if lockable == "inline":
            if sql.is_locked(chat.id, lockable) and can_delete(
                    chat, context.bot.id):
                if message and message.via_bot:
                    try:
                        message.delete()
                    except BadRequest as excp:
                        if excp.message == "Message to delete not found":
                            pass
                        else:
                            LOGGER.exception("ERROR in lockables")
                    break
            continue
        if (filter(update) and sql.is_locked(chat.id, lockable)
                and can_delete(chat, context.bot.id)):
            if lockable == "bots":
                new_members = update.effective_message.new_chat_members
                for new_mem in new_members:
                    if new_mem.is_bot:
                        if not is_bot_admin(chat, context.bot.id):
                            send_message(
                                update.effective_message,
                                "I see a bot and I've been told to stop them from joining..."
                                "but I'm not admin!",
                            )
                            return

                        chat.kick_member(new_mem.id)
                        send_message(
                            update.effective_message,
                            "Only admins are allowed to add bots in this chat! Get outta here.",
                        )
                        break
            else:
                try:
                    message.delete()
                except BadRequest as excp:
                    if excp.message == "Message to delete not found":
                        pass
                    else:
                        LOGGER.exception("ERROR in lockables")

                break
Exemple #30
0
def rmute(update: Update, context: CallbackContext):
    bot, args = context.bot, context.args
    message = update.effective_message

    if not args:
        message.reply_text("You don't seem to be referring to a chat/user.")
        return

    user_id, chat_id = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        return
    elif not chat_id:
        message.reply_text("You don't seem to be referring to a chat.")
        return

    try:
        chat = bot.get_chat(chat_id.split()[0])
    except BadRequest as excp:
        if excp.message == "Chat not found":
            message.reply_text(
                "Chat not found! Make sure you entered a valid chat ID and I'm part of that chat."
            )
            return
        else:
            raise

    if chat.type == 'private':
        message.reply_text("I'm sorry, but that's a private chat!")
        return

    if not is_bot_admin(chat, bot.id) or not chat.get_member(
            bot.id).can_restrict_members:
        message.reply_text(
            "I can't restrict people there! Make sure I'm admin and can mute users."
        )
        return

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user")
            return
        else:
            raise

    if is_user_ban_protected(chat, user_id, member):
        message.reply_text("I really wish I could mute admins...")
        return

    if user_id == bot.id:
        message.reply_text("I'm not gonna MUTE myself, are you crazy?")
        return

    try:
        bot.restrict_chat_member(
            chat.id,
            user_id,
            permissions=ChatPermissions(can_send_messages=False))
        rmuting = "It is so quiet...\n{} has been remotely muted from {}! \n".format(
            mention_html(member.user.id, member.user.first_name),
            (chat.title or chat.first or chat.username))
        message.reply_text(rmuting, parse_mode=ParseMode.HTML)
    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Muted!', quote=False)
        elif excp.message in RMUTE_ERRORS:
            message.reply_text(excp.message)
        else:
            LOGGER.warning(update)
            LOGGER.exception("ERROR mute user %s in chat %s (%s) due to %s",
                             user_id, chat.title, chat.id, excp.message)
            message.reply_text("Well damn, I can't mute that user.")