Skip to content

Commit

Permalink
✨ embed, button 비활성화 여부 칼럼 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
junah201 committed Jun 6, 2024
1 parent 54fb46e commit 898fd50
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 92 deletions.
2 changes: 2 additions & 0 deletions lambdas/event_handler/events/add_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def handler(event, context):
'guild_id': {'S': channel_data.get('guild_id', '')},
"custom_message": {'S': ""},
"type": {"S": "NOTI"},
"disable_embed": {'BOOL': False},
"disable_button": {'BOOL': False},
"index": {"N": "-1"}
}
)
Expand Down
9 changes: 2 additions & 7 deletions lambdas/get_notification_by_guild_id/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,9 @@ def middleware(event, context):

result = [
{
"PK": item.get('PK', {}).get('S'),
"SK": item.get('SK', {}).get('S'),
"guild_id": item.get('guild_id', {}).get('S'),
"channel_id": item.get('channel_id', {}).get('S'),
"channel_name": item.get('channel_name', {}).get('S'),
"custom_message": item.get('custom_message', {}).get('S'),
key: list(value.values())[0]
for key, value in item.items()
}

for item in res.get('Items')
]

Expand Down
86 changes: 45 additions & 41 deletions lambdas/live_check/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,50 +88,54 @@ def middleware(event, context):
for noti in res["Items"]:
discord_channel_id = noti["channel_id"]["S"]

res = send_message(
channel_id=discord_channel_id,
data={
"content": noti.get("custom_message", {}).get("S", ""),
"embeds": [
{
"title": f"{chzzk['liveTitle']}",
"description": f"{chzzk['channel']['channelName']} 님이 방송을 시작했습니다.",
"color": 0x02E895,
"fields": [
{
"name": '카테고리',
"value": chzzk['liveCategoryValue']
}
],
"image": {
"url": (chzzk['liveImageUrl'] or chzzk['channel']['channelImageUrl'] or "").replace("_{type}", "_1080"),
},
"author": {
"name": f"{chzzk['channel']['channelName']}",
"url": f"https://chzzk.naver.com/live/{channel_id}",
"icon_url": chzzk['channel']['channelImageUrl'] or "https://ssl.pstatic.net/cmstatic/nng/img/img_anonymous_square_gray_opacity2x.png?type=f120_120_na"
},
"footer": {
"text": "치직"
},
data = {
"content": noti.get("custom_message", {}).get("S", ""),
}
if noti.get("disable_embed", {"BOOL": False})["BOOL"]:
data["embeds"] = [
{
"title": f"{chzzk['liveTitle']}",
"description": f"{chzzk['channel']['channelName']} 님이 방송을 시작했습니다.",
"color": 0x02E895,
"fields": [
{
"name": '카테고리',
"value": chzzk['liveCategoryValue']
}
],
"image": {
"url": (chzzk['liveImageUrl'] or chzzk['channel']['channelImageUrl'] or "").replace("_{type}", "_1080"),
},
"author": {
"name": f"{chzzk['channel']['channelName']}",
"url": f"https://chzzk.naver.com/live/{channel_id}",
"timestamp": datetime.now().isoformat()
"icon_url": chzzk['channel']['channelImageUrl'] or "https://ssl.pstatic.net/cmstatic/nng/img/img_anonymous_square_gray_opacity2x.png?type=f120_120_na"
},
],
"components": [
{
"type": COMPONENT_TYPE.ACTION_ROW,
"components": [
{
"type": COMPONENT_TYPE.BUTTON,
"label": "바로가기",
"style": BUTTON_STYLE.LINK,
"url": f"https://chzzk.naver.com/live/{channel_id}"
}
]
"footer": {
"text": "치직"
},
],
}
"url": f"https://chzzk.naver.com/live/{channel_id}",
"timestamp": datetime.now().isoformat()
},
]
if noti.get("disable_button", {"BOOL": False})["BOOL"]:
data["components"] = [
{
"type": COMPONENT_TYPE.ACTION_ROW,
"components": [
{
"type": COMPONENT_TYPE.BUTTON,
"label": "바로가기",
"style": BUTTON_STYLE.LINK,
"url": f"https://chzzk.naver.com/live/{channel_id}"
}
]
},
]

res = send_message(
channel_id=discord_channel_id,
data=data
)

# 채널이 존재하지 않는 경우
Expand Down
5 changes: 5 additions & 0 deletions lambdas/post_notification/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def middleware(event, context):
chzzk_id = body.get("chzzk_id", None)
channel_id = body.get("channel_id", None)
custom_message = body.get("custom_message", None)
disable_embed = body.get("disable_embed", False)
disable_button = body.get("disable_button", False)

for i in [token, chzzk_id, channel_id, custom_message]:
if i is None:
Expand Down Expand Up @@ -133,6 +135,9 @@ def middleware(event, context):
'channel_name': {'S': channel_data.get('name', '')},
'guild_id': {'S': channel_data.get('guild_id', '')},
"custom_message": {'S': custom_message},
"type": {"S": "NOTI"},
"disable_embed": {'BOOL': disable_embed},
"disable_button": {'BOOL': disable_button},
"index": {"N": "-1"}
}
)
Expand Down
86 changes: 45 additions & 41 deletions lambdas/send_test_notification/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,50 +66,54 @@ def middleware(event, context):

item = res["Items"][0]

res = send_message(
channel_id=discord_channel_id,
data={
"content": f"관리자의 요청에 따라 전송된 테스트 알림입니다." + "\n\n" + item.get("custom_message", {}).get("S", ""),
"embeds": [
{
"title": f"{chzzk['liveTitle']}",
"description": f"{chzzk['channel']['channelName']} 님이 방송을 시작했습니다.",
"color": 0x02E895,
"fields": [
{
"name": '카테고리',
"value": chzzk['liveCategoryValue']
}
],
"image": {
"url": (chzzk['liveImageUrl'] or chzzk['channel']['channelImageUrl'] or "").replace("_{type}", "_1080"),
},
"author": {
"name": f"{chzzk['channel']['channelName']}",
"url": f"https://chzzk.naver.com/live/{chzzk_id}",
"icon_url": chzzk['channel']['channelImageUrl'] or "https://ssl.pstatic.net/cmstatic/nng/img/img_anonymous_square_gray_opacity2x.png?type=f120_120_na"
},
"footer": {
"text": "치직"
},
data = {
"content": f"관리자의 요청에 따라 전송된 테스트 알림입니다." + "\n\n" + item.get("custom_message", {}).get("S", "")
}
if item.get("disable_embed", {"BOOL": False})["BOOL"]:
data["embeds"] = [
{
"title": f"{chzzk['liveTitle']}",
"description": f"{chzzk['channel']['channelName']} 님이 방송을 시작했습니다.",
"color": 0x02E895,
"fields": [
{
"name": '카테고리',
"value": chzzk['liveCategoryValue']
}
],
"image": {
"url": (chzzk['liveImageUrl'] or chzzk['channel']['channelImageUrl'] or "").replace("_{type}", "_1080"),
},
"author": {
"name": f"{chzzk['channel']['channelName']}",
"url": f"https://chzzk.naver.com/live/{chzzk_id}",
"timestamp": datetime.now().isoformat()
"icon_url": chzzk['channel']['channelImageUrl'] or "https://ssl.pstatic.net/cmstatic/nng/img/img_anonymous_square_gray_opacity2x.png?type=f120_120_na"
},
],
"components": [
{
"type": COMPONENT_TYPE.ACTION_ROW,
"components": [
{
"type": COMPONENT_TYPE.BUTTON,
"label": "바로가기",
"style": BUTTON_STYLE.LINK,
"url": f"https://chzzk.naver.com/live/{chzzk_id}"
}
]
"footer": {
"text": "치직"
},
],
}
"url": f"https://chzzk.naver.com/live/{chzzk_id}",
"timestamp": datetime.now().isoformat()
},
]
if item.get("disable_button", {"BOOL": False})["BOOL"]:
data["components"] = [
{
"type": COMPONENT_TYPE.ACTION_ROW,
"components": [
{
"type": COMPONENT_TYPE.BUTTON,
"label": "바로가기",
"style": BUTTON_STYLE.LINK,
"url": f"https://chzzk.naver.com/live/{chzzk_id}"
}
]
},
]

res = send_message(
channel_id=discord_channel_id,
data=data
)

# 채널이 존재하지 않는 경우
Expand Down
8 changes: 5 additions & 3 deletions lambdas/update_notification/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def middleware(event, context):
chzzk_id = body.get("chzzk_id", None)
channel_id = body.get("channel_id", None)
custom_message = body.get("custom_message", None)
disable_embed = body.get("disable_embed", False)
disable_button = body.get("disable_button", False)

for i in [token, chzzk_id, channel_id, custom_message]:
if i is None:
Expand Down Expand Up @@ -55,9 +57,9 @@ def middleware(event, context):
}

item = res["Items"][0]
item["custom_message"] = {
"S": custom_message
}
item["custom_message"] = {"S": custom_message}
item["disable_embed"] = {"BOOL": disable_embed}
item["disable_button"] = {"BOOL": disable_button}

res = dynamodb.put_item(
TableName='chzzk-bot-db',
Expand Down

0 comments on commit 898fd50

Please sign in to comment.