コード例 #1
0
ファイル: misc.py プロジェクト: gamerfuckerofficial/Exusiai
def get_id(bot: Bot, update: Update, args: List[str]):
    user_id = extract_user(update.effective_message, args)
    chat = update.effective_chat  # type: Optional[Chat]
    if user_id:
        if (update.effective_message.reply_to_message
                and update.effective_message.reply_to_message.forward_from):
            user1 = update.effective_message.reply_to_message.from_user
            user2 = update.effective_message.reply_to_message.forward_from
            update.effective_message.reply_markdown(
                tld(chat.id, "misc_get_id_1").format(
                    escape_markdown(user2.first_name),
                    user2.id,
                    escape_markdown(user1.first_name),
                    user1.id,
                ))
        else:
            user = bot.get_chat(user_id)
            update.effective_message.reply_markdown(
                tld(chat.id,
                    "misc_get_id_2").format(escape_markdown(user.first_name),
                                            user.id))
    else:
        chat = update.effective_chat  # type: Optional[Chat]
        if chat.type == "private":
            update.effective_message.reply_markdown(
                tld(chat.id, "misc_id_1").format(chat.id))

        else:
            update.effective_message.reply_markdown(
                tld(chat.id, "misc_id_2").format(chat.id))
コード例 #2
0
def promote(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message
    user = update.effective_user
    chat = update.effective_chat
    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        chatD = update.effective_chat
        if chat.type == "private":
            return

    if not chatD.get_member(bot.id).can_promote_members:
        update.effective_message.reply_text(tld(chat.id, "admin_err_no_perm"))
        return

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id, "common_err_no_user"))
        return

    user_member = chatD.get_member(user_id)
    if user_member.status == "administrator" or user_member.status == "creator":
        message.reply_text(tld(chat.id, "admin_err_user_admin"))
        return

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "admin_err_self_promote"))
        return

    # set same perms as bot - bot can't assign higher perms than itself!
    bot_member = chatD.get_member(bot.id)

    bot.promoteChatMember(
        chatD.id,
        user_id,
        can_change_info=bot_member.can_change_info,
        can_post_messages=bot_member.can_post_messages,
        can_edit_messages=bot_member.can_edit_messages,
        can_delete_messages=bot_member.can_delete_messages,
        can_invite_users=bot_member.can_invite_users,
        can_restrict_members=bot_member.can_restrict_members,
        can_pin_messages=bot_member.can_pin_messages,
        can_promote_members=bot_member.can_promote_members,
    )

    message.reply_text(
        tld(chat.id, "admin_promote_success").format(
            mention_html(user.id, user.first_name),
            mention_html(user_member.user.id, user_member.user.first_name),
            html.escape(chatD.title),
        ),
        parse_mode=ParseMode.HTML,
    )
    return (
        f"<b>{html.escape(chatD.title)}:</b>"
        "\n#PROMOTED"
        f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}"
        f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
    )
コード例 #3
0
ファイル: warns.py プロジェクト: gamerfuckerofficial/Exusiai
def warns(bot: Bot, update: Update, args: List[str]):
    message = update.effective_message
    chat = update.effective_chat
    user_id = extract_user(message, args) or update.effective_user.id
    result = sql.get_warns(user_id, chat.id)
    num = 1

    if result and result[0] != 0:
        num_warns, reasons = result
        limit, soft_warn = sql.get_warn_setting(chat.id)

        if reasons:
            text = tld(chat.id, "warns_list_warns").format(num_warns, limit)
            for reason in reasons:
                text += "\n {}. {}".format(num, reason)
                num += 1

            msgs = split_message(text)
            for msg in msgs:
                update.effective_message.reply_text(msg)
        else:
            update.effective_message.reply_text(
                tld(chat.id,
                    "warns_list_warns_no_reason").format(num_warns, limit))
    else:
        update.effective_message.reply_text(
            tld(chat.id, "warns_list_warns_none"))
コード例 #4
0
ファイル: misc.py プロジェクト: gamerfuckerofficial/Exusiai
def info(bot: Bot, update: Update, args: List[str]):
    msg = update.effective_message  # type: Optional[Message]
    user_id = extract_user(update.effective_message, args)
    chat = update.effective_chat  # type: Optional[Chat]

    if user_id:
        user = 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(tld(chat.id, "I can't extract a user from this."))
        return

    else:
        return

    text = tld(chat.id, "misc_info_1")
    text += tld(chat.id, "misc_info_id").format(user.id)
    text += tld(chat.id,
                "misc_info_first").format(html.escape(user.first_name))

    if user.last_name:
        text += tld(chat.id,
                    "misc_info_name").format(html.escape(user.last_name))

    if user.username:
        text += tld(chat.id,
                    "misc_info_username").format(html.escape(user.username))

    text += tld(chat.id,
                "misc_info_user_link").format(mention_html(user.id, "link"))

    if user.id == OWNER_ID:
        text += tld(chat.id, "misc_info_is_owner")
    else:
        if user.id == int(254318997):
            text += tld(chat.id, "misc_info_is_original_owner")

        if user.id in SUDO_USERS:
            text += tld(chat.id, "misc_info_is_sudo")
        else:
            if user.id in SUPPORT_USERS:
                text += tld(chat.id, "misc_info_is_support")

            if user.id in WHITELIST_USERS:
                text += tld(chat.id, "misc_info_is_whitelisted")

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

    update.effective_message.reply_text(text, parse_mode=ParseMode.HTML)
コード例 #5
0
ファイル: muting.py プロジェクト: gamerfuckerofficial/Exusiai
def media(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            return
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id, "unrestrict_invalid"))
        return ""

    member = chatD.get_member(int(user_id))

    if member.status != "kicked" and member.status != "left":
        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(
                tld(chat.id, "unrestrict_not_restricted").format(chatD.title))
        else:
            bot.restrict_chat_member(
                chatD.id,
                int(user_id),
                can_send_messages=True,
                can_send_media_messages=True,
                can_send_other_messages=True,
                can_add_web_page_previews=True,
            )
            keyboard = []
            reply = tld(chat.id, "unrestrict_success").format(
                mention_html(member.user.id, member.user.first_name),
                chatD.title)
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML)
            return ("<b>{}:</b>"
                    "\n#UNRESTRICTED"
                    "\n<b>• Admin:</b> {}"
                    "\n<b>• User:</b> {}"
                    "\n<b>• ID:</b> <code>{}</code>".format(
                        html.escape(chatD.title),
                        mention_html(user.id, user.first_name),
                        mention_html(member.user.id, member.user.first_name),
                        user_id,
                    ))
    else:
        message.reply_text(tld(chat.id, "unrestrict_not_in_chat"))

    return ""
コード例 #6
0
def slap(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    msg = update.effective_message

    # reply to correct message
    reply_text = (msg.reply_to_message.reply_text
                  if msg.reply_to_message else msg.reply_text)

    # get user who sent message
    if msg.from_user.username:
        curr_user = "******" + escape_markdown(msg.from_user.username)
    else:
        curr_user = "******".format(msg.from_user.first_name,
                                                   msg.from_user.id)

    user_id = extract_user(update.effective_message, args)
    if user_id:
        slapped_user = bot.get_chat(user_id)
        user1 = curr_user
        if slapped_user.username == "RealAkito":
            reply_text(tld(chat.id, "memes_not_doing_that"))
            return
        if slapped_user.username:
            user2 = "@" + escape_markdown(slapped_user.username)
        else:
            user2 = "[{}](tg://user?id={})".format(slapped_user.first_name,
                                                   slapped_user.id)

    # if no target found, bot targets the sender
    else:
        user1 = "[{}](tg://user?id={})".format(bot.first_name, bot.id)
        user2 = curr_user

    temp = random.choice(tld_list(chat.id, "memes_slaps_templates_list"))
    item = random.choice(tld_list(chat.id, "memes_items_list"))
    hit = random.choice(tld_list(chat.id, "memes_hit_list"))
    throw = random.choice(tld_list(chat.id, "memes_throw_list"))
    itemp = random.choice(tld_list(chat.id, "memes_items_list"))
    itemr = random.choice(tld_list(chat.id, "memes_items_list"))

    repl = temp.format(
        user1=user1,
        user2=user2,
        item=item,
        hits=hit,
        throws=throw,
        itemp=itemp,
        itemr=itemr,
    )

    reply_text(repl, parse_mode=ParseMode.MARKDOWN)
コード例 #7
0
ファイル: feds.py プロジェクト: gamerfuckerofficial/Exusiai
def user_join_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    user = update.effective_user
    msg = update.effective_message
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        user_id = extract_user(msg, args)
        if user_id:
            user = 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(tld(chat.id, "common_err_no_user"))
            return
        else:
            LOGGER.warning("error")
        getuser = sql.search_user_in_fed(fed_id, user_id)
        fed_id = sql.get_fed_id(chat.id)
        info = sql.get_fed_info(fed_id)
        get_owner = eval(info["fusers"])["owner"]
        get_owner = bot.get_chat(get_owner).id
        if user_id == get_owner:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_owner"))
            return
        if getuser:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_owner"))
            return
        if user_id == bot.id:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_bot"))
            return
        res = sql.user_join_fed(fed_id, user_id)
        if res:
            update.effective_message.reply_text(
                tld(chat.id, "feds_promote_success"))
        else:
            update.effective_message.reply_text("")
    else:
        update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
コード例 #8
0
ファイル: feds.py プロジェクト: gamerfuckerofficial/Exusiai
def user_demote_fed(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    user = update.effective_user
    fed_id = sql.get_fed_id(chat.id)

    if is_user_fed_owner(fed_id, user.id):
        msg = update.effective_message
        user_id = extract_user(msg, args)
        if user_id:
            user = 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(tld(chat.id, "common_err_no_user"))
            return
        else:
            LOGGER.warning("error")

        if user_id == bot.id:
            update.effective_message.reply_text(tld(chat.id,
                                                    "feds_demote_bot"))
            return

        if sql.search_user_in_fed(fed_id, user_id) == False:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_target_not_admin"))
            return

        res = sql.user_demote_fed(fed_id, user_id)
        if res == True:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_success"))
        else:
            update.effective_message.reply_text(
                tld(chat.id, "feds_demote_failed"))
    else:
        update.effective_message.reply_text(tld(chat.id, "feds_owner_only"))
        return
コード例 #9
0
ファイル: warns.py プロジェクト: gamerfuckerofficial/Exusiai
def reset_warns(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message
    chat = update.effective_chat
    user = update.effective_user

    user_id = extract_user(message, args)

    if user_id:
        sql.reset_warns(user_id, chat.id)
        message.reply_text(tld(chat.id, "warns_reset_success"))
        warned = chat.get_member(user_id).user
        return tld(chat.id, "warns_reset_log_channel").format(
            html.escape(chat.title),
            mention_html(user.id, user.first_name),
            mention_html(warned.id, warned.first_name),
            warned.id,
        )
    else:
        message.reply_text(tld(chat.id, "common_err_no_user"))
    return ""
コード例 #10
0
def demote(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    message = update.effective_message
    user = update.effective_user
    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        chatD = update.effective_chat
        if chat.type == "private":
            return

    if not chatD.get_member(bot.id).can_promote_members:
        update.effective_message.reply_text(tld(chat.id, "admin_err_no_perm"))
        return

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id, "common_err_no_user"))
        return ""

    user_member = chatD.get_member(user_id)
    if user_member.status == "creator":
        message.reply_text(tld(chat.id, "admin_err_demote_creator"))
        return ""

    if not user_member.status == "administrator":
        message.reply_text(tld(chat.id, "admin_err_demote_noadmin"))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "admin_err_self_demote"))
        return ""

    try:
        bot.promoteChatMember(
            int(chatD.id),
            int(user_id),
            can_change_info=False,
            can_post_messages=False,
            can_edit_messages=False,
            can_delete_messages=False,
            can_invite_users=False,
            can_restrict_members=False,
            can_pin_messages=False,
            can_promote_members=False,
        )
        message.reply_text(
            tld(chat.id, "admin_demote_success").format(
                mention_html(user.id, user.first_name),
                mention_html(user_member.user.id, user_member.user.first_name),
                html.escape(chatD.title),
            ),
            parse_mode=ParseMode.HTML,
        )
        return (
            f"<b>{html.escape(chatD.title)}:</b>"
            "\n#DEMOTED"
            f"\n<b>Admin:</b> {mention_html(user.id, user.first_name)}"
            f"\n<b>User:</b> {mention_html(user_member.user.id, user_member.user.first_name)}"
        )

    except BadRequest:
        message.reply_text(tld(chat.id, "admin_err_cant_demote"))
        return ""
コード例 #11
0
ファイル: muting.py プロジェクト: gamerfuckerofficial/Exusiai
def mute(bot: Bot, update: Update, args: List[str]) -> str:
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message

    conn = connected(bot, update, chat, user.id)
    if conn:
        chatD = dispatcher.bot.getChat(conn)
    else:
        if chat.type == "private":
            return
        else:
            chatD = chat

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text(tld(chat.id, "mute_invalid"))
        return ""

    if user_id == bot.id:
        message.reply_text(tld(chat.id, "mute_not_myself"))
        return ""

    member = chatD.get_member(int(user_id))

    if member:

        if user_id in SUDO_USERS:
            message.reply_text(tld(chat.id, "mute_not_sudo"))

        elif is_user_admin(chatD, user_id, member=member):
            message.reply_text(tld(chat.id, "mute_not_m_admin"))

        elif member.can_send_messages is None or member.can_send_messages:
            bot.restrict_chat_member(chatD.id,
                                     user_id,
                                     can_send_messages=False)
            keyboard = []
            reply = tld(chat.id, "mute_success").format(
                mention_html(member.user.id, member.user.first_name),
                chatD.title)
            message.reply_text(reply,
                               reply_markup=keyboard,
                               parse_mode=ParseMode.HTML)
            return ("<b>{}:</b>"
                    "\n#MUTE"
                    "\n<b>Admin:</b> {}"
                    "\n<b>User:</b> {}".format(
                        html.escape(chatD.title),
                        mention_html(user.id, user.first_name),
                        mention_html(member.user.id, member.user.first_name),
                    ))

        else:
            message.reply_text(
                tld(chat.id, "mute_already_mute").format(chatD.title))
    else:
        message.reply_text(
            tld(chat.id, "mute_not_in_chat").format(chatD.title))

    return ""
コード例 #12
0
ファイル: feds.py プロジェクト: gamerfuckerofficial/Exusiai
def unfban(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat
    user = update.effective_user
    message = update.effective_message
    fed_id = sql.get_fed_id(chat.id)

    if not fed_id:
        update.effective_message.reply_text(
            "This group is not a part of any federation!")
        return

    if is_user_fed_admin(fed_id, user.id) == False:
        update.effective_message.reply_text(
            "Only federation admins can do this!")
        return

    user_id = extract_user(message, args)
    if not user_id:
        message.reply_text("You do not seem to be referring to a user.")
        return

    user_chat = bot.get_chat(user_id)
    if user_chat.type != "private":
        message.reply_text("That's not a user!")
        return

    fban, fbanreason = sql.get_fban_user(fed_id, user_id)
    if fban == False:
        message.reply_text("This user is not fbanned!")
        if not fbanreason:
            return
        return

    message.reply_text(
        "I'll give {} a second chance in this federation".format(
            user_chat.first_name))

    chat_list = sql.all_fed_chats(fed_id)

    for chat in chat_list:
        try:
            member = bot.get_chat_member(chat, user_id)
            if member.status == "kicked":
                bot.unban_chat_member(chat, user_id)
        except BadRequest as excp:
            if excp.message in UNFBAN_ERRORS:
                pass
            else:
                LOGGER.warning("Cannot remove fban on {} because: {}".format(
                    chat, excp.message))
        except TelegramError:
            pass

        try:
            x = sql.un_fban_user(fed_id, user_id)
            if not x:
                message.reply_text(
                    "Fban failure, this user may have been un-fedbanned!")
                return
        except Exception:
            pass

    message.reply_text("This person is un-fbanned.")