From 5f4bb7124554b3987e4e56e6f11705e1dbfb1b5f Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Sat, 29 Jan 2022 16:12:56 +0700 Subject: [PATCH] Check if player has inventory before starting. Testing autocomplete --- Bot/Bot.fs | 20 ++++++++++++++++++-- Bot/Embeds.fs | 6 ++---- Bot/HackerBattle.fs | 13 ++++++++++++- Bot/Trainer.fs | 34 +++++++++++++++++++++++----------- DbService/DbService.fs | 4 +--- paket.dependencies | 6 +++--- paket.lock | 10 +++++----- 7 files changed, 64 insertions(+), 29 deletions(-) diff --git a/Bot/Bot.fs b/Bot/Bot.fs index 2c8c7b3..98ac128 100644 --- a/Bot/Bot.fs +++ b/Bot/Bot.fs @@ -40,7 +40,7 @@ let storeBot = new DiscordClient(storeConfig) //let slotMachineBot = new DiscordClient(slotMachineConfig) //let clients = [| storeBot ; trainerBot ; hackerBattleBot ; playerInteractionsBot ; slotMachineBot |] -let clients = [| storeBot ; hackerBattleBot ; playerInteractionsBot |] +let clients = [| hackerBattleBot ; storeBot ; playerInteractionsBot |] let sc1 = playerInteractionsBot.UseSlashCommands() let sc3 = hackerBattleBot.UseSlashCommands() @@ -55,12 +55,28 @@ sc4.RegisterCommands(guild); hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent)) storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleSellButtonEvents)) +let asdf (_ : DiscordClient) (event : DSharpPlus.EventArgs.InteractionCreateEventArgs) = + async { + printfn "%A" event.Interaction.Type + match event.Interaction.Type with + | InteractionType.AutoComplete -> + printfn "%A" event.Interaction.Data.Options + let builder = DSharpPlus.Entities.DiscordInteractionResponseBuilder() + builder.AddAutoCompleteChoice(DSharpPlus.Entities.DiscordAutoCompleteChoice("Choice 1", "What does this represent?")) + |> ignore + do! event.Interaction.CreateResponseAsync(InteractionResponseType.AutoCompleteResult, builder) + |> Async.AwaitTask + | _ -> return () + } |> Async.StartAsTask + :> Task +//hackerBattleBot.add_InteractionCreated(AsyncEventHandler(asdf)) + let run (client : DiscordClient) = async { do! client.ConnectAsync () |> Async.AwaitTask } -Trainer.sendInitialEmbed hackerBattleBot +//Trainer.sendInitialEmbed hackerBattleBot clients |> Array.map run diff --git a/Bot/Embeds.fs b/Bot/Embeds.fs index 03c08b9..cda11e4 100644 --- a/Bot/Embeds.fs +++ b/Bot/Embeds.fs @@ -5,8 +5,7 @@ open Degenz.Shared open DSharpPlus.Entities open AsciiTableFormatter -let getHackGif = - function +let getHackGif = function | Hack.Virus -> "https://s10.gifyu.com/images/Attack-DegenZ.gif" | Hack.Ransom -> "https://s10.gifyu.com/images/Mind-Control-Degenz-V2.gif" | Hack.Worm -> "https://s10.gifyu.com/images/WormBugAttack_Degenz.gif" @@ -15,8 +14,7 @@ let getHackGif = | Hack.Injection -> "https://s10.gifyu.com/images/Attack-DegenZ.gif" | _ -> "https://s10.gifyu.com/images/Hacker-Degenz-V2.gif" -let getShieldGif = - function +let getShieldGif = function | Shield.Firewall -> "https://s10.gifyu.com/images/Defense-GIF-1-Degenz.gif" | Shield.PortScan -> "https://s10.gifyu.com/images/PortScanDefense_Degenz.gif" | Shield.Encryption -> "https://s10.gifyu.com/images/Anonymous-Degenz-V2.gif" diff --git a/Bot/HackerBattle.fs b/Bot/HackerBattle.fs index aaf6a1c..42b0817 100644 --- a/Bot/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -202,7 +202,6 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) = let! playerResult = DbService.tryFindPlayer event.User.Id match playerResult , shieldResult with | Some player , true -> - // TODO: All of this is wrong let updatedDefenses = removeExpiredActions (TimeSpan.FromHours(6)) (fun (pro : Defense) -> pro.Timestamp) player.Defenses let alreadyUsedShield = updatedDefenses |> Array.exists (fun d -> d.DefenseType = shield) @@ -289,4 +288,16 @@ type HackerGame() = else defend ctx +// [] + member this.TestAutoComplete (ctx : InteractionContext) = + async { + let builder = DiscordInteractionResponseBuilder() +// builder.WithContent("Not working") + builder.IsEphemeral <- true + do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder) + |> Async.AwaitTask + } |> Async.StartAsTask + :> Task + + diff --git a/Bot/Trainer.fs b/Bot/Trainer.fs index 413be3c..ea611dc 100644 --- a/Bot/Trainer.fs +++ b/Bot/Trainer.fs @@ -24,15 +24,22 @@ let sendInitialEmbed (client : DiscordClient) = let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) = async { - let! membr = event.Guild.GetMemberAsync(event.User.Id) |> Async.AwaitTask - let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) - do! membr.GrantRoleAsync(role) |> Async.AwaitTask + let! maybePlayer = DbService.tryFindPlayer event.User.Id do! event.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate) |> Async.AwaitTask - let msg = "First time, eh? Beautopia is a dangerous place. I'm going to teach you how to protect yourself from other degenerates. " - + "And in the process, I'll also show you how to hack some sheeple, so you can earn some cash." - do! Message.sendFollowUpMessageWithButton event "Trainer-2" msg + match maybePlayer with + | Some player when not <| Array.isEmpty player.Weapons && not <| Array.isEmpty player.Shields -> + let msg = "First time, eh? Beautopia is a dangerous place. I'm going to teach you how to protect yourself from other degenerates. " + + "And in the process, I'll also show you how to hack some sheeple, so you can earn some cash." + do! Message.sendFollowUpMessageWithButton event "Trainer-2" msg + | Some player -> + let missingItem = match player.Weapons with [||] -> "Hacks" | _ -> "Shields" + let msg = $"Looks like you don't own any {missingItem}. Go to the store and purchase some before proceeding." + do! Message.sendFollowUpMessage event msg + | None -> + let msg = "An error occurred, please contact a moderator" + do! Message.sendFollowUpMessage event msg } let handleTrainerStep2 (event : ComponentInteractionCreateEventArgs) = @@ -54,9 +61,13 @@ let defend (ctx : InteractionContext) = let! playerResult = DbService.tryFindPlayer ctx.Member.Id match playerResult with | Some player -> - let embed = Embeds.pickDefense "Trainer-3" player + let playerWithShields = + match player.Shields with + | [||] -> { player with Shields = [| Shield.Firewall |] } + | _ -> player + let embed = Embeds.pickDefense "Trainer-3" playerWithShields - do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, embed) + do! ctx.Interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, embed) |> Async.AwaitTask | None -> let builder = DiscordInteractionResponseBuilder() @@ -144,6 +155,7 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = match result with | Some player -> let prize = 2 + do! Async.Sleep 1000 do! sendMessage' $"{player.Name} successfully hacked Degenz-Trainer for a total of {prize} GoodBoyTokenz" do! Async.Sleep 3000 do! sendMessage' ("Look at that, you are now officially an elite haxor! By successfully hacking other people you can earn GoodBoyTokenz. " @@ -159,9 +171,9 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = let handleTrainerStep6 (event : ComponentInteractionCreateEventArgs) = async { - let! membr = event.Guild.GetMemberAsync(event.User.Id) |> Async.AwaitTask - let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) - do! membr.RevokeRoleAsync(role) |> Async.AwaitTask +// let! membr = event.Guild.GetMemberAsync(event.User.Id) |> Async.AwaitTask +// let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) +// do! membr.RevokeRoleAsync(role) |> Async.AwaitTask let builder = DiscordInteractionResponseBuilder() builder.Content <- "Get out of here!" diff --git a/DbService/DbService.fs b/DbService/DbService.fs index a96cfec..c8809cf 100644 --- a/DbService/DbService.fs +++ b/DbService/DbService.fs @@ -11,15 +11,13 @@ let mongo = MongoClient(Environment.GetEnvironmentVariable("CONN_STRING")) let db = mongo.GetDatabase("degenz") let players = db.GetCollection("players") - let tryFindPlayer (id : uint64) = async { let filter = Builders.Filter.Eq("Player.DiscordId", id) let! player = players.FindAsync(filter) |> Async.AwaitTask match player.FirstOrDefault() with | null -> return None - | p -> - return p + | p -> return p .GetValue("Player") .ToBsonDocument() |> BsonSerializer.Deserialize diff --git a/paket.dependencies b/paket.dependencies index c40baa2..697dabe 100644 --- a/paket.dependencies +++ b/paket.dependencies @@ -7,9 +7,9 @@ nuget FSharp.Core >= 6.0.0 source https://nuget.emzi0767.com/api/v3/index.json -nuget DSharpPlus >= 4.2.0-nightly-01061 -nuget DSharpPlus.Interactivity >= 4.2.0-nightly-01061 -nuget DSharpPlus.SlashCommands >= 4.2.0-nightly-01061 +nuget DSharpPlus >= 4.2.0-nightly-01063 +nuget DSharpPlus.Interactivity >= 4.2.0-nightly-01063 +nuget DSharpPlus.SlashCommands >= 4.2.0-nightly-01063 nuget MongoDB.Driver diff --git a/paket.lock b/paket.lock index 5311124..cc7c51e 100644 --- a/paket.lock +++ b/paket.lock @@ -472,7 +472,7 @@ NUGET System.Runtime (>= 4.3) System.ValueTuple (4.5) remote: https://nuget.emzi0767.com/api/v3/index.json - DSharpPlus (4.2.0-nightly-01061) + DSharpPlus (4.2.0-nightly-01063) Emzi0767.Common (>= 2.6.2) Microsoft.Extensions.Logging.Abstractions (>= 5.0) Newtonsoft.Json (>= 13.0.1) @@ -482,9 +482,9 @@ NUGET System.Net.WebSockets.Client (>= 4.3.2) System.Runtime.InteropServices.RuntimeInformation (>= 4.3) System.Threading.Channels (>= 5.0) - DSharpPlus.Interactivity (4.2.0-nightly-01061) + DSharpPlus.Interactivity (4.2.0-nightly-01063) ConcurrentHashSet (>= 1.1) - DSharpPlus (>= 4.2.0-nightly-01061) - DSharpPlus.SlashCommands (4.2.0-nightly-01061) - DSharpPlus (>= 4.2.0-nightly-01061) + DSharpPlus (>= 4.2.0-nightly-01063) + DSharpPlus.SlashCommands (4.2.0-nightly-01063) + DSharpPlus (>= 4.2.0-nightly-01063) Microsoft.Extensions.DependencyInjection (>= 5.0.1)