-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscord.py
51 lines (42 loc) · 1.72 KB
/
discord.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
import urllib3
import json
from settings import CONFIG
class Payload:
def __init__(self, username, event):
self.username = username
self.embeds = []
self.event = event
self.data = {}
if event.is_handled():
self.embeds.append(make_embed(event.title(), event.url(), event.description(), CONFIG["colorNotification"],
event.change_details(), event.image_url()))
self.content = make_content(event.title(), event.url(), event.description(), event.change_details())
else:
warning = f"Warning: `{event.event_name}` webhook event is not handled in Jira-to-Discord AWS Lambda"
self.embeds.append(make_embed(warning, '', '', CONFIG["colorWarning"], "Auto-generated by AWS lambda function", None))
self.content = make_content(warning, '', '', "Auto-generated by AWS lambda function")
self.__set_data()
def __set_data(self):
self.data = {'username': self.username}
if CONFIG["useEmbed"]:
self.data['embeds'] = self.embeds
if CONFIG["useContent"]:
self.data['content'] = self.content
def make_embed(title, url, description, color, footer_text, image_url):
return {
"title": title,
"url": url,
"description": description,
"color": color,
"image": {
"url": image_url
},
"footer": {
"text": footer_text
}
}
def make_content(title, url, description, footer_text):
content = f"**[{title}]({url})**\n"
if description is not None: content += f"> {description}\n"
content += footer_text
return content