Fixed underscore issue in msg body

pull/78/head
fabston 2021-08-13 14:58:40 +02:00
rodzic 6f0df8aaf1
commit 2dbbcfd98c
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 83970F302C5860B2
1 zmienionych plików z 9 dodań i 12 usunięć

Wyświetl plik

@ -17,22 +17,19 @@ import config
def send_alert(data): def send_alert(data):
msg = data["msg"].encode("latin-1", "backslashreplace").decode("unicode_escape")
if config.send_telegram_alerts: if config.send_telegram_alerts:
tg_bot = Bot(token=config.tg_token) tg_bot = Bot(token=config.tg_token)
try: try:
tg_bot.sendMessage( tg_bot.sendMessage(
data["telegram"], data["telegram"],
data["msg"] msg,
.encode("latin-1", "backslashreplace")
.decode("unicode_escape"),
parse_mode="MARKDOWN", parse_mode="MARKDOWN",
) )
except KeyError: except KeyError:
tg_bot.sendMessage( tg_bot.sendMessage(
config.channel, config.channel,
data["msg"] msg,
.encode("latin-1", "backslashreplace")
.decode("unicode_escape"),
parse_mode="MARKDOWN", parse_mode="MARKDOWN",
) )
except Exception as e: except Exception as e:
@ -43,14 +40,14 @@ def send_alert(data):
webhook = DiscordWebhook( webhook = DiscordWebhook(
url="https://discord.com/api/webhooks/" + data["discord"] url="https://discord.com/api/webhooks/" + data["discord"]
) )
embed = DiscordEmbed(title=data["msg"]) embed = DiscordEmbed(title=msg)
webhook.add_embed(embed) webhook.add_embed(embed)
webhook.execute() webhook.execute()
except KeyError: except KeyError:
webhook = DiscordWebhook( webhook = DiscordWebhook(
url="https://discord.com/api/webhooks/" + config.discord_webhook url="https://discord.com/api/webhooks/" + config.discord_webhook
) )
embed = DiscordEmbed(title=data["msg"]) embed = DiscordEmbed(title=msg)
webhook.add_embed(embed) webhook.add_embed(embed)
webhook.execute() webhook.execute()
except Exception as e: except Exception as e:
@ -59,12 +56,12 @@ def send_alert(data):
if config.send_slack_alerts: if config.send_slack_alerts:
try: try:
slack = Slack(url="https://hooks.slack.com/services/" + data["slack"]) slack = Slack(url="https://hooks.slack.com/services/" + data["slack"])
slack.post(text=data["msg"]) slack.post(text=msg)
except KeyError: except KeyError:
slack = Slack( slack = Slack(
url="https://hooks.slack.com/services/" + config.slack_webhook url="https://hooks.slack.com/services/" + config.slack_webhook
) )
slack.post(text=data["msg"]) slack.post(text=msg)
except Exception as e: except Exception as e:
print("[X] Slack Error:\n>", e) print("[X] Slack Error:\n>", e)
@ -74,7 +71,7 @@ def send_alert(data):
tw_api = tweepy.API(tw_auth) tw_api = tweepy.API(tw_auth)
try: try:
tw_api.update_status( tw_api.update_status(
status=data["msg"].replace("*", "").replace("_", "").replace("`", "") status=msg.replace("*", "").replace("_", "").replace("`", "")
) )
except Exception as e: except Exception as e:
print("[X] Twitter Error:\n>", e) print("[X] Twitter Error:\n>", e)
@ -82,7 +79,7 @@ def send_alert(data):
if config.send_email_alerts: if config.send_email_alerts:
try: try:
email_msg = MIMEText( email_msg = MIMEText(
data["msg"].replace("*", "").replace("_", "").replace("`", "") msg.replace("*", "").replace("_", "").replace("`", "")
) )
email_msg["Subject"] = config.email_subject email_msg["Subject"] = config.email_subject
email_msg["From"] = config.email_sender email_msg["From"] = config.email_sender