- Fixed underscore issue
- Fixed Timestamp issue
pull/78/head
vzns 2021-02-02 10:43:10 +01:00
rodzic 9b93667a52
commit 025dbcc58d
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7DF2CD11394B933C
2 zmienionych plików z 9 dodań i 6 usunięć

Wyświetl plik

@ -15,9 +15,9 @@ def send_alert(data):
if config.send_telegram_alerts:
tg_bot = Bot(token=config.tg_token)
try:
tg_bot.sendMessage(data['telegram'], data['msg'], parse_mode='MARKDOWN')
tg_bot.sendMessage(data['telegram'], data['msg'].replace('_', '\_'), parse_mode='MARKDOWN')
except KeyError:
tg_bot.sendMessage(config.channel, data['msg'], parse_mode='MARKDOWN')
tg_bot.sendMessage(config.channel, data['msg'].replace('_', '\_'), parse_mode='MARKDOWN')
except Exception as e:
print('[X] Telegram Error:\n>', e)

11
main.py
Wyświetl plik

@ -10,9 +10,12 @@ from flask import Flask, request
import json
from handler import *
timestamp = time.strftime("%Y-%m-%d %X")
app = Flask(__name__)
def get_timestamp():
timestamp = time.strftime("%Y-%m-%d %X")
return timestamp
@app.route('/webhook', methods=['POST'])
def webhook():
try:
@ -20,16 +23,16 @@ def webhook():
data = request.get_json()
key = data['key']
if key == config.sec_key:
print(timestamp, 'Alert Received & Sent!')
print(get_timestamp(), 'Alert Received & Sent!')
send_alert(data)
return 'Sent alert', 200
else:
print('[X]', timestamp, 'Alert Received & Refused! (Wrong Key)')
print('[X]', get_timestamp(), 'Alert Received & Refused! (Wrong Key)')
return 'Refused alert', 400
except Exception as e:
print('[X]', timestamp, 'Error:\n>', e)
print('[X]', get_timestamp(), 'Error:\n>', e)
return 'Error', 400
if __name__ == '__main__':