def reset_warns(update: Update, context: CallbackContext) -> str: args = context.args message: Optional[Message] = update.effective_message chat: Optional[Chat] = update.effective_chat user: Optional[User] = update.effective_user user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warns have been reset!") warned = chat.get_member(user_id).user return (f"<b>{html.escape(chat.title)}:</b>\n" f"#RESETWARNS\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(warned.id, warned.first_name)}") else: message.reply_text("No user has been designated!") return ""
def reset_warns(update: Update, context: CallbackContext) -> str: args = context.args message = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] if user_can_ban(chat, user, context.bot.id) == False: message.reply_text("You are missing the following rights to use this command:CanRestrictUsers!") return "" user_id = extract_user(message, args) if user_id: sql.reset_warns(user_id, chat.id) message.reply_text("Warns have been reset!") warned = chat.get_member(user_id).user return (f"<b>{html.escape(chat.title)}:</b>\n" f"#RESETWARNS\n" f"<b>Admin:</b> {mention_html(user.id, user.first_name)}\n" f"<b>User:</b> {mention_html(warned.id, warned.first_name)}") else: message.reply_text("No user has been designated!") return ""
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn admins, They are too far to be One Punched!") return if user.id in TIGER_USERS: if warner: message.reply_text("Tigers cant be warned.") else: message.reply_text( "Tiger triggered an auto warn filter!\n I can't warn tigers but they should avoid abusing this." ) return if user.id in WHITELIST_USERS: if warner: message.reply_text("Wolf disasters are warn immune.") else: message.reply_text( "Wolf Disaster triggered an auto warn filter!\nI can't warn wolves but they should avoid abusing this." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = f"{limit} warnings, *Punches {mention_html(user.id, user.first_name)} with a normal punch!* " else: # ban chat.kick_member(user.id) reply = f"{limit} warnings, *Punches {mention_html(user.id, user.first_name)} with a Serious Punch* " for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = [] log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([{ InlineKeyboardButton("Remove warn", callback_data="rm_warn({})".format(user.id)) }]) reply = f"{mention_html(user.id, user.first_name)} has {num_warns}/{limit} warnings... watch out!" if reason: reply += f"\nReason for last warn:\n{html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn these admins, We cannot warn them!") return if user.id in TIGERS: if warner: message.reply_text("Tigers can't be warned.") else: message.reply_text( "Tiger triggered an auto warn filter!\n I can't warn tigers but they should avoid abusing this." ) return if user.id in WOLVES: if warner: message.reply_text("Wolf disasters are warn immune.") else: message.reply_text( "Wolf Disaster triggered an auto warn filter!\nI can't warn wolves but they should avoid abusing this." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = ( f"<code>�</code><b>Punch Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") else: # ban chat.kick_member(user.id) reply = ( f"<code>�</code><b>Ban Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" # message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = None log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton("🔘 Remove warn", callback_data="rm_warn({})".format(user.id)) ]]) reply = ( f"<code>�</code><b>Warn Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Reason:</b> {html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def warn( user: User, chat: Chat, reason: str, message: Message, warner: User = None, ) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn admins, They are too far to be One Punched!") return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = ( f"<code>❕</code><b>Punch Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") else: # ban chat.ban_member(user.id) reply = ( f"<code>❕</code><b>Ban Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" keyboard = None log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([ [ InlineKeyboardButton( "• Remove warn ", callback_data="rm_warn({})".format(user.id), ), ], [ InlineKeyboardButton( text="• Rules", url=f"t.me/{dispatcher.bot.username}?start={chat.id}", ), ], ], ) reply = ( f"<code>❕</code><b>Warn Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Reason:</b> {html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False, ) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn admins, They are too far to be One Punched!") return if user.id in TIGER_USERS: if warner: message.reply_text("Kaplanlar uyarılamaz.") else: message.reply_text( "Tiger otomatik uyarı filtresini tetikledi!\nKaplanları uyaramıyorum ama bunu kötüye kullanmaktan kaçınmalılar." ) return if user.id in WHITELIST_USERS: if warner: message.reply_text("Kurt felaketleri bağışıklığı uyarıyor.") else: message.reply_text( "Kurt Felaketi otomatik uyarı filtresini tetikledi!\nKolları uyaramıyorum, ancak bunu kötüye kullanmaktan kaçınmaları gerekiyor." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Otomatik uyarı filtresi." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = f"{limit} warnings, *Punches {mention_html(user.id, user.first_name)} normal bir yumruk ile!* " else: # ban chat.kick_member(user.id) reply = f"{limit} warnings, *Punches {mention_html(user.id, user.first_name)} normal bir yumruk ile* " for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = [] log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>Kulllanıcı:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Sebep:</b> {reason}\n" f"<b>Sayımları:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([{ InlineKeyboardButton("Uyarıyı kaldır", callback_data="rm_warn({})".format(user.id)) }]) reply = f"{mention_html(user.id, user.first_name)} has {num_warns}/{limit} warnings... watch out!" if reason: reply += f"\nSon uyarmanın nedeni:\n{html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>Kullanıcı:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Sebep:</b> {reason}\n" f"<b>Sayımları:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Yanıt mesajı bulunamadı": # Do not reply message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn admins, They are too far to be One Punched!") return if user.id in TIGERS: if warner: message.reply_text("Pələng istifadəçilər bilməz.") else: message.reply_text( "Pələng istifadəçilərə xəbərdarlıq verə bilmərəm!" ) return if user.id in WOLVES: if warner: message.reply_text("Canavar istifadəçilərin xəbərdarlığa qarşı immuniteti var.") else: message.reply_text( "Canavar istifadəçilərin xəbərdarlığa qarşı immuniteti var." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Xəbərdarlıq filtri." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = ( f"<code>❕</code><b>Qrupdan atıldı</b>\n" f"<code> </code><b>• İstifadəçi:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Limit:</b> {limit}") else: # ban chat.kick_member(user.id) reply = ( f"<code>❕</code><b>Banlandı</b>\n" f"<code> </code><b>• İstifadəçi:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Limit:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = None log_reason = (f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton( "🔘 Xəbərdarlığı sil", callback_data="rm_warn({})".format(user.id)) ]]) reply = ( f"<code>❕</code><b>Xəbərdarlıq</b>\n" f"<code> </code><b>• İstifadəçi:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Say/limit:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Səbəb:</b> {html.escape(reason)}" log_reason = (f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): message.reply_text("Nyah!! admins, They are too far to be eliminated!") return if user.id in TIGERS: if warner: message.reply_text("Blades cant be warned.") else: message.reply_text( "Nyah a blade triggered an auto warn filter!\n I can't warn balde but trysweet sama is watching!! " ) return if user.id in WOLVES: if warner: message.reply_text( "This kitty has a shield given by trysweet sama?!") else: message.reply_text( " A shield user triggered an auto warn filter!\nI can't warn them but they should avoid abusing this." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = ( f"<code>❕</code><b>Punch Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") else: # ban chat.kick_member(user.id) reply = ( f"<code>❕</code><b>Ban Carnival</b>\n" f"<code> </code><b>• The Prey:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" # message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = None log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton("🔘 Release warn", callback_data="rm_warn({})".format(user.id)) ]]) reply = ( f"<code>❕</code><b>Warn Event</b>\n" f"<code> </code><b>• User:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Count:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Reason:</b> {html.escape(reason)}" log_reason = ( f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>User:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Reason:</b> {reason}\n" f"<b>Counts:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: if is_user_admin(chat, user.id): # message.reply_text("Damn admins, They are too far to be One Punched!") return if user.id in TIGERS: if warner: message.reply_text("Los tigres no pueden ser advertidos.") else: message.reply_text( "¡El tigre activó un filtro de advertencia automática! \nNo puedo advertir a los tigres, pero deberÃan evitar abusar de esto." ) return if user.id in WOLVES: if warner: message.reply_text("Los desastres de lobo son inmunes a las advertencias.") else: message.reply_text( "¡El lobo activó un filtro de advertencia automática! \nNo puedo advertir a los lobos, pero deben evitar abusar de esto." ) return if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Filtro de advertencia automatizado." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # punch chat.unban_member(user.id) reply = ( f"<code>â�•</code><b>Evento de advertencias</b>\n" f"<code> </code><b>• Usuario:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Número de advertencias:</b> {limit}") else: # ban chat.kick_member(user.id) reply = ( f"<code>â�•</code><b>Evento de baneo</b>\n" f"<code> </code><b>• Usuario:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Número de advertencias:</b> {limit}") for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" # message.bot.send_sticker(chat.id, BAN_STICKER) # Saitama's sticker keyboard = None log_reason = (f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN_BAN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>Usuario:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Razón:</b> {reason}\n" f"<b>Número de advertencias:</b> <code>{num_warns}/{limit}</code>") else: keyboard = InlineKeyboardMarkup([[ InlineKeyboardButton( "🔘 Remover advertencia", callback_data="rm_warn({})".format(user.id)) ]]) reply = ( f"<code>â�•</code><b>Evento de advertencia</b>\n" f"<code> </code><b>• Usuario:</b> {mention_html(user.id, user.first_name)}\n" f"<code> </code><b>• Número de advertencias:</b> {num_warns}/{limit}") if reason: reply += f"\n<code> </code><b>• Razón:</b> {html.escape(reason)}" log_reason = (f"<b>{html.escape(chat.title)}:</b>\n" f"#WARN\n" f"<b>Admin:</b> {warner_tag}\n" f"<b>Usuario:</b> {mention_html(user.id, user.first_name)}\n" f"<b>Razón:</b> {reason}\n" f"<b>Número de advertencias:</b> <code>{num_warns}/{limit}</code>") try: message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "No encuentro el mensaje que respondiste.": # Do not reply message.reply_text( reply, reply_markup=keyboard, parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason