Example #1
0
def removetag(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        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
        raise
    if user_id == context.bot.id:
        message.reply_text("how I supposed to tag or untag myself")
        return
    chat_id = str(chat.id)[1:]
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user not in tagall_list:
        message.reply_text("{} is doesn't exist in {}'s list!".format(
            mention_html(member.user.id, member.user.first_name), chat.title),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'tagall2_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is successfully removed from {}'s list.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Example #2
0
def warn_user(update: Update, context: CallbackContext) -> str:
    args = context.args
    message: Optional[Message] = update.effective_message
    chat: Optional[Chat] = update.effective_chat
    warner: Optional[User] = update.effective_user

    user_id, reason = extract_user_and_text(message, args)
    if message.text.startswith("/d") and message.reply_to_message:
        message.reply_to_message.delete()
    if user_id:
        if (message.reply_to_message
                and message.reply_to_message.from_user.id == user_id):
            return warn(
                message.reply_to_message.from_user,
                chat,
                reason,
                message.reply_to_message,
                warner,
            )
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("That looks like an invalid User ID to me.")
    return ""
Example #3
0
def set_title(update: Update, context: CallbackContext):
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text(
            "You don't seem to be referring to a user or the ID specified is incorrect..",
        )
        return

    if user_member.status == "creator":
        message.reply_text(
            "This person CREATED the chat, how can i set custom title for him?",
        )
        return

    if user_member.status != "administrator":
        message.reply_text(
            "Can't set title for non-admins!\nPromote them first to set custom title!",
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "I can't set my own title myself! Get the one who made me admin to do it for me.",
        )
        return

    if not title:
        message.reply_text("Setting blank title doesn't do anything!")
        return

    if len(title) > 16:
        message.reply_text(
            "The title length is longer than 16 characters.\nTruncating it to 16 characters.",
        )

    try:
        bot.setChatAdministratorCustomTitle(chat.id, user_id, title)
    except BadRequest:
        message.reply_text(
            "Either they aren't promoted by me or you set a title text that is impossible to set."
        )
        return

    bot.sendMessage(
        chat.id,
        f"Sucessfully set title for <code>{user_member.user.first_name or user_id}</code> "
        f"to <code>{html.escape(title[:16])}</code>!",
        parse_mode=ParseMode.HTML,
    )
Example #4
0
def mute(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    user_id, reason = extract_user_and_text(message, args)
    reply = check_user(user_id, bot, chat)

    if reply:
        message.reply_text(reply)
        return ""

    member = chat.get_member(user_id)

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#MUTE\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}")

    if reason:
        log += f"\n<b>Reason:</b> {reason}"

    if member.can_send_messages is None or member.can_send_messages:
        bot.restrict_chat_member(chat.id, user_id, can_send_messages=False)
        bot.sendMessage(
            chat.id,
            f"Muted <b>{html.escape(member.user.first_name)}</b> with no expiration date!",
            parse_mode=ParseMode.HTML)
        return log

    else:
        message.reply_text("This user is already muted!")

    return ""
Example #5
0
def dwarn_user(update: Update, context: CallbackContext) -> str:
    args = context.args
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    warner = update.effective_user  # type: Optional[User]
    user = update.effective_user
    user_id, reason = extract_user_and_text(message, args)
    
    time.sleep(2)
    message.delete()

    if can_delete(chat, context.bot.id):
        try:
            update.effective_message.reply_to_message.delete()
        except AttributeError:
            pass

    if user_id:
        if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
            return warn(message.reply_to_message.from_user, chat, reason,
                        message.reply_to_message, warner)
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("That looks like an invalid User ID to me.")
    return ""
Example #6
0
def set_title(update: Update, context: CallbackContext):
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text(
            "Có vẻ như bạn không đề cập đến người dùng hoặc ID được chỉ định không chính xác..",
        )
        return

    if user_member.status == "creator":
        message.reply_text(
            "Người này đã tạo ra cuộc trò chuyện, làm thế nào mình có thể đặt tiêu đề tùy chỉnh họ được",
        )
        return

    if user_member.status != "administrator":
        message.reply_text(
            "Không thể đặt tiêu đề cho những người không phải là quản trị viên!\nThăng cấp họ trước để đặt tiêu đề tùy chỉnh!",
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "Mình không thể tự đặt tiêu đề cho chính mình được! Phải là quản trị viên mới thực hiện được điều đó.",
        )
        return

    if not title:
        message.reply_text("Không thể đặt tiêu đề trống!")
        return

    if len(title) > 16:
        message.reply_text(
            "Độ dài tiêu đề dài hơn 16 ký tự.\nVui lòng cắt ngắn nó xuống còn 16 ký tự.",
        )

    try:
        bot.setChatAdministratorCustomTitle(chat.id, user_id, title)
    except BadRequest:
        message.reply_text(
            "Hoặc là họ không được mình thăng cấp hoặc bạn đặt tiêu đề văn bản không thể đặt được."
        )
        return

    bot.sendMessage(
        chat.id,
        f"Đặt tiêu đề thành công cho <code>{user_member.user.first_name or user_id}</code> "
        f"to <code>{html.escape(title[:16])}</code>!",
        parse_mode=ParseMode.HTML,
    )
Example #7
0
def unapprove(update, context):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        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 user_id == context.bot.id:
        message.reply_text("how I supposed to approve or unapprove myself")
        return
    chat_id = str(chat.id)[1:]
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user not in approve_list:
        message.reply_text("{} isn't approved yet.".format(
            mention_html(member.user.id, member.user.first_name)),
                           parse_mode=ParseMode.HTML)
        return
    member = chat.get_member(int(user_id))
    chat_id = str(chat.id)[1:]
    REDIS.srem(f'approve_list_{chat_id}',
               mention_html(member.user.id, member.user.first_name))
    message.reply_text("{} is no longer approved in {}.".format(
        mention_html(member.user.id, member.user.first_name), chat.title),
                       parse_mode=ParseMode.HTML)
Example #8
0
def set_title(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text(
            "Bir kullanıcıya atıfta bulunmuyorsunuz veya belirtilen kimlik yanlış.."
        )
        return

    if user_member.status == 'creator':
        message.reply_text(
            "Bu kişi sohbeti YARATTI, onun için nasıl özel başlık ayarlayabilirim?"
        )
        return

    if not user_member.status == 'administrator':
        message.reply_text(
            "Yönetici olmayanlar için başlık ayarlanamaz!\nÖzel başlık ayarlamak için önce onları tanıtın!"
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "Kendi başlığımı kendim belirleyemiyorum! Beni yönetici yapmasını sağlayanı benim için yapsın."
        )
        return

    if not title:
        message.reply_text("Boş başlık ayarlamak hiçbir şey yapmaz!")
        return

    if len(title) > 16:
        message.reply_text(
            "Başlık uzunluğu 16 karakterden uzun.\n16 karaktere kısaltma.")

    result = requests.post(
        f"https://api.telegram.org/bot{TOKEN}/setChatAdministratorCustomTitle"
        f"?chat_id={chat.id}"
        f"&user_id={user_id}"
        f"&custom_title={title}")
    status = result.json()["tamam"]

    if status is True:
        bot.sendMessage(
            chat.id,
            f"İçin başlığı başarıyla ayarlandı <code>{user_member.user.first_name or user_id}</code> "
            f"to <code>{title[:16]}</code>!",
            parse_mode=ParseMode.HTML)
    else:
        description = result.json()["description"]
        if description == "Bad Request:kullanıcının özel başlığını değiştirmek için yeterli hak yok":
            message.reply_text(
                "Tanıtmadığım yöneticiler için özel başlık ayarlayamıyorum!")
Example #9
0
def set_title(update: Update, context: CallbackContext):
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text(
            "You don't seem to be referring to a user or the ID specified is incorrect.."
        )
        return

    if user_member.status == 'creator':
        message.reply_text(
            "This is a Legendary Trainer and I Dosen't had any right to set title for him sorry!")
        return

    if not user_member.status == 'administrator':
        message.reply_text(
            "Hey Tracy Stop Drinking. This person is not admin and u trying to set custom title for them are u dumb. If u want to set then!\nPromote them first to set custom title!"
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "I can't set my own title myself! Get the one who made me admin to do it for me."
        )
        return

    if not title:
        message.reply_text("Setting blank title doesn't do anything!")
        return

    if len(title) > 16:
        message.reply_text(
            "The title length is longer than 16 characters.\nTruncating it to 16 characters."
        )

    try:
        bot.setChatAdministratorCustomTitle(chat.id, user_id, title)
    except BadRequest:
        message.reply_text(
            "I can't set custom title for admins that I didn't promote!")
        return

    bot.sendMessage(
        chat.id,
        f"Sucessfully set title for <code>{user_member.user.first_name or user_id}</code> "
        f"to <code>{html.escape(title[:16])}</code>!",
        parse_mode=ParseMode.HTML)
Example #10
0
def set_title(update: Update, context: CallbackContext):
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text(
            "ඔය ID එක හරි username එක හරි වැරදි🤦‍♂️ හරියට බලන්න.."
        )
        return

    if user_member.status == 'creator':
        message.reply_text(
            "මේ group එක හදපු කෙනාට මම කොහොමද custom title එකක් දාන්නෙ?😠")
        return

    if not user_member.status == 'administrator':
        message.reply_text(
            "Admin නැති කෙනෙකුට කොහොමද title එකක් දාන්නෙ😬\nමුලින්ම admin දීලා ඊට පස්සෙ custom title එකක් දාන්න"
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "මට මගේ custom title දාන්න බෑ😔. මට admin දුන්න කෙනාට කියල මගේ title එක දාවන්න."
        )
        return

    if not title:
        message.reply_text("Title එක හිස් තියන්න බෑ.")
        return

    if len(title) > 16:
        message.reply_text(
            "Title length එක characters 16ට වඩා වැඩියි.\nඒක characters 16ට වඩා අඩු කරන්න."
        )

    try:
        bot.setChatAdministratorCustomTitle(chat.id, user_id, title)
    except BadRequest:
        message.reply_text(
            "මම admin දුන්නෙ නැති අයට මට title එක දාන්න බෑ.")
        return

    bot.sendMessage(
        chat.id,
        f"සාර්ථකව <code>{user_member.user.first_name or user_id}</code>ට <code>{html.escape(title[:16])}</code>"
        f"  කියල title එක දැම්මා😁",
        parse_mode=ParseMode.HTML)
Example #11
0
def ban(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("I doubt that's a user.")
        return log_message

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

    if user_id == bot.id:
        message.reply_text("Oh yeah, ban myself, noob!")
        return log_message

    # dev users to bypass whitelist protection incase of abuse
    if is_user_ban_protected(chat, user_id, member) and user not in DEV_USERS:
        message.reply_text("This user has immunity - I can't ban them.")
        return log_message

    log = (f"<b>{html.escape(chat.title)}:</b>\n"
           f"#BANNED\n"
           f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
           f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}")
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id)
        # bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        bot.sendMessage(chat.id, "Banned user {}.".format(mention_html(member.user.id, member.user.first_name)),
                        parse_mode=ParseMode.HTML)
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            # Do not reply
            message.reply_text('Banned!', quote=False)
            return log
        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("Uhm...that didn't work...")

    return log_message
Example #12
0
def set_title(update: Update, context: CallbackContext):
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    message = update.effective_message

    user_id, title = extract_user_and_text(message, args)
    try:
        user_member = chat.get_member(user_id)
    except:
        return

    if not user_id:
        message.reply_text("Bir istifadəçiyə istinad etmirsiniz..")
        return

    if user_member.status == 'creator':
        message.reply_text(
            "Bu şəxs qrup yaradıcısıdır və mən onun adminlik başlığını dəyişə bilmərəm?"
        )
        return

    if not user_member.status == 'administrator':
        message.reply_text(
            "Admin olmayanlara başlıq qoymaq mümkün deyil!\nİlk öncə onları admin edin!"
        )
        return

    if user_id == bot.id:
        message.reply_text(
            "Öz başlığımı dəyişə bilmərəm! Bunu mənim üçün başqası edə bilər.")
        return

    if not title:
        message.reply_text("Axı bir başlıq verməmisən!")
        return

    if len(title) > 16:
        message.reply_text("Başlıq 16 simvoldan çox ola bilməz.")

    try:
        bot.setChatAdministratorCustomTitle(chat.id, user_id, title)
    except BadRequest:
        message.reply_text(
            "Mən sadəcə adminlik hüququnu özüm verdiyim şəxslərin başlığını dəyişə bilərəm!"
        )
        return

    bot.sendMessage(
        chat.id,
        f"<code>{user_member.user.first_name or user_id}</code> adminin başlığı "
        f"<code>{html.escape(title[:16])}</code> olaraq ayarlandı!",
        parse_mode=ParseMode.HTML)
Example #13
0
def punch(update: Update, context: CallbackContext) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            "Bunun bir istifadəçi olduğuna şübhə ilə yanaşıram.")
        return log_message

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

    if user_id == bot.id:
        message.reply_text("Yeahhh mən özümə bunu etməyəcəm.")
        return log_message

    if is_user_ban_protected(chat, user_id):
        message.reply_text(
            "ehh bu istifadəçini atmaq istəyərdim amma indi ata bilmirəm....")
        return log_message

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        # bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        bot.sendMessage(
            chat.id,
            f"{mention_html(member.user.id, html.escape(member.user.first_name))} qrupdan atıldı.",
            parse_mode=ParseMode.HTML)
        log = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#KICKED\n"
            f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
            f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
        )
        if reason:
            log += f"\n<b>Səbəb:</b> {reason}"

        return log

    else:
        message.reply_text("pf bu istifadəçini ata bilmirəm.")

    return log_message
Example #14
0
def mute(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    args = context.args
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        reply = "You don't seem to be referring to a user or the ID specified is incorrect.."
        return ""

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

    if user_id == bot.id:
        reply = "I'm not gonna MUTE myself, How high are you?"
        return ""

    if is_user_admin(chat, user_id, member) or user_id in TIGERS:
        reply = "Can't. Find someone else to mute but not this one."
        return ""

    member = chat.get_member(user_id)

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#MUTE\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}")

    if reason:
        log += f"\n<b>Reason:</b> {reason}"

    if member.can_send_messages is None or member.can_send_messages:
        chat_permissions = ChatPermissions(can_send_messages=False)
        bot.restrict_chat_member(chat.id, user_id, chat_permissions)
        bot.sendMessage(
            chat.id,
            f"Muted <b>{html.escape(member.user.first_name)}</b> with no expiration date!",
            parse_mode=ParseMode.HTML)
        return log

    else:
        message.reply_text("This user is already muted!")

    return ""
Example #15
0
def punch(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Bunun bir kullanıcı olduğundan şüpheliyim.")
        return log_message

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "Kullanıcı Bulunamadı":
            message.reply_text("Bu kullanıcıyı bulamıyorum.")
            return log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text("Evet bunu yapmayacağım.")
        return log_message

    if is_user_ban_protected(chat, user_id):
        message.reply_text("Keşke bu kullanıcıyı yumruklayabilseydim....")
        return log_message

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        # bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        bot.sendMessage(
            chat.id,
            f"Bir Tekmeli! {mention_html(member.user.id, member.user.first_name)}.",
            parse_mode=ParseMode.HTML)
        log = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#KICKED\n"
            f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
            f"<b>Kullanıcı:</b> {mention_html(member.user.id, member.user.first_name)}"
        )
        if reason:
            log += f"\n<b>Sebep:</b> {reason}"

        return log

    else:
        message.reply_text("Kahretsin, bu kullanıcıyı yumruklayamam.")

    return log_message
Example #16
0
def eject(update: Update, context: CallbackContext) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("I doubt that's a user.")
        return log_message

    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 log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text("Yeahhh I'm not gonna do that.")
        return log_message

    if is_user_ban_protected(chat, user_id):
        message.reply_text("I really wish I could eject this user....")
        return log_message

    res = chat.unban_member(user_id)  # unban on current user = kick
    if res:
        # bot.send_sticker(chat.id, BAN_STICKER)  # banhammer marie sticker
        bot.sendMessage(
            chat.id,
            f"Ejected! {mention_html(member.user.id, html.escape(member.user.first_name))}.",
            parse_mode=ParseMode.HTML)
        log = (
            f"<b>{html.escape(chat.title)}:</b>\n"
            f"#EJECTED\n"
            f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
            f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
        )
        if reason:
            log += f"\n<b>Reason:</b> {reason}"

        return log

    else:
        message.reply_text("Well damn, I can't eject that user.")

    return log_message
Example #17
0
def sban(update: Update, context: CallbackContext) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    log_message = ""
    bot = context.bot
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    update.effective_message.delete()
    if not user_id:
        return log_message

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            return log_message
        else:
            raise

    if user_id == bot.id:
        return log_message

    if is_user_ban_protected(chat, user_id, member):
        return log_message

    if user_id == 777000 or user_id == 1087968824:
        return log_message

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#SBANNED\n"
        f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
    )
    if reason:
        log += "\n<b>Reason:</b> {}".format(reason)

    try:
        chat.kick_member(user_id)
        return log

    except BadRequest as excp:
        if excp.message == "Reply message not found":
            return log
        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)
    return log_message
Example #18
0
def warn_user(bot: Bot, update: Update, args: List[str]) -> str:
    message: Optional[Message] = update.effective_message
    chat: Optional[Chat] = update.effective_chat
    warner: Optional[User] = update.effective_user

    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
            return warn(message.reply_to_message.from_user, chat, reason, message.reply_to_message, warner)
        else:
            return warn(chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("That looks like an invalid User ID to me.")
    return ""
Example #19
0
def unban(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            "Bunun bir istifadəçi olduğuna şübhə ilə yanaşıram.")
        return log_message

    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 log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text(
            "Mən öz banımı aça bilmərəm çünki mən burdayam və banlı deyiləm...?"
        )
        return log_message

    if is_user_in_chat(chat, user_id):
        message.reply_text("Bu istifadəçinin burada olduğundan əminsən??")
        return log_message

    chat.unban_member(user_id)
    message.reply_text("Yep, istifadəçi artıq qoşula bilər!")

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#UNBANNED\n"
        f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
    )
    if reason:
        log += f"\n<b>Səbəb:</b> {reason}"

    return log
Example #20
0
def warn_user(bot: Bot, update: Update, args: List[str]) -> str:
    message: Optional[Message] = update.effective_message
    chat: Optional[Chat] = update.effective_chat
    warner: Optional[User] = update.effective_user

    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
            return warn(message.reply_to_message.from_user, chat, reason,
                        message.reply_to_message, warner)
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text(
            "Bu benim için geçersiz bir Kullanıcı Kimliği gibi görünüyor.")
    return ""
Example #21
0
def warn_user(update: Update, context: CallbackContext) -> str:
    args = context.args
    message: Optional[Message] = update.effective_message
    chat: Optional[Chat] = update.effective_chat
    warner: Optional[User] = update.effective_user

    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
            return warn(message.reply_to_message.from_user, chat, reason,
                        message.reply_to_message, warner)
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("İstifadəçi Haqqında  Məlumatım Yoxdur! İd Nömrəsiylə Yoxlayın !")
    return ""
Example #22
0
def warn_user(update: Update, context: CallbackContext) -> str:
    args = context.args
    message: Optional[Message] = update.effective_message
    chat: Optional[Chat] = update.effective_chat
    warner: Optional[User] = update.effective_user

    user_id, reason = extract_user_and_text(message, args)

    if user_id:
        if message.reply_to_message and message.reply_to_message.from_user.id == user_id:
            return warn(message.reply_to_message.from_user, chat, reason,
                        message.reply_to_message, warner)
        else:
            return warn(
                chat.get_member(user_id).user, chat, reason, message, warner)
    else:
        message.reply_text("Görünür ki yanlış istifadəçi ID-sidir.")
    return ""
Example #23
0
def addtag(update, context):
    chat = update.effective_chat  
    user = update.effective_user 
    message = update.effective_message
    args = context.args 
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        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 user_id == context.bot.id:
        message.reply_text("how I supposed to tag myself")
        return 
    
    chat_id = str(chat.id)[1:] 
    tagall_list = list(REDIS.sunion(f'tagall2_{chat_id}'))
    match_user = mention_html(member.user.id, member.user.first_name)
    if match_user in tagall_list:
        message.reply_text(
            "{} is already exist in {}'s tag list.".format(mention_html(member.user.id, member.user.first_name),
                                                           chat.title),
            parse_mode=ParseMode.HTML
        )
        return
    message.reply_text(
        "{} accept this, if you want to add yourself into {}'s tag list! or just simply decline this.".format(mention_html(member.user.id, member.user.first_name),
                                                                     chat.title),
        reply_markup=InlineKeyboardMarkup(
                                   [
                                       [
                                           InlineKeyboardButton(text="Accept", callback_data=f"tagall_accept={user_id}"),
                                           InlineKeyboardButton(text="Decline", callback_data=f"tagall_dicline={user_id}")  
                                        ]
                                    ]
                                   ),
        parse_mode=ParseMode.HTML
    )
Example #24
0
def smute(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    args = context.args
    user_id, reason = extract_user_and_text(message, args)
    update.effective_message.delete()
    if not user_id:
        return ""

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

    if user_id == bot.id:
        return ""

    if is_user_admin(chat, user_id, member) or user_id in TIGERS:
        return ""

    member = chat.get_member(user_id)

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#SMUTE\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}")

    if reason:
        log += f"\n<b>Reason:</b> {reason}"

    if member.can_send_messages is None or member.can_send_messages:
        chat_permissions = ChatPermissions(can_send_messages=False)
        bot.restrict_chat_member(chat.id, user_id, chat_permissions)
        return log

    return ""
Example #25
0
def unban(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    log_message = ""
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("I doubt that's a user.")
        return log_message

    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 log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text("How would I unban myself if I wasn't here...?")
        return log_message

    if is_user_in_chat(chat, user_id):
        message.reply_text("Isn't this person already here??")
        return log_message

    chat.unban_member(user_id)
    message.reply_text("Yep, this user can join!")

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#UNBANNED\n"
        f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>User:</b> {mention_html(member.user.id, html.escape(member.user.first_name))}"
    )
    if reason:
        log += f"\n<b>Reason:</b> {reason}"

    return log
Example #26
0
def unban(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    log_message = ""

    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text("Bunun bir kullanıcı olduğundan şüpheliyim.")
        return log_message

    try:
        member = chat.get_member(user_id)
    except BadRequest as excp:
        if excp.message == "Kullanıcı Bulunamadı":
            message.reply_text("Bu kullanıcıyı bulamıyorum.")
            return log_message
        else:
            raise

    if user_id == bot.id:
        message.reply_text("Burada olmasaydım kendimi nasıl kaldırabilirim?")
        return log_message

    if is_user_in_chat(chat, user_id):
        message.reply_text("Bu kişi zaten burada değil mi??")
        return log_message

    chat.unban_member(user_id)
    message.reply_text("Evet, bu kullanıcı katılabilir!")

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#UNBANNED\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>Kullanıcı:</b> {mention_html(member.user.id, member.user.first_name)}"
    )
    if reason:
        log += f"\n<b>Sebep:</b> {reason}"

    return log
Example #27
0
def approval(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    args = context.args
    
    chat = update.effective_chat  
    user = update.effective_user 
    message = update.effective_message
    args = context.args 
    user_id, reason = extract_user_and_text(message, args)
    if not user_id:
        message.reply_text("You don't seem to be referring to a user.")
        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 user_id == context.bot.id:
        message.reply_text("How I supposed to approve myself")
        return 
    
    chat_id = str(chat.id)[1:] 
    approve_list = list(REDIS.sunion(f'approve_list_{chat_id}'))
    target_user = mention_html(member.user.id, member.user.first_name)
    if target_user in approve_list:
        message.reply_text(
            "{} is an approved user. Auto Warns, antiflood, and blocklists won't apply to them.".format(mention_html(member.user.id, member.user.first_name)),                                              
            parse_mode=ParseMode.HTML
        )
        return

    if target_user not in approve_list:
        message.reply_text(
            "{} is not an approved user. They are affected by normal commands.".format(mention_html(member.user.id, member.user.first_name)),                                              
            parse_mode=ParseMode.HTML
        )
        return
Example #28
0
def mute(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    user_id, reason = extract_user_and_text(message, args)
    reply = check_user(user_id, bot, chat)

    if reply:
        message.reply_text(reply)
        return ""

    member = chat.get_member(user_id)

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#MUTE\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>User:</b> {mention_html(member.user.id, member.user.first_name)}")

    if reason:
        log += f"\n<b>Reason:</b> {reason}"

    if member.can_send_messages is None or member.can_send_messages:
        chat_permissions = ChatPermissions(can_send_messages=False)
        bot.restrict_chat_member(chat.id, user_id, chat_permissions)
        bot.sendMessage(
            chat.id,
            f"Yoo sir <b>{html.escape(member.user.first_name)}</b> is successfully muted!",
            parse_mode=ParseMode.HTML,
        )
        return log

    else:
        message.reply_text("Dia udah ke mute sayang!")

    return ""
Example #29
0
def mute(update: Update, context: CallbackContext) -> str:
    bot = context.bot
    args = context.args

    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    user_id, reason = extract_user_and_text(message, args)
    reply = check_user(user_id, bot, chat)

    if reply:
        message.reply_text(reply)
        return ""

    member = chat.get_member(user_id)

    log = (
        f"<b>{html.escape(chat.title)}:</b>\n"
        f"#MUTE\n"
        f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n"
        f"<b>İstifadəçi:</b> {mention_html(member.user.id, member.user.first_name)}")

    if reason:
        log += f"\n<b>Səbəb:</b> {reason}"

    if member.can_send_messages is None or member.can_send_messages:
        chat_permissions = ChatPermissions(can_send_messages=False)
        bot.restrict_chat_member(chat.id, user_id, chat_permissions)
        bot.sendMessage(
            chat.id,
            f"Səssizdir <b>{html.escape(member.user.first_name)}</b> son istifadə tarixi yoxdur!",
            parse_mode=ParseMode.HTML)
        return log

    else:
        message.reply_text("Bu istifadəçi artıq səssizdir!")

    return ""
Example #30
0
def bl_user(update: Update, context: CallbackContext) -> str:
    message = update.effective_message
    user = update.effective_user
    bot, args = context.bot, context.args
    user_id, reason = extract_user_and_text(message, args)

    if not user_id:
        message.reply_text(
            "Bunun bir istifadəçi olduğuna şübhə ilə yanaşıram.")
        return ""

    if user_id == bot.id:
        message.reply_text("Özümə məhəl qoymuramsa, işimi necə görməliyəm?")
        return ""

    if user_id in BLACKLISTWHITELIST:
        message.reply_text("Yox! Bu şəxsə bunu etməyəcəm.")
        return ""

    try:
        target_user = bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("İstifadəçini tapa bilmədim.")
            return ""
        else:
            raise

    sql.blacklist_user(user_id, reason)
    message.reply_text("Artıq bu istifadəçinin varlığına məhəl qoymayacağam!")
    log_message = (
        f"#BLACKLIST\n"
        f"<b>Admin:</b> {mention_html(user.id, html.escape(user.first_name))}\n"
        f"<b>User:</b> {mention_html(target_user.id, html.escape(target_user.first_name))}"
    )
    if reason:
        log_message += f"\n<b>Səbəb:</b> {reason}"

    return log_message