Catch exception so we show embed that we ran out of stock
This commit is contained in:
		
							parent
							
								
									6fe647f9f1
								
							
						
					
					
						commit
						0853463120
					
				@ -246,11 +246,16 @@ let getWhitelistItem () =
 | 
			
		||||
    |> Sql.executeRowAsync (fun read -> {| Stock = read.int "stock" ; Price = read.int "price" |})
 | 
			
		||||
    |> Async.AwaitTask
 | 
			
		||||
 | 
			
		||||
let updateWhitelistStock () =
 | 
			
		||||
    connStr
 | 
			
		||||
let updateWhitelistStock () = async {
 | 
			
		||||
    try
 | 
			
		||||
    do! connStr
 | 
			
		||||
        |> Sql.connect
 | 
			
		||||
        |> Sql.query """
 | 
			
		||||
                UPDATE item SET stock = stock - 1 WHERE symbol = 'WHITELIST'
 | 
			
		||||
            """
 | 
			
		||||
        |> Sql.executeNonQueryAsync
 | 
			
		||||
        |> Async.AwaitTask
 | 
			
		||||
        |> Async.Ignore
 | 
			
		||||
    return true
 | 
			
		||||
    with _ -> return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,6 @@ open Npgsql.FSharp
 | 
			
		||||
 | 
			
		||||
let connStr = GuildEnvironment.connectionString
 | 
			
		||||
let InviteRewardAmount = 100<GBT>
 | 
			
		||||
let WhitelistPrice = 1000
 | 
			
		||||
 | 
			
		||||
type Invite = {
 | 
			
		||||
    Code : string
 | 
			
		||||
@ -356,22 +355,16 @@ let tryGrantWhitelist (ctx : IDiscordContext) stock price =
 | 
			
		||||
        let user = ctx.GetDiscordMember()
 | 
			
		||||
        match! DbService.tryFindPlayer user.Id with
 | 
			
		||||
        | Some player ->
 | 
			
		||||
            let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)
 | 
			
		||||
            if Seq.contains role user.Roles then
 | 
			
		||||
                return AlreadyWhitelisted
 | 
			
		||||
            elif player.Active then
 | 
			
		||||
                let hackerRole = ctx.GetGuild().GetRole(GuildEnvironment.roleHacker)
 | 
			
		||||
                if Seq.contains hackerRole user.Roles then
 | 
			
		||||
                    if int player.Bank >= price then
 | 
			
		||||
                        return Granted player
 | 
			
		||||
                    elif stock > 0 then
 | 
			
		||||
                        return NotEnoughGBT (int player.Bank)
 | 
			
		||||
                    else
 | 
			
		||||
                        return NotEnoughStock
 | 
			
		||||
                else
 | 
			
		||||
                    return NotAHacker
 | 
			
		||||
            else
 | 
			
		||||
                return NotInGame
 | 
			
		||||
            let hasWhitelist = Seq.contains (ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)) user.Roles
 | 
			
		||||
            let isHacker = Seq.contains (ctx.GetGuild().GetRole(GuildEnvironment.roleHacker)) user.Roles
 | 
			
		||||
 | 
			
		||||
            match hasWhitelist , player.Active , isHacker , stock > 0 , int player.Bank >= price with
 | 
			
		||||
            | true , _ , _ , _ , _  -> return AlreadyWhitelisted
 | 
			
		||||
            | _ , false , _ , _ , _ -> return NotInGame
 | 
			
		||||
            | _ , _ , false , _ , _ -> return NotAHacker
 | 
			
		||||
            | _ , _ , _ , false , _ -> return NotEnoughStock
 | 
			
		||||
            | _ , _ , _ , _ , false -> return NotEnoughGBT (int player.Bank)
 | 
			
		||||
            | _ , _ , _ , _ , _     -> return Granted player
 | 
			
		||||
        | None -> return NotInGame
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -399,11 +392,11 @@ Just type `/recruit` anywhere, or press the button below...
 | 
			
		||||
`/recruited` - Check how many Degenz you’ve invited.
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
let notEnoughMoneyMsg total = $"""
 | 
			
		||||
let notEnoughMoneyMsg price total = $"""
 | 
			
		||||
Oh no!
 | 
			
		||||
You don't have enough **$GBT** to buy a WHITELIST spot! Come back when you have `{WhitelistPrice - total}` more $GBT.
 | 
			
		||||
You don't have enough **$GBT** to buy a WHITELIST spot! Come back when you have `{price - total}` more $GBT.
 | 
			
		||||
 | 
			
		||||
The QUICKEST way to earn $GBT is by recruiting other Degenz into the server.
 | 
			
		||||
The QUICKEST way to earn **$GBT** is by recruiting other Degenz into the server.
 | 
			
		||||
Earn `{InviteRewardAmount} $GBT` 💰 for every Degen you recruit into the game!
 | 
			
		||||
 | 
			
		||||
Just type `/recruit` anywhere, anytime... Or just press the button below!
 | 
			
		||||
@ -449,7 +442,7 @@ let handleGimmeWhitelist (ctx : IDiscordContext) =
 | 
			
		||||
        | NotEnoughGBT total ->
 | 
			
		||||
            includeInfo wlItem.Stock wlItem.Price
 | 
			
		||||
            builder.AddComponents([ buyBtn ; recruitBtn ]) |> ignore
 | 
			
		||||
            whitelistEmbed.Description <- notEnoughMoneyMsg total
 | 
			
		||||
            whitelistEmbed.Description <- notEnoughMoneyMsg wlItem.Price total
 | 
			
		||||
        | Granted _ ->
 | 
			
		||||
            includeInfo wlItem.Stock wlItem.Price
 | 
			
		||||
            whitelistEmbed.Color <- DiscordColor.Green
 | 
			
		||||
@ -503,6 +496,8 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
 | 
			
		||||
            builder.Content <- $"We just ran out of stock, tough shit"
 | 
			
		||||
            do! ctx.FollowUp(builder)
 | 
			
		||||
        | Granted player ->
 | 
			
		||||
            match! DbService.updateWhitelistStock () with
 | 
			
		||||
            | true ->
 | 
			
		||||
                let embed = DiscordEmbedBuilder()
 | 
			
		||||
                embed.Description <- buyWhitelistMsg
 | 
			
		||||
                embed.Color <- DiscordColor.Green
 | 
			
		||||
@ -511,7 +506,7 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
 | 
			
		||||
                builder.AddComponents ([ recruitBtn ]) |> ignore
 | 
			
		||||
                let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)
 | 
			
		||||
                do! ctx.GetDiscordMember().GrantRoleAsync(role)
 | 
			
		||||
            let! _ = DbService.updatePlayerCurrency -WhitelistPrice player
 | 
			
		||||
                let! _ = DbService.updatePlayerCurrency -wlItem.Price player
 | 
			
		||||
                builder.AddEmbed(embed) |> ignore
 | 
			
		||||
                do! ctx.FollowUp(builder)
 | 
			
		||||
 | 
			
		||||
@ -523,8 +518,13 @@ let handleBuyWhitelist (ctx : IDiscordContext) =
 | 
			
		||||
                    |> Async.AwaitTask
 | 
			
		||||
                    |> Async.Ignore
 | 
			
		||||
                let user = ctx.GetDiscordMember()
 | 
			
		||||
            do! Analytics.whiteListPurchased WhitelistPrice user.Id user.Username
 | 
			
		||||
 | 
			
		||||
                do! Analytics.whiteListPurchased wlItem.Price user.Id user.Username
 | 
			
		||||
            | false ->
 | 
			
		||||
                let embed = DiscordEmbedBuilder()
 | 
			
		||||
                embed.Description <- "Oh no! Looks like the last Whitelist spot was taken. Don't worry you weren't charged..."
 | 
			
		||||
                embed.Color <- DiscordColor.Red
 | 
			
		||||
                builder.AddEmbed(embed) |> ignore
 | 
			
		||||
                do! ctx.FollowUp(builder)
 | 
			
		||||
    } :> Task
 | 
			
		||||
 | 
			
		||||
let handleCreateInvite (ctx : IDiscordContext) =
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user