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)
def report(update: Update, context: CallbackContext) -> str: bot = context.bot 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 chat_name = chat.title or chat.first or chat.username admin_list = chat.get_administrators() if reported_user.id in REPORT_IMMUNE_USERS: message.reply_text("Uh? You reporting whitelisted users?") 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 = False 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 chat.type != Chat.SUPERGROUP: bot.send_message(admin.user.id, msg + link, 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) if not chat.username: bot.send_message(admin.user.id, msg + link, 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) if chat.username and chat.type == Chat.SUPERGROUP: bot.send_message( admin.user.id, msg + link, parse_mode=ParseMode.HTML, reply_markup=reply_markup, ) 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: # TODO: cleanup exceptions LOGGER.exception("Exception while reporting user") message.reply_to_message.reply_text( "{} reported the message to the admins.".format( mention_html(user.id, user.first_name)), parse_mode=ParseMode.HTML, ) return msg return ""
def __chat_settings__(_, __, 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))