Skip to content

Commit

Permalink
Start setting up exercise log command for sets
Browse files Browse the repository at this point in the history
  • Loading branch information
arnavb committed Jun 1, 2024
1 parent 37e2504 commit 35fbb59
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ open System
open JimBroBot.DomainTypes
open JimBroBot.UserCommands

let commands = [ "add", (addExerciseBuilder, addExerciseResponder) ]
let commands =
[ "add", (addExerciseBuilder, addExerciseResponder)
"log", (logExerciseBuilder, logExerciseResponder) ]

let loadBotConfig () =
DotEnv.Load(DotEnvOptions(probeForEnv = true, ignoreExceptions = false))
Expand Down
87 changes: 86 additions & 1 deletion UserCommands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,91 @@ let logExerciseBuilder name =
.AddOption(
(new SlashCommandOptionBuilder())
.WithName("set")
.WithDescription("Log a set (reps + weight)")
.WithDescription("Log a set")
.WithType(ApplicationCommandOptionType.SubCommand)
.AddOption(
"name",
ApplicationCommandOptionType.String,
"Name of exercise",
isRequired = true,
choices = Array.empty
)
.AddOption(
"count",
ApplicationCommandOptionType.Integer,
"Number of sets",
isRequired = true,
minValue = 0,
maxValue = 5,
choices = Array.empty
)
.AddOption(
"reps",
ApplicationCommandOptionType.Integer,
"Number of reps for each set",
minValue = 0.0,
isRequired = true,
choices = Array.empty
)
.AddOption(
"weight",
ApplicationCommandOptionType.Number,
"Weight for each rep",
isRequired = true,
minValue = 0.0,
choices = Array.empty
)
.AddOption(
"warmup",
ApplicationCommandOptionType.Boolean,
"Whether this is a warmup set or not",
isRequired = false,
choices = Array.empty
)
)

let logSetHelper (command: SocketSlashCommand) (options: obj list) =
let (name, count, reps, weight, warmup) =
match options with
| rawName :: rawCount :: rawReps :: rawWeight :: rawWarmup :: _ ->
let name = rawName :?> string
let count = rawCount :?> int64
let reps = rawReps :?> int64
let weight = rawWeight :?> double
let warmup = rawWarmup :?> bool

name, count, reps, weight, warmup
| rawName :: rawCount :: rawReps :: rawWeight :: _ ->
let name = rawName :?> string
let count = rawCount :?> int64
let reps = rawReps :?> int64
let weight = rawWeight :?> double

name, count, reps, weight, false
| _ -> failwith "Missing parameter (should be impossible)"

task {
do! command.RespondAsync $"Logging {count} set(s) of {name} with {reps} reps of {weight} lbs each ({warmup})"
}

let logSpeedHelper (command: SocketSlashCommand) options = task { return () }

let logTimeHelper (command: SocketSlashCommand) options = task { return () }

let logExerciseResponder (command: SocketSlashCommand) =
let user = command.User

let allOptions = command.Data.Options |> List.ofSeq

let logExerciseType = allOptions |> List.head |> _.Name |> stringToExerciseType

let parameters =
allOptions |> List.head |> _.Options |> List.ofSeq |> List.map _.Value

let helper =
match logExerciseType with
| SetBased -> logSetHelper
| SpeedBased -> logSpeedHelper
| TimeBased -> logTimeHelper

task { do! helper command parameters }

0 comments on commit 35fbb59

Please sign in to comment.