Adding leaderboard command. Switching to degenz server

This commit is contained in:
Joseph Ferano 2022-01-11 14:38:42 +07:00
parent 86354e2efe
commit 0343203a4e
4 changed files with 60 additions and 24 deletions

View File

@ -11,6 +11,8 @@ open Joebot.Functions
let mutable players : Player list = []
let battleChannel = 930363007781978142uL
let addHackerRole (ctx : InteractionContext) =
async {
for role in ctx.Guild.Roles do
@ -22,7 +24,7 @@ let addHackerRole (ctx : InteractionContext) =
players <-
match player with
| Some _ -> players
| None -> (newPlayer ctx.Member.Id)::players
| None -> (newPlayer ctx.Member.Username ctx.Member.Id)::players
if Option.isSome player then
do! ctx.CreateResponseAsync("Already registered as an elite haxxor", true)
@ -34,7 +36,6 @@ let addHackerRole (ctx : InteractionContext) =
} |> Async.StartAsTask
:> Task
let removeHackerRole (ctx : InteractionContext) =
async {
for role in ctx.Member.Roles do
@ -53,7 +54,7 @@ let attack (ctx : InteractionContext) (target : DiscordUser) =
let defender = players |> List.tryFind (fun p -> p.DiscordId = target.Id)
match attacker , defender with
| Some attacker , Some defender ->
let updatedAttacks = removeExpiredActions (TimeSpan.FromMinutes(15)) (fun (atk : Attack) -> atk.Timestamp) attacker.Attacks
let updatedAttacks = removeExpiredActions (TimeSpan.FromMinutes(5)) (fun (atk : Attack) -> atk.Timestamp) attacker.Attacks
players <-
players
|> List.map (fun p -> if p.DiscordId = attacker.DiscordId then { p with Attacks = updatedAttacks } else p)
@ -78,8 +79,9 @@ let attack (ctx : InteractionContext) (target : DiscordUser) =
else
async {
let builder = DiscordInteractionResponseBuilder()
let timeRemaining = TimeSpan.FromMinutes(15) - (DateTime.UtcNow - updatedAttacks.Head.Timestamp)
builder.Content <- $"You already hacked, please wait {timeRemaining.Minutes} minutes and {timeRemaining.Seconds} seconds to attempt another hack"
let timestamp = updatedAttacks |> List.rev |> List.head |> fun a -> a.Timestamp // This should be the next expiring timestamp
let timeRemaining = TimeSpan.FromMinutes(15) - (DateTime.UtcNow - timestamp)
builder.Content <- $"No more hacks available, please wait {timeRemaining.Minutes} minutes and {timeRemaining.Seconds} seconds to attempt another hack"
builder.AsEphemeral true |> ignore
@ -101,6 +103,7 @@ let defend (ctx : InteractionContext) =
players <-
players
|> List.map (fun p -> if p.DiscordId = player.DiscordId then { p with Defenses = updatedDefenses } else p)
if updatedDefenses.Length < 2 then
let builder = DiscordInteractionResponseBuilder()
builder.AddEmbed (constructEmbed "Pick a defense to mount for a duration of time") |> ignore
@ -111,6 +114,16 @@ let defend (ctx : InteractionContext) =
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
else
let builder = DiscordInteractionResponseBuilder()
let timestamp = updatedDefenses |> List.rev |> List.head |> fun a -> a.Timestamp // This should be the next expiring timestamp
let timeRemaining = TimeSpan.FromMinutes(15) - (DateTime.UtcNow - timestamp)
builder.Content <- $"Cannot add new defense, please wait {timeRemaining.Minutes} minutes and {timeRemaining.Seconds} seconds to add another defense"
builder.AsEphemeral true |> ignore
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
@ -126,7 +139,7 @@ let status (ctx : InteractionContext) =
async {
let builder = DiscordInteractionResponseBuilder()
builder.IsEphemeral <- true
builder.Content <- $"%A{player}"
builder.Content <- Functions.statusFormat player
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
}
@ -134,6 +147,20 @@ let status (ctx : InteractionContext) =
} |> Async.StartAsTask
:> Task
let leaderboard (ctx : InteractionContext) =
async {
let builder = DiscordInteractionResponseBuilder()
builder.IsEphemeral <- true
builder.Content <-
players
|> List.sortByDescending (fun p -> p.Bank)
|> List.mapi (fun i p -> $"{i + 1}. {p.Bank} {p.Name}")
|> String.concat "\n"
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|> Async.AwaitTask
} |> Async.StartAsTask
:> Task
let handleAttack (event : ComponentInteractionCreateEventArgs) =
let updatePlayer amount attack p = {
p with Attacks = attack::p.Attacks

View File

@ -9,7 +9,15 @@ open Joebot.Types
let hackDescription = ""
let newPlayer (membr : uint64) =
let statusFormat player =
$"Hack Inventory: {player.Weapons}
Shield Inventory: {player.Shields}
Active Hacks: {player.Attacks}
Active Defenses: {player.Defenses}
Bank: {player.Bank}"
let newPlayer nickname (membr : uint64) =
let h1 = [| Virus ; Ransom |]
let h2 = [| DDos ; Worm |]
let h3 = [| Crack ; Injection |]
@ -24,6 +32,7 @@ let newPlayer (membr : uint64) =
let shields = [ getRandom d1 ; getRandom d2 ; getRandom d3 ]
{ DiscordId = membr
Name = nickname
Weapons = weapons
Shields = shields
Attacks = []

View File

@ -31,6 +31,8 @@ type JoeBot() =
[<SlashCommand("status", "Get your current status like bank account, and active hacks and defenses")>]
member this.Status (ctx : InteractionContext) = Commands.status ctx
[<SlashCommand("leaderboard", "View the current list of players ranked by highest earnings")>]
member this.Leaderboard (ctx : InteractionContext) = Commands.leaderboard ctx
let config = DiscordConfiguration()
config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk"
@ -44,7 +46,7 @@ client.add_ComponentInteractionCreated(AsyncEventHandler(handleButtonEvent))
let slash = client.UseSlashCommands()
slash.RegisterCommands<JoeBot>(922419263275425832uL);
slash.RegisterCommands<JoeBot>(922414052708327494uL);
client.ConnectAsync ()
|> Async.AwaitTask

View File

@ -32,8 +32,6 @@ type Weapon =
| "Injection" -> Some Injection
| _ -> None
type Shield =
| Firewall
| PortScan
@ -61,7 +59,6 @@ type HackResult =
| Strong
| Weak
type DiscordPlayer = {
Id : uint64
Name : string
@ -80,6 +77,7 @@ type Defense = {
type Player = {
DiscordId : uint64
Name : string
Weapons : Weapon list
Shields : Shield list
Attacks : Attack list