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 # type: Optional[User] chat_name = chat.title or chat.first or chat.username 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 ""
def report_setting(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return 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("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) msg.reply_text("Mematikan pelaporan! Anda tidak akan mendapatkan laporan apa pun.") else: msg.reply_text("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) msg.reply_text("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) msg.reply_text("Mematikan pelaporan! Tidak ada admin yang akan diberitahukan ketika seseorang menyebut /report atau @admin.") else: msg.reply_text("Pengaturan obrolan saat ini adalah: `{}`".format(sql.chat_should_report(chat.id)), parse_mode=ParseMode.MARKDOWN)
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) 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)
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] 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) #link = "\n<b>Link:</b> " \ # "<a href=\"http://telegram.me/{}/{}\">klik disini</a>".format(chat.username, message.message_id) else: msg = tl(update.effective_message, "{} memanggil admin di \"{}\"!").format( mention_html(user.id, user.first_name), html.escape(chat_name)) #link = "" 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: #bot.send_message(admin.user.id, msg + link, parse_mode=ParseMode.HTML) #bot.send_message(admin.user.id, msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup) 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: pass context.bot.send_message(admin.user.id, msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup) except Unauthorized: pass except BadRequest as excp: # TODO: cleanup exceptions LOGGER.exception("Exception while reporting user") return msg return ""
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))
def report(bot: Bot, update: Update) -> str: spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id) if spam == True: return update.effective_message.reply_text( "Saya kecewa dengan anda, saya tidak akan mendengar kata-kata anda sekarang!" ) message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] global msg global keyboard 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 chat.username and chat.type == Chat.SUPERGROUP: msg = "<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) #link = "\n<b>Link:</b> " \ # "<a href=\"http://telegram.me/{}/{}\">klik disini</a>".format(chat.username, message.message_id) keyboard = [[ InlineKeyboardButton( u"⚠️ Pesan yang dilaporkan", url="https://t.me/{}/{}".format( chat.username, str(message.reply_to_message.message_id))) ], [ InlineKeyboardButton( u"⚠️ Tendang", callback_data="report_{}=kick={}={}".format( chat.id, reported_user.id, reported_user.first_name)), InlineKeyboardButton( u"⛔️ Banned", callback_data="report_{}=banned={}={}".format( chat.id, reported_user.id, reported_user.first_name)) ], [ InlineKeyboardButton( u"Hapus pesan", callback_data="report_{}=delete={}={}".format( chat.id, reported_user.id, message.reply_to_message.message_id)) ], [ InlineKeyboardButton( u"Tutup Tombol", callback_data="report_{}=close={}={}".format( chat.id, reported_user.id, reported_user.first_name)) ]] reply_markup = InlineKeyboardMarkup(keyboard) should_forward = True bot.send_message( chat.id, "<i>⚠️ Pesan telah di laporkan ke semua admin!</i>", parse_mode=ParseMode.HTML, reply_to_message_id=message.message_id) else: msg = "{} memanggil admin di \"{}\"!".format( mention_html(user.id, user.first_name), html.escape(chat_name)) #link = "" reply_markup = "" should_forward = True bot.send_message( chat.id, "<i>⚠️ Pesan telah di laporkan ke semua admin!</i>", parse_mode=ParseMode.HTML, reply_to_message_id=message.message_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: #bot.send_message(admin.user.id, msg + link, parse_mode=ParseMode.HTML) #bot.send_message(admin.user.id, msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup) 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: pass bot.send_message(admin.user.id, msg, parse_mode=ParseMode.HTML, reply_markup=reply_markup) except Unauthorized: pass except BadRequest as excp: # TODO: cleanup exceptions LOGGER.exception("Exception while reporting user") return msg return ""