fix
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pavel_Duron 2022-12-11 20:48:14 +10:00
parent 9b64b498ec
commit 751bda0681
3 changed files with 28 additions and 16 deletions

1
.gitignore vendored
View File

@ -2,4 +2,3 @@ __pycache__
testDB.py testDB.py
TIME.py TIME.py
.vscode .vscode
tupica/

15
bot.py
View File

@ -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( logging.basicConfig(
level = logging.DEBUG, level = logging.DEBUG,
handlers = [ graypy.GELFUDPHandler('localhost', 12201) ] 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())

28
handlers/sendalarm.py Normal file
View File

@ -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)