Skip to content

Commit

Permalink
add discord message queue
Browse files Browse the repository at this point in the history
  • Loading branch information
Masterain98 committed Nov 10, 2023
1 parent e96b1c2 commit 8cc2d93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)}

Expand Down
21 changes: 21 additions & 0 deletions private_endpoints.py
Original file line number Diff line number Diff line change
@@ -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 = ""
Expand All @@ -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 ""

0 comments on commit 8cc2d93

Please sign in to comment.