diff --git a/PlayerInteractions/Bot.fs b/Bot/Bot.fs similarity index 94% rename from PlayerInteractions/Bot.fs rename to Bot/Bot.fs index d97c97d..fb8c7a1 100644 --- a/PlayerInteractions/Bot.fs +++ b/Bot/Bot.fs @@ -17,7 +17,7 @@ let playerInteractionsConfig = DiscordConfiguration() let hackerBattleConfig = DiscordConfiguration() let storeConfig = DiscordConfiguration() //let slotMachineConfig = DiscordConfiguration() -//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace +//hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace //let configs = [| playerInteractionsConfig ; hackerBattleConfig ; storeConfig ; slotMachineConfig ; |] let configs = [| playerInteractionsConfig ; hackerBattleConfig ; storeConfig |] @@ -39,9 +39,6 @@ let hackerBattleBot = new DiscordClient(hackerBattleConfig) let storeBot = new DiscordClient(storeConfig) //let slotMachineBot = new DiscordClient(slotMachineConfig) -hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent)) -storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleSellButtonEvents)) - //let clients = [| storeBot ; trainerBot ; hackerBattleBot ; playerInteractionsBot ; slotMachineBot |] let clients = [| storeBot ; hackerBattleBot ; playerInteractionsBot |] @@ -55,11 +52,16 @@ sc3.RegisterCommands(guild); sc4.RegisterCommands(guild); //sc5.RegisterCommands(guild); +hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent)) +storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleSellButtonEvents)) + let run (client : DiscordClient) = async { do! client.ConnectAsync () |> Async.AwaitTask } +Trainer.sendInitialEmbed hackerBattleBot + clients |> Array.map run |> Array.toSeq diff --git a/PlayerInteractions/PlayerInteractions.fsproj b/Bot/Bot.fsproj similarity index 100% rename from PlayerInteractions/PlayerInteractions.fsproj rename to Bot/Bot.fsproj diff --git a/PlayerInteractions/GuildEnvironment.fs b/Bot/GuildEnvironment.fs similarity index 90% rename from PlayerInteractions/GuildEnvironment.fs rename to Bot/GuildEnvironment.fs index 1ec5ef5..32b8de1 100644 --- a/PlayerInteractions/GuildEnvironment.fs +++ b/Bot/GuildEnvironment.fs @@ -13,7 +13,7 @@ let guildId = getId "DISCORD_GUILD" let tokenPlayerInteractions = getVar "TOKEN_PLAYER_INTERACTIONS" let tokenHackerBattle = getVar "TOKEN_HACKER_BATTLE" let tokenStore = getVar "TOKEN_STORE" -let eventsChannelHackerBattle = getId "EVENTS_CHANNEL_HACKER_BATTLE" +let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE" let channelTraining = getId "CHANNEL_TRAINING" let botHackerBattle = getId "BOT_HACKER_BATTLE" let roleTrainee = getId "ROLE_TRAINEE" diff --git a/PlayerInteractions/HackerBattle.fs b/Bot/HackerBattle.fs similarity index 97% rename from PlayerInteractions/HackerBattle.fs rename to Bot/HackerBattle.fs index 05eb247..a061759 100644 --- a/PlayerInteractions/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -127,7 +127,7 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = let builder = DiscordMessageBuilder() builder.WithContent($"{event.User.Username} successfully hacked <@{targetId}> for a total of {prize} GoodBoyTokenz") |> ignore - let channel = (event.Guild.GetChannel(GuildEnvironment.eventsChannelHackerBattle)) + let channel = (event.Guild.GetChannel(GuildEnvironment.channelEventsHackerBattle)) do! channel.SendMessageAsync(builder) |> Async.AwaitTask |> Async.Ignore @@ -145,7 +145,7 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = let builder = DiscordMessageBuilder() builder.WithContent($"Hacking attempt failed! <@{targetId}> defended hack from {event.User.Username} and took {prize} from them! ") |> ignore - let channel = (event.Guild.GetChannel(GuildEnvironment.eventsChannelHackerBattle)) + let channel = (event.Guild.GetChannel(GuildEnvironment.channelEventsHackerBattle)) do! channel.SendMessageAsync(builder) |> Async.AwaitTask |> Async.Ignore @@ -211,16 +211,16 @@ type HackerGame() = [] member this.AttackCommand (ctx : InteractionContext, [] target : DiscordUser) = - let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Name = "trainee") ctx.Member.Roles - if ctx.Channel.Name = "training-dojo" && hasTraineeRole then + let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles + if ctx.Channel.Id = GuildEnvironment.channelTraining && hasTraineeRole then Trainer.attack ctx target else attack ctx target [] member this.DefendCommand (ctx : InteractionContext) = - let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Name = "Trainee") ctx.Member.Roles - if ctx.Channel.Name = "training-dojo" && hasTraineeRole then + let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles + if ctx.Channel.Id = GuildEnvironment.channelTraining && hasTraineeRole then Trainer.defend ctx else defend ctx diff --git a/PlayerInteractions/Items.json b/Bot/Items.json similarity index 100% rename from PlayerInteractions/Items.json rename to Bot/Items.json diff --git a/PlayerInteractions/PlayerInteractions.fs b/Bot/PlayerInteractions.fs similarity index 100% rename from PlayerInteractions/PlayerInteractions.fs rename to Bot/PlayerInteractions.fs diff --git a/PlayerInteractions/SlotMachine.fs b/Bot/SlotMachine.fs similarity index 100% rename from PlayerInteractions/SlotMachine.fs rename to Bot/SlotMachine.fs diff --git a/PlayerInteractions/Store.fs b/Bot/Store.fs similarity index 100% rename from PlayerInteractions/Store.fs rename to Bot/Store.fs diff --git a/PlayerInteractions/Trainer.fs b/Bot/Trainer.fs similarity index 88% rename from PlayerInteractions/Trainer.fs rename to Bot/Trainer.fs index 48933a8..ebe23aa 100644 --- a/PlayerInteractions/Trainer.fs +++ b/Bot/Trainer.fs @@ -62,13 +62,15 @@ let sendInitialEmbed (client : DiscordClient) = let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) = async { - 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.sendInteractionEventWithButton event "Trainer-2" msg - let! membr = event.Guild.GetMemberAsync(event.User.Id) |> Async.AwaitTask let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) do! membr.GrantRoleAsync(role) |> Async.AwaitTask + + 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 } let handleTrainerStep2 (event : ComponentInteractionCreateEventArgs) = @@ -77,7 +79,7 @@ let handleTrainerStep2 (event : ComponentInteractionCreateEventArgs) = match result with | Some player -> let weaponName = player.Shields |> Array.tryHead |> Option.defaultValue Shield.Firewall - do! Message.sendFollowUpMessage event + do! Message.sendInteractionEvent event ($"First things first, let's get your system protected. Let's enable a shield to protect you from potential hackers. " + $"You currently have {weaponName} in your arsenal. To enable it and protect your system, you can use the `/defend` slash command to choose a shield." + $"\n\nRun the `/defend` command now and then select '{weaponName}'.") @@ -93,7 +95,7 @@ let defend (ctx : InteractionContext) = let builder = DiscordInteractionResponseBuilder() builder.AddEmbed (constructEmbed "Pick a defense to mount for 8 hours") |> ignore - constructButtons "Defend" (string player.DiscordId) player.Shields + constructButtons "Trainer-3" (string player.DiscordId) player.Shields |> Seq.cast |> builder.AddComponents |> ignore @@ -123,28 +125,31 @@ let handleDefense (event : ComponentInteractionCreateEventArgs) = | Some player -> let prize = 0.223f do! sendMessage' $"{event.User.Username} has protected their system!" + do! Async.Sleep 3000 do! sendMessage' "Ok, good, let me make sure that worked. I'll try to hack you now" + do! Async.Sleep 4000 do! sendMessage' $"Hacking attempt failed! {player.Name} defended hack from Degenz-Trainer and took {prize} from them! " + do! Async.Sleep 3000 let msg = ("I wasn't able to hack you. Great job! Because you had your system protected when I tried to hack you, you took some money from me. " + "Shields only protect you for a certain amount of time, so remember to keep your system protected at all times.") - do! Message.sendFollowUpMessageWithButton event "Trainer-3" msg + do! Message.sendFollowUpMessageWithButton event "Trainer-4" msg | None -> do! sendMessage' $"Something went wrong, please contact a moderator" } -let handleTrainerStep3 (event : ComponentInteractionCreateEventArgs) = +let handleTrainerStep4 (event : ComponentInteractionCreateEventArgs) = async { let! result = DbService.tryFindPlayer event.User.Id match result with | Some player -> // TODO: There's a potential bug here where if the player sold their weapons, they'll get stuck let weaponName = player.Weapons |> Array.tryHead |> Option.defaultValue Hack.Virus - do! Message.sendFollowUpMessage event + do! Message.sendInteractionEvent event ($"Next why don't you try hacking me. You currently have {weaponName} equipped. To hack me and get some money, " + $" you can use the '/hack' slash command and select a user to hack, then choose the hack attack you wish to use." + $"\n\nRun the `/hack` command now and pick me as your target, then click on the '{weaponName}' button.") | None -> - do! Message.sendFollowUpMessage event $"Something went wrong, please contact a moderator" + do! Message.sendInteractionEvent event $"Something went wrong, please contact a moderator" } let attack (ctx : InteractionContext) (target : DiscordUser) = @@ -156,7 +161,7 @@ let attack (ctx : InteractionContext) (target : DiscordUser) = let builder = DiscordInteractionResponseBuilder() builder.AddEmbed (constructEmbed "Pick an attack to use on your target") |> ignore - constructButtons "Attack" (string player.DiscordId) player.Weapons + constructButtons "Trainer-5" (string player.DiscordId) player.Weapons |> Seq.cast |> builder.AddComponents |> ignore @@ -194,33 +199,40 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = | Some player -> let prize = 2 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. " + "Hacks take time to recover so check back in later once you've used all your hacks.") + do! Async.Sleep 6000 let msg = ("I think we're done. You are going to need more hacks and shields if you want to survive in this crazy world. " + "Remember to go check out the store and purchase whatever you need to add to your arsenal." + "\n\nAlright you degenerate, off you go!") - do! Message.sendFollowUpMessageWithButton event "Trainer-4" msg + do! Message.sendFollowUpMessageWithButton event "Trainer-6" msg | None -> do! sendMessage' $"Something went wrong, please contact a moderator" } -let handleTrainerStep4 (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 builder = DiscordInteractionResponseBuilder() + builder.Content <- "Get out of here!" + do! event.Interaction.CreateResponseAsync(InteractionResponseType.UpdateMessage, builder) + |> Async.AwaitTask } let handleButtonEvent (event : ComponentInteractionCreateEventArgs) = async { - match event.Id with - | id when id.StartsWith("Trainer") -> - let split = id.Split("-") - match int split.[1] with - | 1 -> do! handleTrainerStep1 event - | 2 -> do! handleTrainerStep2 event - | 3 -> do! handleTrainerStep3 event - | _ -> do! Message.sendFollowUpMessage event "No action found" + let split = event.Id.Split("-") + match int split.[1] with + | 1 -> do! handleTrainerStep1 event + | 2 -> do! handleTrainerStep2 event + | 3 -> do! handleDefense event + | 4 -> do! handleTrainerStep4 event + | 5 -> do! handleAttack event + | 6 -> do! handleTrainerStep6 event | _ -> do! Message.sendFollowUpMessage event "No action found" } diff --git a/PlayerInteractions/paket.references b/Bot/paket.references similarity index 100% rename from PlayerInteractions/paket.references rename to Bot/paket.references diff --git a/DegenzGame.sln b/DegenzGame.sln index e865622..84b9a1a 100644 --- a/DegenzGame.sln +++ b/DegenzGame.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.30114.105 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "PlayerInteractions", "PlayerInteractions\PlayerInteractions.fsproj", "{FF9E58A6-1A1D-4DEC-B52D-265F215BF315}" +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Bot", "Bot\Bot.fsproj", "{FF9E58A6-1A1D-4DEC-B52D-265F215BF315}" EndProject Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "DbService", "DbService\DbService.fsproj", "{B1D3E1CC-451C-42D4-B054-D64E75E1A3B9}" EndProject