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: # kick chat.unban_member(user.id) reply = f"{limit} warnings, {mention_html(user.id, user.first_name)} with a normal warn! " else: # ban chat.kick_member(user.id) reply = f"{limit} warnings, {mention_html(user.id, user.first_name)} with a Serious warn " for warn_reason in reasons: reply += f"\n - {html.escape(warn_reason)}" message.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie 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...❌️❌️❌️ ഇത് നിനക്കുള്ള താക്കീത് ആണ്.. ആവർത്തിച്ചാൽ താക്കോലിട്ട് പൂട്ടികളയും!" if reason: reply += f"\nReason for last warn:\n{html.escape(reason)}" log_reason = (f"<b>{html.escape(chat.title)}:</b>\n" f"#WARNn<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 __import_data__(chat_id, data): for user_id, count in data.get('warns', {}).items(): for x in range(int(count)): sql.warn_user(user_id, chat_id)