Skip to content

Commit

Permalink
Merge pull request raykrueger#8 from skrueger-ftc/stop-command
Browse files Browse the repository at this point in the history
feat: Add Discord command to manually stop Game Server
  • Loading branch information
raykrueger authored Jun 12, 2023
2 parents 217927f + 6515b6b commit d79b53c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
24 changes: 22 additions & 2 deletions resources/discord-bot-asl.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
{
"Variable": "$.SubCommand",
"StringEquals": "start",
"Next": "UpdateService"
"Next": "StartService"
},
{
"Variable": "$.SubCommand",
"StringEquals": "stop",
"Next": "StopService"
}
],
"Default": "WutMessage"
Expand All @@ -26,7 +31,7 @@
},
"ResultPath": "$.Discord"
},
"UpdateService": {
"StartService": {
"Type": "Task",
"Next": "RunningCheck",
"Parameters": {
Expand Down Expand Up @@ -68,6 +73,21 @@
},
"ResultPath": "$.Discord"
},
"StopService": {
"Type": "Task",
"Next": "DescribeServices",
"Parameters": {
"Cluster": "",
"Service": "",
"DesiredCount": 0
},
"Resource": "arn:aws:states:::aws-sdk:ecs:updateService",
"ResultSelector": {
"DesiredCount.$": "$.Service.DesiredCount",
"RunningCount.$": "$.Service.RunningCount"
},
"ResultPath": "$.Service"
},
"DescribeServices": {
"Type": "Task",
"Parameters": {
Expand Down
5 changes: 5 additions & 0 deletions resources/functions/discord_provider/discord_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def on_create(event):
"description": "Start the server, if it isn't running",
"type": 1,
},
{
"name": "stop",
"description": "Stop the server, if it is running",
"type": 1,
},
],
}

Expand Down
9 changes: 8 additions & 1 deletion src/discord-state-machine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,20 @@ export class DiscordStateMachine extends Construct {
],
},
},
UpdateService: {
StartService: {
Parameters: {
Cluster: props.service.cluster.clusterArn,
Service: props.service.serviceArn,
DesiredCount: 1,
},
},
StopService: {
Parameters: {
Cluster: props.service.cluster.clusterArn,
Service: props.service.serviceArn,
DesiredCount: 0,
},
},
SendDiscordResponse: {
Parameters: {
FunctionName: f.functionArn,
Expand Down

0 comments on commit d79b53c

Please sign in to comment.