version 1.4.4: MarkdownV2 dot escape fix в show_users, try/except для бота
- bot.py: числа трафика в бэктиках (избегание unescaped dots в MarkdownV2) - bot.py: try/except в show_users с выводом ошибки пользователю
This commit is contained in:
@@ -150,6 +150,7 @@ async def show_main(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
async def show_users(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
query = update.callback_query
|
||||
await query.answer()
|
||||
try:
|
||||
cfg = load_mita_config()
|
||||
users = cfg.get("users", [])
|
||||
if not users:
|
||||
@@ -197,8 +198,8 @@ async def show_users(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
s = stats_map.get(name, {})
|
||||
w = "🟢" if name in warp_users else "⚪"
|
||||
o = "🟢" if s.get("online") else "🔴"
|
||||
day = f"{s.get('day_mb', 0):.1f} МБ" if s.get("day_mb") else "—"
|
||||
mon = f"{s.get('month_mb', 0):.1f} МБ" if s.get("month_mb") else "—"
|
||||
day = f"`{s.get('day_mb', 0):.1f} МБ`" if s.get("day_mb") else "—"
|
||||
mon = f"`{s.get('month_mb', 0):.1f} МБ`" if s.get("month_mb") else "—"
|
||||
ename = escape_md(name)
|
||||
lines.append(f"{o} {ename} {w} д:{day} м:{mon}")
|
||||
user_buttons.append([InlineKeyboardButton(
|
||||
@@ -206,32 +207,40 @@ async def show_users(update: Update, context: ContextTypes.DEFAULT_TYPE):
|
||||
callback_data=f"user_{name}"
|
||||
)])
|
||||
|
||||
# Ограничение Telegram: 4096 символов на сообщение
|
||||
user_buttons.extend([
|
||||
[InlineKeyboardButton("➕ Создать", callback_data="create"),
|
||||
InlineKeyboardButton("🗑 Удалить", callback_data="delete_menu")],
|
||||
[InlineKeyboardButton("🔄 WARP", callback_data="warp_menu")],
|
||||
[InlineKeyboardButton("« Назад", callback_data="main")],
|
||||
])
|
||||
|
||||
text = "\n".join(lines)
|
||||
if len(text) > 4000:
|
||||
text = text[:3997] + "…"
|
||||
if len(user_buttons) > 96:
|
||||
user_buttons = user_buttons[:96]
|
||||
|
||||
user_buttons.extend([
|
||||
[InlineKeyboardButton("➕ Создать", callback_data="create"),
|
||||
InlineKeyboardButton("🗑 Удалить", callback_data="delete_menu")],
|
||||
[InlineKeyboardButton("🔄 WARP", callback_data="warp_menu")],
|
||||
[InlineKeyboardButton("« Назад", callback_data="main")],
|
||||
])
|
||||
|
||||
user_buttons.extend([
|
||||
[InlineKeyboardButton("➕ Создать", callback_data="create"),
|
||||
InlineKeyboardButton("🗑 Удалить", callback_data="delete_menu")],
|
||||
[InlineKeyboardButton("🔄 WARP", callback_data="warp_menu")],
|
||||
[InlineKeyboardButton("« Назад", callback_data="main")],
|
||||
])
|
||||
|
||||
await query.edit_message_text(
|
||||
text,
|
||||
reply_markup=InlineKeyboardMarkup(user_buttons),
|
||||
parse_mode="MarkdownV2"
|
||||
)
|
||||
except Exception as e:
|
||||
_log.error("show_users failed: %s", e, exc_info=True)
|
||||
try:
|
||||
await query.edit_message_text(
|
||||
f"⚠ Ошибка загрузки пользователей:\n`{e}`",
|
||||
reply_markup=back_button(),
|
||||
parse_mode="MarkdownV2"
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
_log.error("show_users failed: %s", e)
|
||||
await query.edit_message_text(
|
||||
f"⚠ Ошибка: {e}",
|
||||
reply_markup=back_button()
|
||||
)
|
||||
|
||||
# ── create ────────────────────────────────────────────────────────────────────
|
||||
@admin_only
|
||||
|
||||
Reference in New Issue
Block a user