Ejemplo n.º 1
0
def check_afk(update, context, user_id, fst_name, userc_id):
    if sql.is_afk(user_id):
        user = sql.check_afk_status(user_id)
        if not user.reason:
            if int(userc_id) == int(user_id):
                return
            res = "{} is afk".format(fst_name)
            noreason = update.effective_message.reply_text(res)
            sleep(10)
            noreason.delete()
        else:
            if int(userc_id) == int(user_id):
                return
            res = "<b>{}</b> is away from keyboard! says it's because of <b>Reason:</b> <code>{}</code>".format(
                fst_name, user.reason)
            replafk = update.effective_message.reply_text(res,
                                                          parse_mode="html")
            sleep(10)
            replafk.delete()
Ejemplo n.º 2
0
def info(update, context):
    args = context.args
    msg = update.effective_message  # type: Optional[Message]
    user_id = extract_user(update.effective_message, args)
    chat = update.effective_chat

    if user_id:
        user = context.bot.get_chat(user_id)

    elif not msg.reply_to_message and not args:
        user = msg.from_user

    elif not msg.reply_to_message and (
            not args or
        (len(args) >= 1 and not args[0].startswith("@")
         and not args[0].isdigit()
         and not msg.parse_entities([MessageEntity.TEXT_MENTION]))):
        msg.reply_text("I can't extract a user from this.")
        return

    else:
        return

    del_msg = msg.reply_text(
        "Hold tight while I steal some data from <b>FBI Database</b>...",
        parse_mode=ParseMode.HTML,
    )

    text = ("<b>USER INFO</b>:"
            "\n<b>ID:</b> <code>{}</code>"
            "\n<b>First Name:</b> <code>{}</code>".format(
                user.id, html.escape(user.first_name)))

    if user.last_name:
        text += "\n<b>Last Name:</b> <code>{}</code>".format(
            html.escape(user.last_name))

    if user.username:
        text += "\n<b>Username:</b> @{}".format(html.escape(user.username))

    text += "\n<b>Permanent user link:</b> {}".format(
        mention_html(user.id, "link"))

    text += "\n<b>Number of profile pics:</b> <code>{}</code>".format(
        context.bot.get_user_profile_photos(user.id).total_count)

    if chat.type != "private":
        status = context.bot.get_chat_member(chat.id, user.id).status
        if status:
            _stext = "\n<b>Status:</b> <code>{}</code>"

        afk_st = is_afk(user.id)
        if afk_st:
            text += _stext.format("Away From Keyboard")
        else:
            status = context.bot.get_chat_member(chat.id, user.id).status
            if status:
                if status in {"left", "kicked"}:
                    text += _stext.format("Absent")
                elif status == "member":
                    text += _stext.format("Present")
                elif status in {"administrator", "creator"}:
                    text += _stext.format("Admin")

    try:
        sw = spamwtc.get_ban(int(user.id))
        if sw:
            text += "\n\n<b>This person is banned in Spamwatch!</b>"
            text += f"\n<b>Reason:</b> <pre>{sw.reason}</pre>"
            text += "\nAppeal at @SpamWatchSupport"
        else:
            pass
    except BaseException:
        pass  # don't crash if api is down somehow...

    cas_banned = check_cas(user.id)
    if cas_banned:
        text += "\n\n<b>This Person is CAS Banned!</b>"
        text += f"\n<b>Reason: </b> <a href='{cas_banned}'>CAS Banned</a>"
        text += "\nAppeal at @cas_discussion"

    if user.id == OWNER_ID:
        text += "\n\nAye this guy is my owner.\nI would never do anything against him!"

    elif user.id in DEV_USERS:
        text += ("\n\nThis person is one of my dev users! "
                 "\nHe has the most command for me after my owner.")

    elif user.id in SUDO_USERS:
        text += ("\n\nThis person is one of my sudo users! "
                 "Nearly as powerful as my owner - so watch it.")

    elif user.id in SUPPORT_USERS:
        text += ("\n\nThis person is one of my support users! "
                 "Not quite a sudo user, but can still gban you off the map.")

    elif user.id in WHITELIST_USERS:
        text += ("\n\nThis person has been whitelisted! "
                 "That means I'm not allowed to ban/kick them.")

    elif user.id == int(1087968824):
        text += "\n\nThis is anonymous admin in this group. "

    try:
        memstatus = chat.get_member(user.id).status
        if memstatus == "administrator" or memstatus == "creator":
            result = context.bot.get_chat_member(chat.id, user.id)
            if result.custom_title:
                text += f"\n\nThis user has custom title <b>{result.custom_title}</b> in this chat."
    except BadRequest:
        pass

    for mod in USER_INFO:
        try:
            mod_info = mod.__user_info__(user.id).strip()
        except TypeError:
            mod_info = mod.__user_info__(user.id, chat.id).strip()
        if mod_info:
            text += "\n\n" + mod_info

    try:
        profile = context.bot.get_user_profile_photos(user.id).photos[0][-1]
        context.bot.sendChatAction(chat.id, "upload_photo")
        context.bot.send_photo(
            chat.id,
            photo=profile,
            caption=(text),
            parse_mode=ParseMode.HTML,
        )
    except IndexError:
        context.bot.sendChatAction(chat.id, "typing")
        msg.reply_text(text,
                       parse_mode=ParseMode.HTML,
                       disable_web_page_preview=True)
    finally:
        del_msg.delete()