2024-03-05 14:46:43 +03:00
|
|
|
|
import json
|
|
|
|
|
|
2024-03-05 15:31:21 +03:00
|
|
|
|
import loguru
|
2024-02-15 10:56:32 +03:00
|
|
|
|
import requests
|
|
|
|
|
from loguru import logger
|
|
|
|
|
from storage import Storage
|
|
|
|
|
|
|
|
|
|
s = Storage()
|
|
|
|
|
|
|
|
|
|
_TOKEN = '6767909836:AAFpsqtWeBNIBgSSi2_19rltEHOF0mrvTg0'
|
|
|
|
|
_URL = 'https://api.telegram.org/bot'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _log(message):
|
|
|
|
|
if message.record.get('level').name == "ERROR":
|
|
|
|
|
icon = "❌ "
|
|
|
|
|
elif message.record.get('level').name == "SUCCESS":
|
|
|
|
|
icon = "✅ "
|
|
|
|
|
else:
|
|
|
|
|
icon = "ℹ️ "
|
|
|
|
|
for chat_id in s.get_users():
|
|
|
|
|
r = requests.post("{0}{1}/sendMessage".format(_URL, _TOKEN), {
|
|
|
|
|
"chat_id": int(chat_id),
|
|
|
|
|
"disable_notification": True,
|
2024-03-05 14:46:43 +03:00
|
|
|
|
"text": icon + message,
|
2024-03-05 15:31:21 +03:00
|
|
|
|
# "reply_markup": json.dumps({"keyboard": [[{"text": "Остановить Бот"}]]})
|
2024-02-15 10:56:32 +03:00
|
|
|
|
})
|
2024-03-05 14:46:43 +03:00
|
|
|
|
if r.status_code != 200:
|
|
|
|
|
print(r.json())
|
2024-02-15 10:56:32 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _filter_info_only(record):
|
|
|
|
|
return record.get('level').name == "INFO" or record.get('level').name == "SUCCESS"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger.add(_log, format="{message}", filter=_filter_info_only)
|
|
|
|
|
logger.add(_log, format=" {message}", filter=lambda record: record.get('level').name == "ERROR")
|