Skip to content

Commit

Permalink
Go back to using the Discord API correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
raykrueger committed Oct 7, 2024
1 parent 6640228 commit b730a9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
17 changes: 5 additions & 12 deletions resources/functions/discord/discord.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import boto3
import os
import json
import hashlib
from nacl.signing import VerifyKey
from nacl.exceptions import BadSignatureError

cluster = os.environ.get("CLUSTER_ARN")
service = os.environ.get("SERVICE_ARN")
stateMachineArn = os.environ.get("STATE_MACHINE")
secrets_manager = boto3.client("secretsmanager")
ecs = boto3.client("ecs")
sfn = boto3.client("stepfunctions")
Expand Down Expand Up @@ -65,13 +65,11 @@ def post(event):
elif rtype == 2:
sub_command = request["data"]["options"][0]["name"]

h = hashlib.sha256()
h.update(bytes(interaction_token, "utf-8"))
execution_name = h.hexdigest()
execution_name = f"{interaction_id}"

print("Starting State Machine")
sfn.start_execution(
stateMachineArn=os.environ.get("STATE_MACHINE"),
stateMachineArn=stateMachineArn,
name=execution_name,
input=json.dumps(
{
Expand All @@ -82,14 +80,9 @@ def post(event):
),
)
return {
"statusCode": 202,
"statusCode": 200,
"headers": {"Content-Type": "application/json"},
#
#"body": json.dumps(
# {
# "type": 5,
# }
#),
"body": json.dumps( { "type": 5, })
}
else:
return go_away()
Expand Down
13 changes: 7 additions & 6 deletions resources/functions/discord/discord_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@ def handle(event, context):
interaction_id = event["InteractionId"]
interaction_token = event["InteractionToken"]
message = event["Discord"]["Message"]
url = f"https://discord.com/api/v10/interactions/{interaction_id}/{interaction_token}/callback"
headers = {"Authorization": f"Bot {bot_token}"}
url = f"https://discord.com/api/v10/webhooks/{app_id}/{interaction_token}"

headers = {
"Authorization": f"Bot {bot_token}",
}

body = {
"type": 4,
"data": {
"content": message
}
"content": message
}

res = requests.post(url, json=body, headers=headers)

if not res.ok:
print(f"ERROR: {res.text}")

Expand Down

0 comments on commit b730a9e

Please sign in to comment.