python_bot/handlers/sendalarm.py

29 lines
979 B
Python
Raw Normal View History

2022-12-11 20:48:14 +10:00
from create_bot import dp, bot
2022-12-11 20:48:14 +10:00
from aiogram import types, Dispatcher
from sqdb import user, session
2022-12-11 20:48:14 +10:00
@dp.message_handler(commands=['sendall'])
async def sendall(message: types.Message):
print('команда прошла')
2022-12-11 20:48:14 +10:00
if message.chat.type == 'private':
if message.from_user.id == 226765676:
text = message.text[9:]
try:
2023-07-14 02:38:51 +10:00
chats_id = -1001355646177
try:
await bot.send_message(chats_id, text)
except:
2022-12-11 20:48:14 +10:00
print('вероятно бота нет в чате')
await bot.send_message(message.from_user.id, 'Сообщение успешно отправлено во все чаты')
except:
session.rollback()
print('eror sendall')
finally: session.close_all()
# def register_handlers_test(dp: Dispatcher):
# dp.register_message_handler(send_welcome)