Esempio n. 1
0
def report_setting(update, context):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]
    args = context.args

    if chat.type == chat.PRIVATE:
        if len(args) >= 1:
            if args[0] in ("yes", "on"):
                sql.set_user_setting(chat.id, True)
                msg.reply_text(
                    "Turned on reporting! You'll be notified whenever anyone reports something."
                )

            elif args[0] in ("no", "off"):
                sql.set_user_setting(chat.id, False)
                msg.reply_text(
                    "Turned off reporting! You wont get any reports.")
        else:
            msg.reply_text(
                "Your current report preference is: `{}`".format(
                    sql.user_should_report(chat.id)),
                parse_mode=ParseMode.MARKDOWN,
            )

    else:
        if len(args) >= 1:
            if args[0] in ("yes", "on"):
                sql.set_chat_setting(chat.id, True)
                msg.reply_text(
                    "Turned on reporting! Admins who have turned on reports will be notified when /report "
                    "or @admin are called.")

            elif args[0] in ("no", "off"):
                sql.set_chat_setting(chat.id, False)
                msg.reply_text(
                    "Turned off reporting! No admins will be notified on /report or @admin."
                )
        else:
            msg.reply_text(
                "This chat's current setting is: `{}`".format(
                    sql.chat_should_report(chat.id)),
                parse_mode=ParseMode.MARKDOWN,
            )
Esempio n. 2
0
def __chat_settings__(chat_id, user_id):
    return "This chat is setup to send user reports to admins, via /report and @admin: `{}`".format(
        sql.chat_should_report(chat_id))
Esempio n. 3
0
def report(update, context) -> str:
    message = update.effective_message  # type: Optional[Message]
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]

    if chat and message.reply_to_message and sql.chat_should_report(chat.id):
        # type: Optional[User]
        reported_user = message.reply_to_message.from_user
        chat_name = chat.title or chat.first or chat.username
        admin_list = chat.get_administrators()
        messages = update.effective_message

        isadmeme = chat.get_member(reported_user.id).status
        if isadmeme == "administrator" or isadmeme == "creator":
            return ""  # No point of reporting admins!

        if user.id == reported_user.id:
            message.reply_text("Why the hell you're reporting yourself?")
            return ""

        if reported_user.id == context.bot.id:
            message.reply_text("I'm not gonna report myself!")
            return ""

        if chat.username and chat.type == Chat.SUPERGROUP:

            reported = f"Reported {mention_html(reported_user.id, reported_user.first_name)} to the admins!"

            msg = (
                f"<b>Report from: </b>{html.escape(chat.title)}\n"
                f"<b> ├Ч Report by:</b> {mention_html(user.id, user.first_name)}(<code>{user.id}</code>)\n"
                f"<b> ├Ч Reported user:</b> {mention_html(reported_user.id, reported_user.first_name)} (<code>{reported_user.id}</code>)\n"
            )
            link = f'<b> ├Ч Reported message:</b> <a href="https://t.me/{chat.username}/{message.reply_to_message.message_id}">click here</a>'
            should_forward = False
            keyboard = [
                [
                    InlineKeyboardButton(
                        "ЁЯТм Message",
                        url=
                        f"https://t.me/{chat.username}/{message.reply_to_message.message_id}",
                    ),
                    InlineKeyboardButton(
                        "тЪ╜ Kick",
                        callback_data=
                        f"report_{chat.id}=kick={reported_user.id}={reported_user.first_name}",
                    ),
                ],
                [
                    InlineKeyboardButton(
                        "тЫФя╕П Ban",
                        callback_data=
                        f"report_{chat.id}=banned={reported_user.id}={reported_user.first_name}",
                    ),
                    InlineKeyboardButton(
                        "тЭО Delete Message",
                        callback_data=
                        f"report_{chat.id}=delete={reported_user.id}={message.reply_to_message.message_id}",
                    ),
                ],
            ]
            reply_markup = InlineKeyboardMarkup(keyboard)
        else:
            reported = f"Reported {mention_html(reported_user.id, reported_user.first_name)} to the admins!"

            msg = f'{mention_html(user.id, user.first_name)} is calling for admins in "{html.escape(chat_name)}"!'
            link = ""
            should_forward = True

        for admin in admin_list:
            if admin.user.is_bot:  # can't message bots
                continue

            if sql.user_should_report(admin.user.id):
                try:
                    context.bot.send_message(
                        admin.user.id,
                        msg + link,
                        reply_markup=reply_markup,
                        parse_mode=ParseMode.HTML,
                    )
                    if should_forward:
                        message.reply_to_message.forward(admin.user.id)

                        if (
                                len(message.text.split()) > 1
                        ):  # If user is giving a reason, send his message too
                            message.forward(admin.user.id)

                except Unauthorized:
                    pass
                except BadRequest as excp:  # TODO: cleanup exceptions
                    if excp.message == "Message_id_invalid":
                        pass
                    else:
                        LOGGER.exception("Exception while reporting user " +
                                         excp.message)

        message.reply_to_message.reply_text(reported,
                                            parse_mode=ParseMode.HTML)
        return msg

    return ""
async def _(event):
    if event.is_private:
        return
    if await is_register_admin(event.input_chat, event.message.sender_id):
        return

    chat = event.chat_id
    user = event.sender
    args = event.pattern_match.group(1)

    if not sql.chat_should_report(chat):
        return

    if not event.chat.username:
        await event.reply(
            "Damn, this chat has no username so I can't markup the reported message."
        )
        return

    if event.reply_to_msg_id:
        c = await event.get_reply_message()
        reported_user = c.sender_id
        reported_user_first_name = c.sender.first_name
        if await is_register_admin(event.input_chat, reported_user):
            await event.reply("Why are you reporting an admin ?")
            return

        if not args:
            await event.reply("Add a reason for reporting first.")
            return

        if user.id == reported_user:
            await event.reply("Why are you reporting yourself ?")
            return

        if user.id == BOT_ID:
            await event.reply("Why are you reporting me ?")
            return

        if reported_user == OWNER_ID:
            await event.reply("Hey, don't dare reporting my master !")
            return

        msg = (
            f"<b>⚠️ Report: </b>{html.escape(event.chat.title)}\n"
            f"<b> • Report by:</b> <p><a href='tg://user?id={user.id}'>{user.first_name}</a></p> (<code>{user.id}</code>)\n"
            f"<b> • Reported user:</b> <p><a href='tg://user?id={reported_user}'>{reported_user_first_name}</a></p> (<code>{reported_user}</code>)\n"
            f"<b> • Reason:</b> {args}")
        buttons = [
            [
                Button.url(
                    "➡ Message",
                    url=f"https://t.me/{event.chat.username}/{c.id}",
                )
            ],
            [
                Button.inline(
                    "⚠ Kick",
                    data=f"report_{chat}=kick={reported_user}",
                ),
                Button.inline(
                    "⛔️ Ban",
                    data=f"report_{chat}=banned={reported_user}",
                ),
            ],
            [
                Button.inline(
                    "❎ Delete Message",
                    data=f"report_{chat}=delete={reported_user}={c.id}",
                )
            ],
        ]

        async for userr in tbot.iter_participants(
                event.chat_id, filter=ChannelParticipantsAdmins):
            try:
                if userr.bot:
                    pass
                else:
                    await tbot.send_message(userr.id,
                                            msg,
                                            buttons=buttons,
                                            parse_mode="html")
                    await tbot.send_message(
                        userr.id,
                        "**In case if the original message was deleted by the accused, a copy is sent to you as below 👇**",
                    )
                    await c.forward_to(userr.id)
            except Exception:
                pass

        try:
            await tbot.send_message(
                event.chat_id,
                f"<p><a href='tg://user?id={user.id}'>{user.first_name}</a></p> reported <p><a href='tg://user?id={reported_user}'>{reported_user_first_name}</a></p> to the admins!",
                parse_mode="html",
            )
        except Exception:
            pass

        await event.delete()

    else:
        await event.reply("Reply to a message to report it to the admins.")