65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
from config import conf
|
|
from aiogram import Bot, Dispatcher, types
|
|
from aiogram.fsm.storage.memory import MemoryStorage
|
|
from aiogram import F
|
|
from zabbix import event_close
|
|
from zabbix import event_acknowledge
|
|
import logging as log
|
|
|
|
tg_bot = Bot(token=conf.tgbot.token)
|
|
storage = MemoryStorage()
|
|
dp = Dispatcher(storage=storage)
|
|
|
|
|
|
@dp.callback_query(F.data.startswith("h"))
|
|
async def handle_mute_1h(callback_query: types.CallbackQuery):
|
|
|
|
if event_acknowledge(
|
|
int(callback_query.data[1:]),
|
|
1,
|
|
callback_query.from_user.username,
|
|
):
|
|
new_text = (
|
|
callback_query.message.text
|
|
+ "\n"
|
|
+ callback_query.from_user.username
|
|
+ " Замьютил на час"
|
|
)
|
|
await callback_query.message.edit_text(new_text)
|
|
|
|
|
|
@dp.callback_query(F.data.startswith("d"))
|
|
async def handle_mute_1d(callback_query: types.CallbackQuery):
|
|
if event_acknowledge(
|
|
int(callback_query.data[1:]),
|
|
24,
|
|
callback_query.from_user.username,
|
|
):
|
|
new_text = (
|
|
callback_query.message.text
|
|
+ "\n"
|
|
+ callback_query.from_user.username
|
|
+ " Замьютил на сутки"
|
|
)
|
|
await callback_query.message.edit_text(new_text)
|
|
|
|
|
|
@dp.callback_query(F.data.startswith("c"))
|
|
async def handle_close(callback_query: types.CallbackQuery):
|
|
if event_close(
|
|
int(callback_query.data[1:]),
|
|
callback_query.from_user.username,
|
|
):
|
|
new_text = (
|
|
callback_query.message.text
|
|
+ "\n"
|
|
+ callback_query.from_user.username
|
|
+ " Закрыл"
|
|
)
|
|
await callback_query.message.edit_text(new_text)
|
|
|
|
|
|
async def start_bot():
|
|
log.info("Telegram bot loop started")
|
|
await dp.start_polling(tg_bot)
|