diff --git a/JimBroBot/Data.fs b/JimBroBot/Data.fs index 309cf6c..b391cc7 100644 --- a/JimBroBot/Data.fs +++ b/JimBroBot/Data.fs @@ -38,16 +38,20 @@ let readExerciseLogEntriesForBotUser (connectionString: string) (botUserId: int) LogDate = read.dateOnly "log_date" }) -let loadDataForUser (connectionString: string, discordId: string) = +let loadDataForUser (connectionString: string) (discordId: string) = task { - let! botUser = readBotUser connectionString discordId - let! botUserExercises = readExercisesForBotUser connectionString botUser.Id - - let exerciseInfos = botUserExercises |> Seq.map databaseExerciseToDomainExerciseInfo - - // TODO: Figure out way to load and combine exercise log - return - { Id = discordId - Exercises = exerciseInfos - ExerciseLog = Seq.empty } + try + let! botUser = readBotUser connectionString discordId + let! botUserExercises = readExercisesForBotUser connectionString botUser.Id + + let exerciseInfos = botUserExercises |> Seq.map databaseExerciseToDomainExerciseInfo + + // TODO: Figure out way to load and combine exercise log + return + Ok + { Id = discordId + Exercises = exerciseInfos + ExerciseLog = Seq.empty } + with NoResultsException(_) -> + return Error NoUserFound } diff --git a/JimBroBot/DomainTypes.fs b/JimBroBot/DomainTypes.fs index f97e56d..2f8f758 100644 --- a/JimBroBot/DomainTypes.fs +++ b/JimBroBot/DomainTypes.fs @@ -8,6 +8,7 @@ type BotError = | NoEnvBotToken | BotStartError of string | MissingCommandHandler + | NoUserFound type ExerciseType = | SetBased diff --git a/JimBroBot/UserCommands.fs b/JimBroBot/UserCommands.fs index 59c731a..0d0893e 100644 --- a/JimBroBot/UserCommands.fs +++ b/JimBroBot/UserCommands.fs @@ -6,6 +6,7 @@ open TimeSpanParserUtil open JimBroBot.DomainTypes open JimBroBot.Converters +open JimBroBot.Data let addExerciseBuilder name = (new SlashCommandBuilder()) @@ -250,14 +251,32 @@ let profileResponder (command: SocketSlashCommand) connectionString = task { do! command.DeferAsync() - let user = command.User + let botUserId = command.User.Id |> string - let profileEmbed = - (EmbedBuilder()) - .WithTitle($"{user.Mention}'s Profile") - .WithDescription("A summary of various stats") + let! user = loadDataForUser connectionString botUserId - let! _ = command.FollowupAsync(embed = profileEmbed.Build()) + match user with + | Ok user -> + let profileEmbed = + (EmbedBuilder()) + .WithTitle($"{command.User.GlobalName}'s Profile") + .WithDescription("A summary of various stats") + .AddField( + (EmbedFieldBuilder()) + .WithIsInline(true) + .WithName("Exercises") + .WithValue(user.Exercises |> Seq.length) + ) - return () + let! _ = command.FollowupAsync(embed = profileEmbed.Build()) + + return () + | Error(NoUserFound) -> + let! _ = command.FollowupAsync "User has no bot account!" + + return () + | Error(_) -> + let! _ = command.FollowupAsync "Unexpected error; try again later." + + return () }