diff --git a/main.py b/main.py index 44f708c..436994e 100644 --- a/main.py +++ b/main.py @@ -3,7 +3,7 @@ from push import push_handler from release import release_handler from issue_comment import comment_handler -from private_endpoints import private_send_issue_comment +from private_endpoints import private_send_issue_comment, add_discord_message, get_discord_message import uvicorn app = FastAPI(docs_url=None, redoc_url=None) @@ -45,6 +45,10 @@ async def private_send(request: Request): if hook_type == "send_issue_comment": result = await private_send_issue_comment(request_payload["data"]) + elif hook_type == "add_discord_message": + result = await add_discord_message(request_payload["data"]) + elif hook_type == "get_discord_message": + result = await get_discord_message() return {"message": str(result)} diff --git a/private_endpoints.py b/private_endpoints.py index 5cf1d7e..7f0351c 100644 --- a/private_endpoints.py +++ b/private_endpoints.py @@ -1,5 +1,7 @@ from operater import make_issue_comment +discord_message_queue = [] + async def private_send_issue_comment(payload_data: dict) -> str: return_result = "" @@ -10,3 +12,22 @@ async def private_send_issue_comment(payload_data: dict) -> str: comment_body = payload_data["comment"] return_result += make_issue_comment(repo_name, issue_number, comment_body) return return_result + + +async def add_discord_message(payload_data: dict) -> str: + global discord_message_queue + new_queue = discord_message_queue.copy() + if len(new_queue) > 5: + return "queue full" + message = payload_data["message"] + new_queue.append(message) + discord_message_queue = list(tuple(new_queue)) + return "ok" + + +async def get_discord_message() -> str: + global discord_message_queue + if len(discord_message_queue) > 0: + return discord_message_queue.pop(0) + else: + return ""