示例#1
0
def report_alt(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):
		reported_user = message.reply_to_message.from_user
		admin_list = chat.get_administrators()

		msg = tl(update.effective_message, "<b>{}:</b>"
			  "\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)"
			  "\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(html.escape(chat.title),
																	  mention_html(
																		  reported_user.id,
																		  reported_user.first_name),
																	  reported_user.id,
																	  mention_html(user.id,
																				   user.first_name),
																	  user.id)
		all_admins = []
		for admin in admin_list:
			if admin.user.is_bot:  # don't tag bot
				continue

			if sql.user_should_report(admin.user.id):
				all_admins.append("<a href='tg://user?id={}'>⁣</a>".format(admin.user.id))

		context.bot.send_message(chat.id, tl(update.effective_message, "⚠️ {} <b>telah di laporkan ke admin!</b>{}").format(
					mention_html(reported_user.id, reported_user.first_name),
					"".join(all_admins)), parse_mode=ParseMode.HTML, reply_to_message_id=message.reply_to_message.message_id)
		return msg

	return ""
示例#2
0
def report_setting(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    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(tld(chat.id, "reports_pm_on"))

            elif args[0] in ("no", "off"):
                sql.set_user_setting(chat.id, False)
                msg.reply_text(tld(chat.id, "reports_pm_off"))
        else:
            msg.reply_text(tld(chat.id, "reports_pm_pref").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(tld(chat.id, "reports_chat_on"))

            elif args[0] in ("no", "off"):
                sql.set_chat_setting(chat.id, False)
                msg.reply_text(tld(chat.id, "reports_chat_off"))
        else:
            msg.reply_text(tld(chat.id, "reports_chat_pref").format(
                sql.chat_should_report(chat.id)),
                           parse_mode=ParseMode.MARKDOWN)
示例#3
0
文件: reporting.py 项目: MhdRezza/Eva
def report_setting(bot: Bot, update: Update, args: List[str]):
    chat = update.effective_chat  # type: Optional[Chat]
    msg = update.effective_message  # type: Optional[Message]

    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)
示例#4
0
def report_setting(update, context):
    chat = update.effective_chat
    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)
                send_message(update.effective_message, tl(update.effective_message,
                                                          "Menghidupkan pelaporan! Anda akan diberi tahu setiap kali ada yang melaporkan sesuatu."))

            elif args[0] in ("no", "off"):
                sql.set_user_setting(chat.id, False)
                send_message(update.effective_message, tl(update.effective_message,
                                                          "Mematikan pelaporan! Anda tidak akan mendapatkan laporan apa pun."))
        else:
            send_message(update.effective_message,
                         tl(update.effective_message, "Preferensi laporan Anda saat ini: `{}`").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)
                send_message(update.effective_message, tl(update.effective_message,
                                                          "Menghidupkan pelaporan! Admin yang telah mengaktifkan laporan akan diberi tahu ketika seseorang menyebut /report "
                                                          "atau @admin."))

            elif args[0] in ("no", "off"):
                sql.set_chat_setting(chat.id, False)
                send_message(update.effective_message, tl(update.effective_message,
                                                          "Mematikan pelaporan! Tidak ada admin yang akan diberitahukan ketika seseorang menyebut /report atau @admin."))
        else:
            send_message(update.effective_message,
                         tl(update.effective_message, "Pengaturan obrolan saat ini adalah: `{}`").format(
                             sql.chat_should_report(chat.id)),
                         parse_mode=ParseMode.MARKDOWN)
示例#5
0
def report(bot: Bot, update: Update) -> 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):
        reported_user = message.reply_to_message.from_user  # type: Optional[User]
        chat_name = chat.title or chat.first or chat.username
        admin_list = chat.get_administrators()

        if int(reported_user.id) == int(user.id):
            return ""

        if chat.username and chat.type == Chat.SUPERGROUP:
            msg = "<b>{}:</b>" \
                  "\n<b>Reported user:</b> {} (<code>{}</code>)" \
                  "\n<b>Reported by:</b> {} (<code>{}</code>)".format(html.escape(chat.title),
                                                                      mention_html(
                                                                          reported_user.id,
                                                                          reported_user.first_name),
                                                                      reported_user.id,
                                                                      mention_html(user.id,
                                                                                   user.first_name),
                                                                      user.id)
            link = "\n<b>Link:</b> " \
                   "<a href=\"http://telegram.me/{}/{}\">click here</a>".format(chat.username, message.message_id)

            should_forward = True
            keyboard = [[
                InlineKeyboardButton(
                    u"➡ Message",
                    url="https://t.me/{}/{}".format(
                        chat.username,
                        str(message.reply_to_message.message_id)))
            ],
                        [
                            InlineKeyboardButton(
                                u"⚠ Kick",
                                callback_data="report_{}=kick={}={}".format(
                                    chat.id, reported_user.id,
                                    reported_user.first_name)),
                            InlineKeyboardButton(
                                u"⛔️ Ban",
                                callback_data="report_{}=banned={}={}".format(
                                    chat.id, reported_user.id,
                                    reported_user.first_name))
                        ],
                        [
                            InlineKeyboardButton(
                                u"❎ Delete Message",
                                callback_data="report_{}=delete={}={}".format(
                                    chat.id, reported_user.id,
                                    message.reply_to_message.message_id))
                        ]]
            reply_markup = InlineKeyboardMarkup(keyboard)

        else:
            msg = "{} is calling for admins in \"{}\"!".format(
                mention_html(user.id, user.first_name), 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:
                    if not chat.type == Chat.SUPERGROUP:
                        bot.send_message(admin.user.id,
                                         msg + link,
                                         parse_mode=ParseMode.HTML,
                                         disable_web_page_preview=True)

                        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)

                    if not chat.username:
                        bot.send_message(admin.user.id,
                                         msg + link,
                                         parse_mode=ParseMode.HTML,
                                         disable_web_page_preview=True)

                        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)

                    if chat.username and chat.type == Chat.SUPERGROUP:
                        bot.send_message(admin.user.id,
                                         msg + link,
                                         parse_mode=ParseMode.HTML,
                                         reply_markup=reply_markup,
                                         disable_web_page_preview=True)

                        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
                    LOGGER.exception(
                        f"Exception while reporting user : {excp}")

        message.reply_to_message.reply_text(tld(
            chat.id,
            "reports_success").format(mention_html(user.id, user.first_name)),
                                            parse_mode=ParseMode.HTML,
                                            disable_web_page_preview=True)
        return msg

    return ""
示例#6
0
文件: reporting.py 项目: MhdRezza/Eva
def __chat_settings__(bot, update, chat, chatP, user):
    return "This chat is setup to send user reports to admins, via /report and @admin: `{}`".format(
        sql.chat_should_report(chat.id))
示例#7
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]
    bot = context.bot
    global CURRENT_REPORT

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

        a, b = user_protection_checker(bot, message.reply_to_message.from_user.id)
        if not a:
            return ""

        admin_list = chat.get_administrators()

        if chat.username and chat.type == Chat.SUPERGROUP:
            msg = tl(update.effective_message, "<b>{}:</b>"
                                               "\n<b>Pengguna yang dilaporkan:</b> {} (<code>{}</code>)"
                                               "\n<b>Dilaporkan oleh:</b> {} (<code>{}</code>)").format(
                html.escape(chat.title),
                mention_html(
                    reported_user.id,
                    reported_user.first_name),
                reported_user.id,
                mention_html(user.id,
                             user.first_name),
                user.id)

        else:
            msg = tl(update.effective_message, "{} memanggil admin di \"{}\"!").format(
                mention_html(user.id, user.first_name),
                html.escape(chat_name))

        if chat.username:
            chatlink = "https://t.me/{}/{}".format(chat.username, str(message.reply_to_message.message_id))
        else:
            chatlink = "https://t.me/c/{}/{}".format(str(chat.id)[4:], str(message.reply_to_message.message_id))
        keyboard = [
            [InlineKeyboardButton(tl(update.effective_message, "⚠️ Pesan yang dilaporkan"), url=chatlink)],
            [InlineKeyboardButton(tl(update.effective_message, "⚠️ Tendang"),
                                  callback_data="rp_{}=1={}".format(chat.id, reported_user.id)),
             InlineKeyboardButton(tl(update.effective_message, "⛔️ Banned"),
                                  callback_data="rp_{}=2={}".format(chat.id, reported_user.id))],
            [InlineKeyboardButton(tl(update.effective_message, "Hapus pesan"),
                                  callback_data="rp_{}=3={}".format(chat.id, message.reply_to_message.message_id))],
            [InlineKeyboardButton(tl(update.effective_message, "Tutup Tombol"),
                                  callback_data="rp_{}=4={}".format(chat.id, reported_user.id))]
        ]
        reply_markup = InlineKeyboardMarkup(keyboard)

        should_forward = True
        context.bot.send_message(chat.id,
                                 tl(update.effective_message, "<i>⚠️ Pesan telah di laporkan ke semua admin!</i>"),
                                 parse_mode=ParseMode.HTML, reply_to_message_id=message.message_id)

        CURRENT_REPORT[str(chat.id)] = msg
        CURRENT_REPORT[str(chat.id) + "key"] = reply_markup
        CURRENT_REPORT[str(chat.id) + "user"] = {'name': reported_user.first_name, 'id': reported_user.id,
                                                 'rname': user.first_name, 'rid': user.id}
        for admin in admin_list:
            if admin.user.is_bot:  # can't message bots
                continue

            if sql.user_should_report(admin.user.id):
                try:

                    try:
                        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 Exception:
                        pass
                    context.bot.send_message(admin.user.id, msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup)

                except Unauthorized:
                    pass
                except BadRequest:  # TODO: cleanup exceptions
                    LOGGER.exception("Exception while reporting user")
        return msg

    return ""
示例#8
0
def __chat_settings__(chat_id, user_id):
    return tl(user_id,
              "Obrolan ini disetel untuk mengirim laporan pengguna ke admin, melalui /report dan @admin: `{}`").format(
        sql.chat_should_report(chat_id))