From 0e3909d4f21428a87f860ef089c818c31fc9d888 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 7 Feb 2022 22:14:22 +0700 Subject: [PATCH] Enforce channel --- Bot/Store.fs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Bot/Store.fs b/Bot/Store.fs index 88aae98..6332bde 100644 --- a/Bot/Store.fs +++ b/Bot/Store.fs @@ -59,7 +59,7 @@ let arsenal (ctx : InteractionContext) = do! DbService.updatePlayer updatedPlayer }) -let buy (ctx : InteractionContext) itemType = +let buy itemType (ctx : InteractionContext) = Game.executePlayerInteraction ctx (fun player -> async { let itemStore = Embeds.getBuyItemsEmbed itemType Armory.battleItems do! ctx.Interaction.CreateFollowupMessageAsync(itemStore) @@ -68,7 +68,7 @@ let buy (ctx : InteractionContext) itemType = }) // TODO: Remove active shield when selling -let sell (ctx : InteractionContext) itemType = +let sell itemType (ctx : InteractionContext) = Game.executePlayerInteraction ctx (fun player -> async { match checkHasItemsInArsenal itemType player with | Ok _ -> @@ -124,18 +124,28 @@ let handleStoreEvents (_ : DiscordClient) (event : ComponentInteractionCreateEve type Store() = inherit ApplicationCommandModule () + let enforceChannel (ctx : InteractionContext) (storeFn : InteractionContext -> Task) = + match ctx.Channel.Id with + | id when id = GuildEnvironment.channelArmory -> + storeFn ctx + | _ -> + task { + let msg = $"You must go to <#{GuildEnvironment.channelArmory}> channel to buy/sell or check your arsenal" + do! Messaging.sendSimpleResponse ctx msg + } + [] - member this.Arsenal (ctx : InteractionContext) = arsenal ctx + member this.Arsenal (ctx : InteractionContext) = enforceChannel ctx arsenal [] - member _.BuyHack (ctx : InteractionContext) = buy ctx ItemType.Hack + member _.BuyHack (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Hack) [] - member this.BuyShield (ctx : InteractionContext) = buy ctx ItemType.Shield + member this.BuyShield (ctx : InteractionContext) = enforceChannel ctx (buy ItemType.Shield) [] - member this.SellHack (ctx : InteractionContext) = sell ctx ItemType.Hack + member this.SellHack (ctx : InteractionContext) = enforceChannel ctx (sell ItemType.Hack) [] - member this.SellShield (ctx : InteractionContext) = sell ctx ItemType.Shield + member this.SellShield (ctx : InteractionContext) = enforceChannel ctx (sell ItemType.Shield)