добавил новую функию рассылки для админа/изменил регистрацию хендлеров

This commit is contained in:
Pavel_Duron 2022-12-13 17:51:47 +10:00
parent 41c4b7c1c4
commit 1b868e430b
6 changed files with 19 additions and 51 deletions

19
bot.py
View File

@ -4,12 +4,12 @@ import graypy
from aiogram import executor
from create_bot import dp
from handlers import pipisa, time_new_year, start_help
from othersq import sendnot
from handlers import pipisa, time_new_year, sendalarm, start_help
import handlers
# logging.basicConfig(level=logging.DEBUG)
logging.basicConfig(
@ -17,15 +17,10 @@ logging.basicConfig(
handlers = [ graypy.GELFUDPHandler('localhost', 12201) ]
)
pipisa.register_handlers_pipisa(dp)
time_new_year.register_handlers_time(dp)
start_help.register_handlers_StartHelp(dp)
sendnot.register_handlers_sendnotal(dp)
# pipisa.register_handlers_pipisa(dp)
# time_new_year.register_handlers_time(dp)
# sendalarm.register_handlers_test(dp)
# start_help.register_handlers_StartHelp(dp)
if __name__ == '__main__':

View File

@ -1,3 +1,4 @@
from handlers import pipisa
from handlers import time_new_year
from handlers import sendalarm
from handlers import start_help

View File

@ -166,8 +166,8 @@ async def send_global_top(message: types.Message):
session.close_all()
def register_handlers_pipisa(dp: Dispatcher):
dp.register_message_handler(up_dick)
dp.register_message_handler(send_topchat)
dp.register_message_handler(send_global_top)
# def register_handlers_pipisa(dp: Dispatcher):
# dp.register_message_handler(up_dick)
# dp.register_message_handler(send_topchat)
# dp.register_message_handler(send_global_top)

View File

@ -1,12 +1,13 @@
from create_bot import dp, bot
from aiogram import types, Dispatcher
from sqdb import user, session
from sqdb import session, user
from create_bot import bot, dp
@dp.message_handler(commands=['sendall'])
async def sendalarm(message: types.Message):
print('начал работать')
async def sendall(message: types.Message):
print('команда прошла')
if message.chat.type == 'private':
if message.from_user.id == 226765676:
text = message.text[9:]
@ -24,5 +25,5 @@ async def sendalarm(message: types.Message):
finally: session.close_all()
def register_handlers_sendalarming(dp: Dispatcher):
dp.register_message_handler(sendalarm)
# def register_handlers_test(dp: Dispatcher):
# dp.register_message_handler(send_welcome)

View File

@ -1 +0,0 @@
from othersq import sendnot

View File

@ -1,28 +0,0 @@
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)