discord-bot-game/Bot/PlayerInteractions.fs

76 lines
2.7 KiB
Forth

module Degenz.PlayerInteractions
open System.Threading.Tasks
open DSharpPlus.SlashCommands
open Degenz.Types
module Commands =
let newPlayer nickname (membr : uint64) =
let rand = System.Random(System.Guid.NewGuid().GetHashCode())
let randHack = rand.Next(0, 3)
let randShield = rand.Next(6, 9)
let hack = Armory.battleItems |> Array.find (fun i -> i.Id = randHack)
let shield = Armory.battleItems |> Array.find (fun i -> i.Id = randShield)
{ DiscordId = membr
Name = nickname
Inventory = [| hack ; shield |]
Events = [||]
// XP = 0
// Achievements = [||]
Traits = PlayerTraits.empty
Bank = 100<GBT> }
let upsertPlayer discordId =
async {
let! player = DbService.tryFindPlayer GuildEnvironment.pgDb discordId
let! newPlayer =
match player with
| Some _ -> async.Return false
| None ->
async {
do! newPlayer "" discordId |> DbService.insertNewPlayer
return true
}
return newPlayer
}
[<CLIMutable>]
type LeaderboardEntry = {
Position : string
Amount : string
Name : string
}
// let leaderboard (ctx : InteractionContext) =
// async {
// do! ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource) |> Async.AwaitTask
//
// let builder = DiscordFollowupMessageBuilder()
// builder.IsEphemeral <- true
//
// let! leaders = DbService.getTopPlayers 10
// let content =
// leaders
// |> Seq.toArray
// |> Array.sortByDescending (fun p -> p.Bank)
// |> Array.mapi (fun i p -> { Position = string (i + 1) ; Amount = string p.Bank ; Name = p.Name })
// |> Formatter.Format
// builder.Content <- if not <| String.IsNullOrEmpty content then $"```{content}```" else "There are no active hackers"
// do! ctx.Interaction.CreateFollowupMessageAsync(builder)
// |> Async.AwaitTask
// |> Async.Ignore
// } |> Async.StartAsTask
// :> Task
type PlayerInteractions() =
inherit ApplicationCommandModule ()
[<SlashCommand("redpill", "Take the redpill and become a hacker")>]
member _.AddHackerRole (ctx : InteractionContext) = Commands.upsertPlayer ctx.Member.Id
// [<SlashCommand("leaderboard", "View the current list of players ranked by highest earnings")>]
// member this.Leaderboard (ctx : InteractionContext) = Commands.leaderboard ctx