discord-bot-game/Bot/PlayerInteractions.fs

84 lines
3.0 KiB
Forth

module Degenz.PlayerInteractions
open System.Threading.Tasks
open DSharpPlus.Entities
open DSharpPlus
open DSharpPlus.SlashCommands
open Degenz.Store
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
Arsenal = [| hack ; shield |]
Actions = [||]
Bank = 100<GBT> }
let addHackerRole (ctx : InteractionContext) =
async {
let! player = DbService.tryFindPlayer ctx.Member.Id
let! newPlayer =
match player with
| Some _ -> async.Return false
| None ->
async {
do! newPlayer ctx.Member.DisplayName ctx.Member.Id
|> DbService.insertNewPlayer
return true
}
if newPlayer then
do! ctx.CreateResponseAsync("You are now an elite haxxor", true)
|> Async.AwaitTask
else
do! ctx.CreateResponseAsync("Already registered as an elite haxxor", true)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task
[<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.addHackerRole ctx
// [<SlashCommand("leaderboard", "View the current list of players ranked by highest earnings")>]
// member this.Leaderboard (ctx : InteractionContext) = Commands.leaderboard ctx