Only assign role if there weren't any errors

This commit is contained in:
Joseph Ferano 2022-05-13 11:59:06 +07:00
parent 5fb7d83ac0
commit 43f947145f
2 changed files with 9 additions and 5 deletions

View File

@ -2,6 +2,7 @@ module Degenz.Store
open System
open System.Data
open System.Threading.Tasks
open DSharpPlus.Entities
open DSharpPlus
open DSharpPlus.EventArgs
@ -233,7 +234,7 @@ let sell itemType getItems (ctx : IDiscordContext) =
})
// TODO: When you buy a shield, prompt the user to activate it
let handleBuyItem (ctx : IDiscordContext) itemId =
let handleBuyItem (dispatch : IDiscordContext -> Task) (ctx : IDiscordContext) itemId =
executePlayerAction ctx (fun player -> async {
let storeId = ctx.GetInteractionId().Split("-").[2]
let! storeInventory = DbService.getStoreItems storeId
@ -262,6 +263,8 @@ let handleBuyItem (ctx : IDiscordContext) itemId =
builder.AddEmbed(embed) |> ignore
do! ctx.FollowUp builder |> Async.AwaitTask
do! dispatch ctx |> Async.AwaitTask
let builder = DiscordMessageBuilder()
builder.WithContent($"{player.Name} just purchased {item.Name}!") |> ignore
let channel = ctx.GetGuild().GetChannel(GuildEnvironment.channelEventsHackerBattle)
@ -322,7 +325,7 @@ let handleJpegEvents _ (event : ComponentInteractionCreateEventArgs) =
let itemId = id.Split("-").[1]
let storeId = id.Split("-").[2]
match id with
| id when id.StartsWith("Buy") -> handleBuyItem ctx itemId
| id when id.StartsWith("Buy") -> handleBuyItem (fun _ -> Task.CompletedTask) ctx itemId
| id when id.StartsWith("ShowStore") -> buy storeId None ctx
| id when id.StartsWith("ShowJpegInventory") -> showJpegsEmbed ctx
| _ ->
@ -339,7 +342,7 @@ let handleStoreEvents _ (event : ComponentInteractionCreateEventArgs) =
let itemId = id.Split("-").[1]
let storeId = id.Split("-").[2]
match id with
| id when id.StartsWith("Buy") -> handleBuyItem ctx itemId
| id when id.StartsWith("Buy") -> handleBuyItem (fun _ -> Task.CompletedTask) ctx itemId
| id when id.StartsWith("Sell") -> handleSell ctx itemId
| id when id.StartsWith("ShowHacks") -> buy storeId (Some ItemType.Hack) ctx
| id when id.StartsWith("ShowShields") -> buy storeId (Some ItemType.Shield) ctx

View File

@ -57,8 +57,9 @@ let handleButtonEvent _ (event : ComponentInteractionCreateEventArgs) =
task {
let id = ctx.GetInteractionId()
let itemId = id.Split("-").[1]
do! Store.handleBuyItem ctx itemId
do! grantWhitelistRole (itemId = "WHITEOG") ctx
let dispatch ctx = grantWhitelistRole (itemId = "WHITEOG") ctx
do! Store.handleBuyItem dispatch ctx itemId
} :> Task
| id when id.StartsWith("CreateGuildInvite") -> InviteTracker.handleCreateInvite ctx
| id when id.StartsWith("ShowRecruited") -> InviteTracker.getInvitedUsersForId (ctx.GetDiscordMember()) ctx