Events for thief, update conn string var

This commit is contained in:
Joseph Ferano 2022-02-24 14:58:01 +07:00
parent 34d5d9c42a
commit eb4e42ad11
3 changed files with 12 additions and 16 deletions

View File

@ -11,7 +11,8 @@ DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../.dev.env" ], overwriteEx
let getVar str = Environment.GetEnvironmentVariable(str)
let getId str = getVar str |> uint64
let pgDb = getVar "CONN_STRING_2"
let pgDb = getVar "DATABASE_URL"
let guildId = getId "DISCORD_GUILD"
let tokenPlayerInteractions = getVar "TOKEN_PLAYER_INTERACTIONS"
let tokenSteal = getVar "TOKEN_STEAL"

View File

@ -151,11 +151,6 @@ let handleSteal (ctx : IDiscordContext) =
let num = rand.NextDouble()
let dp = { DiscordPlayer.Id = targetId ; DiscordPlayer.Name = targetName }
let stealAction = {
Type = Stealing ( true , dp )
Cooldown = ThiefCooldown.Minutes * 1<mins>
Timestamp = DateTime.UtcNow
}
let getResultEmbed' = getResultEmbed winPercentage prize thief.Bank thief dp
// TODO: Send event to the hall of privacy
// TODO: We need to check if the player is on cooldown
@ -170,9 +165,8 @@ let handleSteal (ctx : IDiscordContext) =
Timestamp = DateTime.UtcNow
Cooldown = VictimRecovery.Minutes * 1<mins>
}
let actions = t |> Player.removeExpiredActions |> fun p -> Array.append [| mugged |] p.Events
do! DbService.updatePlayer GuildEnvironment.pgDb { t with Bank = max (t.Bank - prize) 0<GBT> ; Events = actions }
|> Async.Ignore
do! DbService.updatePlayer GuildEnvironment.pgDb { t with Bank = max (t.Bank - prize) 0<GBT> } |> Async.Ignore
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId mugged |> Async.Ignore
| None -> ()
let stole = {
@ -180,13 +174,16 @@ let handleSteal (ctx : IDiscordContext) =
Cooldown = ThiefCooldown.Minutes * 1<mins>
Timestamp = DateTime.UtcNow
}
let actions = thief |> Player.removeExpiredActions |> fun p -> Array.append [| stole |] p.Events
do! DbService.updatePlayer GuildEnvironment.pgDb { thief with Bank = thief.Bank + prize ; Events = actions }
|> Async.Ignore
do! DbService.updatePlayer GuildEnvironment.pgDb { thief with Bank = thief.Bank + prize } |> Async.Ignore
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId stole |> Async.Ignore
| false ->
let embed = getResultEmbed' WentToPrison
do! DbService.updatePlayer GuildEnvironment.pgDb { thief with Events = Array.append [| stealAction |] thief.Events }
|> Async.Ignore
let imprisoned = {
Type = Imprison
Cooldown = ThiefCooldown.Minutes * 1<mins>
Timestamp = DateTime.UtcNow
}
do! DbService.addPlayerEvent GuildEnvironment.pgDb victim.DiscordId imprisoned |> Async.Ignore
do! Messaging.sendFollowUpEmbed ctx (embed.Build())
do! Async.Sleep 2000
let role = ctx.GetGuild().GetRole(GuildEnvironment.rolePrisoner)

View File

@ -100,13 +100,11 @@ module Types =
| Stealing of instigator : bool * adversary : DiscordPlayer
| Imprison
[<CLIMutable>]
type PlayerEvent =
{ Type : PlayerEventType
Cooldown : int<mins>
Timestamp : DateTime }
[<CLIMutable>]
type PlayerTraits = {
Strength : int
Focus : int