Analytics, several fixes

This commit is contained in:
Joseph Ferano 2022-04-20 12:58:34 +07:00
parent 937eeb4cc2
commit 310699ea50
2 changed files with 70 additions and 49 deletions

View File

@ -150,3 +150,18 @@ let shieldActivated (discordMember : DiscordMember) shieldName =
"shield_name" , shieldName
]
track "Shield Button Clicked" discordMember.Id data
let prizeTableViewed (discordMember : DiscordMember) =
let data = [
"user_display_name" , discordMember.Username
]
track "Shield Button Clicked" discordMember.Id data
let slotPlayed (discordMember : DiscordMember) amount result prize =
let data = [
"user_display_name" , discordMember.Username
"play_amount" , string amount
"result" , string result
"prize" , string result
]
track "Shield Button Clicked" discordMember.Id data

View File

@ -136,12 +136,14 @@ let sleepTime = 1500
let mutable guildEmojis : Map<string, DiscordEmoji> option = None
let mutable anyEmoji : DiscordEmoji option = None
let embedButtons =
let button1 = DiscordButtonComponent(ButtonStyle.Success, $"spin-1x", $"Spin 1x - {PlayPricex1} $GBT") :> DiscordComponent
let button2 = DiscordButtonComponent(ButtonStyle.Success, $"spin-2x", $"Spin 2x - {PlayPricex2} $GBT") :> DiscordComponent
let button3 = DiscordButtonComponent(ButtonStyle.Success, $"spin-3x", $"Spin 3x - {PlayPricex3} $GBT") :> DiscordComponent
let embedButtons includePrizeTable =
let button1 = DiscordButtonComponent(ButtonStyle.Success, $"spin-1x", $"Bet 1x - {PlayPricex1} $GBT") :> DiscordComponent
let button2 = DiscordButtonComponent(ButtonStyle.Success, $"spin-2x", $"Bet 2x - {PlayPricex2} $GBT") :> DiscordComponent
let button3 = DiscordButtonComponent(ButtonStyle.Success, $"spin-3x", $"Bet 3x - {PlayPricex3} $GBT") :> DiscordComponent
let button4 = DiscordButtonComponent(ButtonStyle.Primary, $"prizes", $"Show Prizes") :> DiscordComponent
[| button1 ; button2 ; button3 ; button4 |]
if includePrizeTable
then [| button1 ; button2 ; button3 ; button4 |]
else [| button1 ; button2 ; button3 |]
let getJackpotAmount () =
GuildEnvironment.connectionString
@ -177,7 +179,7 @@ let handlePrizeTable (ctx : IDiscordContext) =
let prizeTxt =
match prize with
| Money m -> $"**{m}** $GBT"
| Jackpot -> $"**🎉JACKPOT🎉**"
| Jackpot -> $"**JACKPOT**"
let line =
match s1 , s2 , s3 with
| Symbol s1' , Symbol s2' , Symbol s3' ->
@ -193,9 +195,8 @@ let handlePrizeTable (ctx : IDiscordContext) =
embed.Color <- DiscordColor.Green
embed.Title <- "Degenz Slots Prize Table"
embed.Description <- $"Current Jackpot At: **{jackpot}** $GBT\n\n**Combo** **Prize**\n{rows}"
let builder = DiscordFollowupMessageBuilder()
builder.IsEphemeral <- true
do! ctx.FollowUp(builder.AddEmbed(embed))
do! ctx.FollowUp(DiscordFollowupMessageBuilder().AsEphemeral().AddEmbed(embed))
do! Analytics.prizeTableViewed (ctx.GetDiscordMember())
| _ , _ -> return ()
} :> Task
@ -225,7 +226,12 @@ let spinEmojis (builder : DiscordFollowupMessageBuilder) (results : SlotSymbol a
}
let spin multiplier (ctx : IDiscordContext) =
PlayerInteractions.executePlayerAction ctx (fun player -> async {
let playAmount =
match multiplier with
| 1 -> PlayPricex1
| 2 -> PlayPricex2
| _ -> PlayPricex3
let execute player = async {
let random = Random(Guid.NewGuid().GetHashCode())
let symbols = [| reel1.[random.Next(0, reel1.Length)] ; reel2.[random.Next(0, reel2.Length)] ; reel3.[random.Next(0, reel3.Length)] |]
@ -253,49 +259,49 @@ let spin multiplier (ctx : IDiscordContext) =
let addGBTField (embed : DiscordEmbedBuilder) prize =
let sym = if prize > 0<GBT> then "+" else "-"
embed.AddField("New 💰$GBT Balance", $"`💰` {player.Bank} `💰` {player.Bank + prize} `({sym}{abs prize} $GBT)`") |> ignore
match prize with
| Some (Money amount) ->
let prizeWithMultiplier = amount * multiplier
do! DbService.updatePlayerCurrency prizeWithMultiplier player |> Async.Ignore
embed.ImageUrl <- "https://s7.gifyu.com/images/youwin.png"
embed.Color <- DiscordColor.Green
embed.Color <- DiscordColor.Purple
embed.Description <- $"You win **{prizeWithMultiplier}** GBT!"
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed prizeWithMultiplier
| Some (Jackpot) ->
let! jackpot = getJackpotAmount ()
embed.ImageUrl <- "https://s7.gifyu.com/images/jackpot2ac30c9823f6a91c.png"
embed.Color <- DiscordColor.Purple
embed.Description <- $"YOU HIT THE JACKPOT!!!"
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed jackpot
do! resetJackpot BaseJackpotAmount |> Async.Ignore
| None ->
let playAmount =
match multiplier with
| 1 -> PlayPricex1
| 2 -> PlayPricex2
| _ -> PlayPricex3
// TODO: We have to make sure we don't go below zero
do! DbService.updatePlayerCurrency -playAmount player |> Async.Ignore
do! incrementJackpot playAmount |> Async.Ignore
let! jackpot = getJackpotAmount ()
embed.Description <- $"Better luck next time! You paid {playAmount} $GBT"
embed.Color <- DiscordColor.Red
embed.AddField("New 🎉JACKPOT🎉", $"`💰` {jackpot} `$GBT`", true) |> ignore
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed -playAmount
let! result , prizeAmount = async {
match prize with
| Some (Money amount) ->
let prizeWithMultiplier = amount * multiplier
do! DbService.updatePlayerCurrency prizeWithMultiplier player |> Async.Ignore
embed.Color <- DiscordColor.Green
embed.Description <- $"You win **{prizeWithMultiplier}** GBT!"
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed prizeWithMultiplier
return "WON" , prizeWithMultiplier
| Some (Jackpot) ->
let! jackpot = getJackpotAmount ()
embed.Color <- DiscordColor.Purple
embed.Description <- $"YOU HIT THE JACKPOT!!!"
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed jackpot
do! DbService.updatePlayerCurrency jackpot player |> Async.Ignore
do! resetJackpot BaseJackpotAmount |> Async.Ignore
return "JACKPOT" , jackpot
| None ->
do! DbService.updatePlayerCurrency -playAmount player |> Async.Ignore
do! incrementJackpot playAmount |> Async.Ignore
let! jackpot = getJackpotAmount ()
embed.Description <- $"Better luck next time! You paid {playAmount} $GBT"
embed.Color <- DiscordColor.Red
embed.AddField("New JACKPOT", $"`💰` {jackpot} `$GBT`", true) |> ignore
embed.AddField("Result", $"{slotsContent}", true) |> ignore
addGBTField embed -playAmount
return "LOST" , 0<GBT>
}
let dwb = DiscordWebhookBuilder()
dwb.AddComponents(embedButtons).AddEmbed(embed).WithContent(slotsContent) |> ignore
dwb.AddComponents(embedButtons false).AddEmbed(embed).WithContent(slotsContent) |> ignore
do! itx.EditFollowupMessageAsync(followUpMessage.Id, dwb) |> Async.AwaitTask |> Async.Ignore
return ()
})
do! Analytics.slotPlayed (ctx.GetDiscordMember()) playAmount result prizeAmount
}
PlayerInteractions.executePlayerAction ctx (fun player ->
if player.Bank > playAmount then
execute player
else
Messaging.sendFollowUpMessage ctx "You do not have sufficient funds to play")
let handleButton (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) =
let ctx = DiscordEventContext event
// TODO: We have to make sure the player has enough money
match event.Id with
| "spin-1x" -> spin 1 ctx
| "spin-2x" -> spin 2 ctx
@ -335,7 +341,7 @@ let sendInitialEmbed (ctx : IDiscordContext) =
builder.AddEmbed(embed) |> ignore
builder.AddComponents embedButtons |> ignore
builder.AddComponents(embedButtons true) |> ignore
do! GuildEnvironment.botClientSlots.Value.SendMessageAsync(channel, builder)
|> Async.AwaitTask
|> Async.Ignore