From 751bda06819d0fd99e7ab9baf8f0f62079cff7e9 Mon Sep 17 00:00:00 2001 From: Pavel_Duron Date: Sun, 11 Dec 2022 20:48:14 +1000 Subject: [PATCH] fix --- .gitignore | 1 - bot.py | 15 --------------- handlers/sendalarm.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 handlers/sendalarm.py diff --git a/.gitignore b/.gitignore index c127e7e..ac9720e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ __pycache__ testDB.py TIME.py .vscode -tupica/ \ No newline at end of file diff --git a/bot.py b/bot.py index 0d2fb06..1d6f09d 100644 --- a/bot.py +++ b/bot.py @@ -9,26 +9,11 @@ from othersq import sendnot -class TagFilter(logging.Filter): - def __init__(self): - self.tag = 'jack_bot' - - def filter(self, record): - record.tag = self.tag - return True - logging.basicConfig( level = logging.DEBUG, handlers = [ graypy.GELFUDPHandler('localhost', 12201) ] ) -( logging.getLogger( ) ).addFilter(TagFilter()) -#logging.LoggerAdapter(logging.getLogger( ), {'tag': 'jack_bot'}) -#root_logger = logging.getLogger( ) - -#handler = graypy.GELFUDPHandler('localhost', 12201) -#root_logger.addHandler(handler) -#root_logger.addFilter(TagFilter()) diff --git a/handlers/sendalarm.py b/handlers/sendalarm.py new file mode 100644 index 0000000..1132a50 --- /dev/null +++ b/handlers/sendalarm.py @@ -0,0 +1,28 @@ + +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_sendalarming(dp: Dispatcher): + dp.register_message_handler(sendalarm) \ No newline at end of file