forked from Pavel_Durov/python_bot
fix
This commit is contained in:
parent
9b64b498ec
commit
751bda0681
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,4 +2,3 @@ __pycache__
|
||||
testDB.py
|
||||
TIME.py
|
||||
.vscode
|
||||
tupica/
|
15
bot.py
15
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())
|
||||
|
||||
|
||||
|
||||
|
28
handlers/sendalarm.py
Normal file
28
handlers/sendalarm.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user