Check if player has inventory before starting. Testing autocomplete

This commit is contained in:
Joseph Ferano 2022-01-29 16:12:56 +07:00
parent 9924460001
commit 5f4bb71245
7 changed files with 64 additions and 29 deletions

View File

@ -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<Store>(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

View File

@ -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"

View File

@ -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
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
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

View File

@ -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!"

View File

@ -11,15 +11,13 @@ let mongo = MongoClient(Environment.GetEnvironmentVariable("CONN_STRING"))
let db = mongo.GetDatabase("degenz")
let players = db.GetCollection<BsonDocument>("players")
let tryFindPlayer (id : uint64) =
async {
let filter = Builders<BsonDocument>.Filter.Eq("Player.DiscordId", id)
let! player = players.FindAsync<BsonDocument>(filter) |> Async.AwaitTask
match player.FirstOrDefault() with
| null -> return None
| p ->
return p
| p -> return p
.GetValue("Player")
.ToBsonDocument()
|> BsonSerializer.Deserialize<Player>

View File

@ -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

View File

@ -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)