From 6515b6b1d6d690f40a7b32e541ae27ef5f0fff3d Mon Sep 17 00:00:00 2001 From: Sean Krueger Date: Sun, 4 Jun 2023 15:11:30 -0500 Subject: [PATCH] Add Discord command to stop server --- resources/discord-bot-asl.json | 24 +++++++++++++++++-- .../discord_provider/discord_provider.py | 5 ++++ src/discord-state-machine.ts | 9 ++++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/resources/discord-bot-asl.json b/resources/discord-bot-asl.json index 984a595..89333bd 100644 --- a/resources/discord-bot-asl.json +++ b/resources/discord-bot-asl.json @@ -13,7 +13,12 @@ { "Variable": "$.SubCommand", "StringEquals": "start", - "Next": "UpdateService" + "Next": "StartService" + }, + { + "Variable": "$.SubCommand", + "StringEquals": "stop", + "Next": "StopService" } ], "Default": "WutMessage" @@ -26,7 +31,7 @@ }, "ResultPath": "$.Discord" }, - "UpdateService": { + "StartService": { "Type": "Task", "Next": "RunningCheck", "Parameters": { @@ -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": { diff --git a/resources/functions/discord_provider/discord_provider.py b/resources/functions/discord_provider/discord_provider.py index 5efcd40..05af30b 100644 --- a/resources/functions/discord_provider/discord_provider.py +++ b/resources/functions/discord_provider/discord_provider.py @@ -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, + }, ], } diff --git a/src/discord-state-machine.ts b/src/discord-state-machine.ts index 5ed1d0c..99a4c60 100644 --- a/src/discord-state-machine.ts +++ b/src/discord-state-machine.ts @@ -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,