-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebhook_generator.py
65 lines (46 loc) · 2.35 KB
/
webhook_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from distutils.command.config import config
import eas_codes_converter
import json
from discord_webhook import DiscordWebhook, DiscordEmbed
with open("settings.json", "r") as configfile:
configdata = json.load(configfile)
WH_URL=configdata['webhook']['url']
# Load this in from settings.json
EMBED_ENABLE = configdata['webhook']['zczc_str_enable']
FILTER_ENABLE = configdata['webhook']['filter_display_enable']
MON_NUM_ENABLE = configdata['webhook']['mon_num_enable']
def generateRXAlertEmbed(input_data):
EVENT = eas_codes_converter.SAME2txt(input_data[4][2])
webhook = DiscordWebhook(url=WH_URL)
embed = DiscordEmbed(title=f'{"".join(EVENT[0])}', description=f'{"".join(input_data[3])}', color=f'{"".join(EVENT[1])}')
embed.add_embed_field(name='Timestamp: ', value=f'{"".join(input_data[0])}')
if MON_NUM_ENABLE:
embed.add_embed_field(name='Monitor Channel: ', value=f'{"".join(input_data[2])}')
if FILTER_ENABLE:
embed.add_embed_field(name='Filter Match: ', value=f'{"".join(input_data[1])}')
if EMBED_ENABLE:
embed.add_embed_field(name='Raw: ', value=f'{"-".join(input_data[4])}')
webhook.add_embed(embed)
response = webhook.execute()
def generateLocalAlertEmbed(input_data):
EVENT = eas_codes_converter.SAME2txt(input_data[2][2])
webhook = DiscordWebhook(url=WH_URL)
# you can set the color as a decimal (color=242424) or hex (color='03b2f8') number
embed = DiscordEmbed(title=f'{"".join(EVENT[0])}', description=f'{"".join(input_data[1])}', color=f'{"".join(EVENT[1])}')
embed.set_footer(text='DigiDEC v0.1 by trevor229')
# Embed field names must have text in them :sadge:
embed.add_embed_field(name='Timestamp: ', value=f'{"".join(input_data[0])}')
if EMBED_ENABLE:
embed.add_embed_field(name='Raw: ', value=f'{"-".join(input_data[2])}')
# add embed object to webhook
webhook.add_embed(embed)
response = webhook.execute()
# Response code from Discord API
#print(response)
def determineType(alert_data, alert_type):
if alert_type == 1:
print("webhook_generator: Local alert/alert relay detected...executing local alert webhook...")
generateLocalAlertEmbed(alert_data)
elif alert_type == 2:
print("webhook_generator: Remote alert detected...executing remote alert webhook...")
generateRXAlertEmbed(alert_data)