Add inline alerts menu with callbacks
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime, timedelta, timezone
|
from datetime import datetime, timedelta, timezone
|
||||||
from aiogram import F
|
from aiogram import F
|
||||||
from aiogram.types import Message
|
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
from app import dp, bot, cfg, ADMIN_ID
|
from app import dp, bot, cfg, ADMIN_ID
|
||||||
from auth import is_admin_msg
|
from auth import is_admin_msg
|
||||||
from services.alert_mute import set_mute, clear_mute, list_mutes
|
from services.alert_mute import set_mute, clear_mute, list_mutes
|
||||||
@@ -88,6 +88,25 @@ async def _handle_alerts(msg: Message, action: str, args: list[str]):
|
|||||||
await msg.answer(HELP_TEXT)
|
await msg.answer(HELP_TEXT)
|
||||||
|
|
||||||
|
|
||||||
|
ALERTS_KB = InlineKeyboardMarkup(
|
||||||
|
inline_keyboard=[
|
||||||
|
[
|
||||||
|
InlineKeyboardButton(text="List", callback_data="alerts:list"),
|
||||||
|
InlineKeyboardButton(text="Recent 24h", callback_data="alerts:recent:24"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
InlineKeyboardButton(text="Mute load 60m", callback_data="alerts:mute:load:60"),
|
||||||
|
InlineKeyboardButton(text="Unmute load", callback_data="alerts:unmute:load"),
|
||||||
|
],
|
||||||
|
[
|
||||||
|
InlineKeyboardButton(text="Test CRIT", callback_data="alerts:test:critical"),
|
||||||
|
InlineKeyboardButton(text="Test WARN", callback_data="alerts:test:warn"),
|
||||||
|
InlineKeyboardButton(text="Test INFO", callback_data="alerts:test:info"),
|
||||||
|
],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dp.message(F.text.startswith("/alerts"))
|
@dp.message(F.text.startswith("/alerts"))
|
||||||
async def alerts_cmd(msg: Message):
|
async def alerts_cmd(msg: Message):
|
||||||
if not is_admin_msg(msg):
|
if not is_admin_msg(msg):
|
||||||
@@ -95,7 +114,7 @@ async def alerts_cmd(msg: Message):
|
|||||||
|
|
||||||
parts = msg.text.split()
|
parts = msg.text.split()
|
||||||
if len(parts) < 2:
|
if len(parts) < 2:
|
||||||
await msg.answer(HELP_TEXT)
|
await msg.answer(HELP_TEXT, reply_markup=ALERTS_KB)
|
||||||
return
|
return
|
||||||
|
|
||||||
action = parts[1].lower()
|
action = parts[1].lower()
|
||||||
@@ -122,3 +141,19 @@ async def alerts_mute_load(msg: Message):
|
|||||||
if not is_admin_msg(msg):
|
if not is_admin_msg(msg):
|
||||||
return
|
return
|
||||||
await _handle_alerts(msg, "mute", ["load", "60"])
|
await _handle_alerts(msg, "mute", ["load", "60"])
|
||||||
|
|
||||||
|
|
||||||
|
@dp.callback_query(F.data.startswith("alerts:"))
|
||||||
|
async def alerts_cb(cb: CallbackQuery):
|
||||||
|
if cb.from_user.id != ADMIN_ID:
|
||||||
|
await cb.answer()
|
||||||
|
return
|
||||||
|
parts = cb.data.split(":")
|
||||||
|
# formats: alerts:action or alerts:action:arg1:arg2
|
||||||
|
if len(parts) < 2:
|
||||||
|
await cb.answer()
|
||||||
|
return
|
||||||
|
action = parts[1]
|
||||||
|
args = parts[2:] if len(parts) > 2 else []
|
||||||
|
await _handle_alerts(cb.message, action, args)
|
||||||
|
await cb.answer()
|
||||||
|
|||||||
Reference in New Issue
Block a user