Assign Trainee role and alert player if they're in the wrong channel

This commit is contained in:
Joseph Ferano 2022-02-03 18:02:26 +07:00
parent 7ebba3f61a
commit 3b5852bcfb
4 changed files with 41 additions and 13 deletions

View File

@ -51,7 +51,8 @@ let pickDefense actionId player =
let pickHack actionId attacker defender = let pickHack actionId attacker defender =
let buttons = 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<DiscordComponent> |> Seq.cast<DiscordComponent>
let embed = let embed =

View File

@ -17,6 +17,7 @@ let tokenStore = getVar "TOKEN_STORE"
let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE" let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE"
let channelTraining = getId "CHANNEL_TRAINING" let channelTraining = getId "CHANNEL_TRAINING"
let channelArmory = getId "CHANNEL_ARMORY" let channelArmory = getId "CHANNEL_ARMORY"
let channelBattle = getId "CHANNEL_BATTLE"
let botHackerBattle = getId "BOT_HACKER_BATTLE" let botHackerBattle = getId "BOT_HACKER_BATTLE"
let botArmory = getId "BOT_ARMORY" let botArmory = getId "BOT_ARMORY"
let roleTrainee = getId "ROLE_TRAINEE" let roleTrainee = getId "ROLE_TRAINEE"

View File

@ -109,7 +109,7 @@ let failedHack (event : ComponentInteractionCreateEventArgs) attacker defender h
|> Async.Ignore |> Async.Ignore
} }
let attack (ctx : InteractionContext) (target : DiscordUser) = let attack (target : DiscordUser) (ctx : InteractionContext) =
Game.executePlayerInteraction ctx (fun attacker -> async { Game.executePlayerInteraction ctx (fun attacker -> async {
let! defender = DbService.tryFindPlayer target.Id let! defender = DbService.tryFindPlayer target.Id
match defender with match defender with
@ -232,19 +232,33 @@ let handleButtonEvent (_ : DiscordClient) (event : ComponentInteractionCreateEve
type HackerGame() = type HackerGame() =
inherit ApplicationCommandModule () 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
}
[<SlashCommand("hack", "Send a hack attack to another player")>] [<SlashCommand("hack", "Send a hack attack to another player")>]
member this.AttackCommand (ctx : InteractionContext, [<Option("target", "The player you want to hack")>] target : DiscordUser) = member this.AttackCommand (ctx : InteractionContext, [<Option("target", "The player you want to hack")>] target : DiscordUser) =
if ctx.Channel.Id = GuildEnvironment.channelTraining then enforceChannels ctx (Trainer.attack target) (attack target)
Trainer.attack ctx target
else
attack ctx target
[<SlashCommand("shield", "Create a passive shield that will protect you for a certain time")>] [<SlashCommand("shield", "Create a passive shield that will protect you for a certain time")>]
member this.ShieldCommand (ctx : InteractionContext) = member this.ShieldCommand (ctx : InteractionContext) =
if ctx.Channel.Id = GuildEnvironment.channelTraining then enforceChannels ctx Trainer.defend defend
Trainer.defend ctx
else
defend ctx
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>] // [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
member this.TestAutoComplete (ctx : InteractionContext) = member this.TestAutoComplete (ctx : InteractionContext) =

View File

@ -37,6 +37,11 @@ let handleTrainerStep1 (event : ComponentInteractionCreateEventArgs) =
let name = Player.shields player |> Array.tryHead |> Option.defaultValue defaultShield |> fun w -> w.Name 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 $"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 do! sendFollowUpMessage event
("Beautopia© is a dangerous place...\n" ("Beautopia© is a dangerous place...\n"
+ "Quick, put up a SHIELD 🛡 before another Degen hacks you, and steals your 💰$GBT.\n\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}`") + $"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 { Game.executePlayerInteraction ctx (fun player -> async {
let isRightTarget = target.Id = GuildEnvironment.botHackerBattle let isRightTarget = target.Id = GuildEnvironment.botHackerBattle
match isRightTarget with match isRightTarget with
| true -> | true ->
let playerWithAttacks = let playerWithAttacks =
match player.Arsenal with match Player.hacks player with
| [||] -> { player with Arsenal = [| defaultHack |] } | [||] -> { player with Arsenal = [| defaultHack |] }
| _ -> player | _ -> player
let embed = Embeds.pickHack "Trainer-4" playerWithAttacks 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" + "You successfully **HACKED** me, and are now an **Elite Haxor!**\n\n"
+ "When you **HACK** other Degenz, you **STEAL** their 💰$GBT.\n" + "When you **HACK** other Degenz, you **STEAL** their 💰$GBT.\n"
+ "But remember, hacks take time to recover, so use them wisely.") + "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 do! sendFollowUpMessage event
("Your training is **complete!**\n\n" ("Your training is **complete!**\n\n"
+ "But, youre going to need more **HACKS & SHIELDS** 🛡 to survive in **Beautopia©...**\n" + "But, youre going to need more **HACKS & SHIELDS** 🛡 to survive in **Beautopia©...**\n"