| 17 | |
| 18 | |
| 19 | def send_alert(data): |
| 20 | msg = data["msg"].encode("latin-1", "backslashreplace").decode("unicode_escape") |
| 21 | if config.send_telegram_alerts: |
| 22 | tg_bot = Bot(token=config.tg_token) |
| 23 | try: |
| 24 | tg_bot.sendMessage( |
| 25 | data["telegram"], |
| 26 | msg, |
| 27 | parse_mode="MARKDOWN", |
| 28 | ) |
| 29 | except KeyError: |
| 30 | tg_bot.sendMessage( |
| 31 | config.channel, |
| 32 | msg, |
| 33 | parse_mode="MARKDOWN", |
| 34 | ) |
| 35 | except Exception as e: |
| 36 | print("[X] Telegram Error:\n>", e) |
| 37 | |
| 38 | if config.send_discord_alerts: |
| 39 | try: |
| 40 | webhook = DiscordWebhook( |
| 41 | url="https://discord.com/api/webhooks/" + data["discord"] |
| 42 | ) |
| 43 | embed = DiscordEmbed(title=msg) |
| 44 | webhook.add_embed(embed) |
| 45 | webhook.execute() |
| 46 | except KeyError: |
| 47 | webhook = DiscordWebhook( |
| 48 | url="https://discord.com/api/webhooks/" + config.discord_webhook |
| 49 | ) |
| 50 | embed = DiscordEmbed(title=msg) |
| 51 | webhook.add_embed(embed) |
| 52 | webhook.execute() |
| 53 | except Exception as e: |
| 54 | print("[X] Discord Error:\n>", e) |
| 55 | |
| 56 | if config.send_slack_alerts: |
| 57 | try: |
| 58 | slack = Slack(url="https://hooks.slack.com/services/" + data["slack"]) |
| 59 | slack.post(text=msg) |
| 60 | except KeyError: |
| 61 | slack = Slack( |
| 62 | url="https://hooks.slack.com/services/" + config.slack_webhook |
| 63 | ) |
| 64 | slack.post(text=msg) |
| 65 | except Exception as e: |
| 66 | print("[X] Slack Error:\n>", e) |
| 67 | |
| 68 | if config.send_twitter_alerts: |
| 69 | tw_auth = tweepy.OAuthHandler(config.tw_ckey, config.tw_csecret) |
| 70 | tw_auth.set_access_token(config.tw_atoken, config.tw_asecret) |
| 71 | tw_api = tweepy.API(tw_auth) |
| 72 | try: |
| 73 | tw_api.update_status( |
| 74 | status=msg.replace("*", "").replace("_", "").replace("`", "") |
| 75 | ) |
| 76 | except Exception as e: |