From aefe9f6a092d59ee945d95b3d777021d87d24176 Mon Sep 17 00:00:00 2001 From: Pavel_Duron Date: Fri, 9 Dec 2022 19:20:50 +1000 Subject: [PATCH] add testfucn --- bot.py | 5 ++++- othersq/__init__.py | 1 + othersq/sendnot.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 othersq/__init__.py create mode 100644 othersq/sendnot.py diff --git a/bot.py b/bot.py index 98d9210..a5d650b 100644 --- a/bot.py +++ b/bot.py @@ -1,17 +1,20 @@ from create_bot import dp import logging from aiogram import executor + from handlers import pipisa, time_new_year, start_help +from othersq import sendnot logging.basicConfig(level=logging.DEBUG) + pipisa.register_handlers_pipisa(dp) time_new_year.register_handlers_time(dp) start_help.register_handlers_StartHelp(dp) - +sendnot.register_handlers_sendnotal(dp) diff --git a/othersq/__init__.py b/othersq/__init__.py new file mode 100644 index 0000000..bf46e75 --- /dev/null +++ b/othersq/__init__.py @@ -0,0 +1 @@ +from othersq import sendnot \ No newline at end of file diff --git a/othersq/sendnot.py b/othersq/sendnot.py new file mode 100644 index 0000000..26d5a44 --- /dev/null +++ b/othersq/sendnot.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 sendall(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_sendnotal(dp: Dispatcher): + dp.register_message_handler(sendall) \ No newline at end of file