Pavel_Duron
71b87a97ff
All checks were successful
continuous-integration/drone/push Build is passing
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
|
|
from aiogram import types, Dispatcher
|
|
|
|
from sqdb import session, user
|
|
from create_bot import bot, dp
|
|
|
|
@dp.message_handler(commands=['sendall'])
|
|
async def sendalarm(message: types.Message):
|
|
print('начал работать')
|
|
if message.chat.type == 'private':
|
|
if message.from_user.id == 226765676:
|
|
text = message.text[9:]
|
|
try:
|
|
chats_id = session.query(user.chat_id).distinct()
|
|
for row in chats_id:
|
|
try:
|
|
await bot.send_message(row[0], text)
|
|
except:
|
|
print('вероятно бота нет в чате')
|
|
await bot.send_message(message.from_user.id, 'Сообщение успешно отправлено во все чаты')
|
|
except:
|
|
session.rollback()
|
|
print('eror sendall')
|
|
finally: session.close_all()
|
|
|
|
|
|
def register_handlers_sendalarm(dp: Dispatcher):
|
|
dp.register_message_handler(sendalarm) |