diff --git a/Bot/Embeds.fs b/Bot/Embeds.fs index 87be0bd..7bd827b 100644 --- a/Bot/Embeds.fs +++ b/Bot/Embeds.fs @@ -51,7 +51,8 @@ let pickDefense actionId player = let pickHack actionId attacker defender = let buttons = - Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}" (Player.hacks attacker) + let hacks = Player.hacks attacker + Messaging.constructButtons actionId $"{defender.DiscordId}-{defender.Name}" hacks |> Seq.cast let embed = diff --git a/Bot/GuildEnvironment.fs b/Bot/GuildEnvironment.fs index 94c7091..dde7a9e 100644 --- a/Bot/GuildEnvironment.fs +++ b/Bot/GuildEnvironment.fs @@ -17,6 +17,7 @@ let tokenStore = getVar "TOKEN_STORE" let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE" let channelTraining = getId "CHANNEL_TRAINING" let channelArmory = getId "CHANNEL_ARMORY" +let channelBattle = getId "CHANNEL_BATTLE" let botHackerBattle = getId "BOT_HACKER_BATTLE" let botArmory = getId "BOT_ARMORY" let roleTrainee = getId "ROLE_TRAINEE" diff --git a/Bot/HackerBattle.fs b/Bot/HackerBattle.fs index 5c906ce..0d30728 100644 --- a/Bot/HackerBattle.fs +++ b/Bot/HackerBattle.fs @@ -109,7 +109,7 @@ let failedHack (event : ComponentInteractionCreateEventArgs) attacker defender h |> Async.Ignore } -let attack (ctx : InteractionContext) (target : DiscordUser) = +let attack (target : DiscordUser) (ctx : InteractionContext) = Game.executePlayerInteraction ctx (fun attacker -> async { let! defender = DbService.tryFindPlayer target.Id match defender with @@ -232,19 +232,33 @@ let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEve type HackerGame() = inherit ApplicationCommandModule () + let enforceChannels (ctx : InteractionContext) (trainerFn : InteractionContext -> Task) (battleFn : InteractionContext -> Task) = + match ctx.Channel.Id with + | id when id = GuildEnvironment.channelTraining -> + let hasTraineeRole = Seq.exists (fun (r : DiscordRole) -> r.Id = GuildEnvironment.roleTrainee) ctx.Member.Roles + if hasTraineeRole then + trainerFn ctx + else + task { + let msg = $"You're currently not in training, either go to <#{GuildEnvironment.channelBattle}> to hack for real, " + + "or restart training by clicking on the Pinned embed's button up top." + do! Messaging.sendSimpleResponse ctx msg + } + | id when id = GuildEnvironment.channelBattle -> + battleFn ctx + | _ -> + task { + let msg = $"You must go to <#{GuildEnvironment.channelBattle}> channel to hack or shield up for real" + do! Messaging.sendSimpleResponse ctx msg + } + [] member this.AttackCommand (ctx : InteractionContext, [] target : DiscordUser) = - if ctx.Channel.Id = GuildEnvironment.channelTraining then - Trainer.attack ctx target - else - attack ctx target + enforceChannels ctx (Trainer.attack target) (attack target) [] member this.ShieldCommand (ctx : InteractionContext) = - if ctx.Channel.Id = GuildEnvironment.channelTraining then - Trainer.defend ctx - else - defend ctx + enforceChannels ctx Trainer.defend defend // [] member this.TestAutoComplete (ctx : InteractionContext) = diff --git a/Bot/Trainer.fs b/Bot/Trainer.fs index 2e4ed52..e8de436 100644 --- a/Bot/Trainer.fs +++ b/Bot/Trainer.fs @@ -37,6 +37,11 @@ let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) = let name = Player.shields player |> Array.tryHead |> Option.defaultValue defaultShield |> fun w -> w.Name $"Looks like you have `{name}` in your arsenal… 👀\n\n" , name + let membr = event.User :?> DiscordMember + let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) + do! membr.GrantRoleAsync(role) + |> Async.AwaitTask + do! sendFollowUpMessage event ("Beautopia© is a dangerous place...\n" + "Quick, put up a SHIELD 🛡 before another Degen hacks you, and steals your 💰$GBT.\n\n" @@ -99,13 +104,13 @@ let handleTrainerStep3 (event : ComponentInteractionCreateEventArgs) = + $"Type the `/hack` command now, then choose me - <@{GuildEnvironment.botHackerBattle}> as your target, and select `{weaponName}`") }) -let attack (ctx : InteractionContext) (target : DiscordUser) = +let attack (target : DiscordUser) (ctx : InteractionContext) = Game.executePlayerInteraction ctx (fun player -> async { let isRightTarget = target.Id = GuildEnvironment.botHackerBattle match isRightTarget with | true -> let playerWithAttacks = - match player.Arsenal with + match Player.hacks player with | [||] -> { player with Arsenal = [| defaultHack |] } | _ -> player let embed = Embeds.pickHack "Trainer-4" playerWithAttacks player @@ -137,7 +142,14 @@ let handleAttack (event : ComponentInteractionCreateEventArgs) = + "You successfully **HACKED** me, and are now an **Elite Haxor!**\n\n" + "When you **HACK** other Degenz, you **STEAL** their 💰$GBT.\n" + "But remember, hacks take time to recover, so use them wisely.") - do! Async.Sleep 7000 + + do! Async.Sleep 5000 + + let membr = event.User :?> DiscordMember + let role = event.Guild.GetRole(GuildEnvironment.roleTrainee) + do! membr.RevokeRoleAsync(role) + |> Async.AwaitTask + do! sendFollowUpMessage event ("Your training is **complete!**\n\n" + "But, you’re going to need more **HACKS & SHIELDS** 🛡 to survive in **Beautopia©...**\n"