From 8652828892b74ba19c2c5d80b990e2861c645d45 Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 18 Feb 2022 20:48:50 +0700 Subject: [PATCH] Setup steal bot, more tweaks --- .gitignore | 4 +--- Bot/Bot.fs | 18 ++++++++++++++---- Bot/GuildEnvironment.fs | 10 ++++------ Bot/Thief.fs | 18 ++++++++++++++++-- 4 files changed, 35 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index b218407..9fa882c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,9 +10,7 @@ *.userosscache *.sln.docstates -env.prod -env.stag -env.dev +*.env # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs diff --git a/Bot/Bot.fs b/Bot/Bot.fs index 521c553..f58fcd8 100644 --- a/Bot/Bot.fs +++ b/Bot/Bot.fs @@ -5,7 +5,6 @@ open DSharpPlus open DSharpPlus.SlashCommands open Degenz open Degenz.HackerBattle -open Degenz.RockPaperScissors open Degenz.Store open Degenz.Thief open Emzi0767.Utilities @@ -17,11 +16,12 @@ let guild = GuildEnvironment.guildId let hackerBattleConfig = DiscordConfiguration() let storeConfig = DiscordConfiguration() +let stealConfig = DiscordConfiguration() //let slotMachineConfig = DiscordConfiguration() //hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace //let configs = [| hackerBattleConfig ; storeConfig ; slotMachineConfig ; |] -let configs = [ hackerBattleConfig ; storeConfig ] +let configs = [ hackerBattleConfig ; storeConfig ; stealConfig ] hackerBattleConfig.TokenType <- TokenType.Bot hackerBattleConfig.Intents <- DiscordIntents.All @@ -29,27 +29,34 @@ hackerBattleConfig.Intents <- DiscordIntents.All storeConfig.TokenType <- TokenType.Bot storeConfig.Intents <- DiscordIntents.All +stealConfig.TokenType <- TokenType.Bot +stealConfig.Intents <- DiscordIntents.All + hackerBattleConfig.Token <- GuildEnvironment.tokenHackerBattle storeConfig.Token <- GuildEnvironment.tokenStore +stealConfig.Token <- GuildEnvironment.tokenSteal //slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE") let hackerBattleBot = new DiscordClient(hackerBattleConfig) let storeBot = new DiscordClient(storeConfig) +let stealBot = new DiscordClient(stealConfig) //let slotMachineBot = new DiscordClient(slotMachineConfig) //let clients = [| hackerBattleBot ; storeBot ; slotMachineBot |] let hackerCommands = hackerBattleBot.UseSlashCommands() let storeCommands = storeBot.UseSlashCommands() +let stealCommands = stealBot.UseSlashCommands() //let sc3 = slotMachineBot.UseSlashCommands() hackerCommands.RegisterCommands(guild); -hackerCommands.RegisterCommands(guild); -//hackerCommands.RegisterCommands(guild); storeCommands.RegisterCommands(guild); +stealCommands.RegisterCommands(guild); +//hackerCommands.RegisterCommands(guild); //sc3.RegisterCommands(guild); hackerBattleBot.add_ComponentInteractionCreated(AsyncEventHandler(HackerBattle.handleButtonEvent)) storeBot.add_ComponentInteractionCreated(AsyncEventHandler(Store.handleStoreEvents)) +stealBot.add_ComponentInteractionCreated(AsyncEventHandler(Thief.handleStealButton)) let asdf (_ : DiscordClient) (event : DSharpPlus.EventArgs.InteractionCreateEventArgs) = async { @@ -72,9 +79,12 @@ if guild <> 922419263275425832uL then hackerBattleBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously GuildEnvironment.botUserHackerBattle <- Some hackerBattleBot.CurrentUser + storeBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously GuildEnvironment.botUserArmory <- Some storeBot.CurrentUser +stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously + //async { // let! user = hackerBattleBot.GetUserAsync(GuildEnvironment.botIdHackerBattle) |> Async.AwaitTask // if user <> null then diff --git a/Bot/GuildEnvironment.fs b/Bot/GuildEnvironment.fs index ac322a5..8887276 100644 --- a/Bot/GuildEnvironment.fs +++ b/Bot/GuildEnvironment.fs @@ -4,18 +4,16 @@ module Degenz.GuildEnvironment open System open DSharpPlus.Entities open dotenv.net -let g = Environment.GetEnvironmentVariable("DISCORD_GUILD") -printfn $"{g}" -DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../env.dev" ], overwriteExistingVars = false)) -//DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../env.stag" ], overwriteExistingVars = false)) -//DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../env.prod" ], overwriteExistingVars = false)) +DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../.dev.env" ], overwriteExistingVars = false)) +//DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../.sta.env" ], overwriteExistingVars = false)) +//DotEnv.Load(DotEnvOptions(envFilePaths = [ "../../../../.prod.env" ], overwriteExistingVars = false)) let getVar str = Environment.GetEnvironmentVariable(str) let getId str = getVar str |> uint64 let guildId = getId "DISCORD_GUILD" -printfn $"{guildId}" let tokenPlayerInteractions = getVar "TOKEN_PLAYER_INTERACTIONS" +let tokenSteal = getVar "TOKEN_STEAL" let tokenHackerBattle = getVar "TOKEN_HACKER_BATTLE" let tokenStore = getVar "TOKEN_STORE" let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE" diff --git a/Bot/Thief.fs b/Bot/Thief.fs index 1dc974f..126f7d4 100644 --- a/Bot/Thief.fs +++ b/Bot/Thief.fs @@ -4,11 +4,12 @@ open System open System.Threading.Tasks open DSharpPlus open DSharpPlus.Entities +open DSharpPlus.EventArgs open DSharpPlus.SlashCommands open Degenz.Messaging let ThiefCooldown = TimeSpan.FromMinutes(1) -let VictimRecovery = TimeSpan.FromHours(6) +let VictimRecovery = TimeSpan.FromHours(4) type StealResult = | Success @@ -116,7 +117,8 @@ let checkThiefCooldown attacker = let calculateWinPercentage amountRequested bank attackerStrength defenderStrength = let powerPercentage = float (attackerStrength - defenderStrength) * 0.005 + 0.1 - let cappedAmount = float bank * 0.5 +// let cappedAmount = float bank * 0.5 + let cappedAmount = float bank let cappedRequest , wasCapped = if amountRequested > cappedAmount then ( cappedAmount , true ) else ( amountRequested , false ) let wagerPercentage = 1.0 - (cappedRequest / cappedAmount) // Max chance of success is 90.0% @@ -246,6 +248,18 @@ let handleSteal (ctx : IDiscordContext) = do! ctx.Respond InteractionResponseType.UpdateMessage builder |> Async.AwaitTask } |> Async.StartAsTask :> Task +let handleStealButton (_ : DiscordClient) (event : ComponentInteractionCreateEventArgs) = + let eventCtx = DiscordEventContext event :> IDiscordContext + match event.Id with + | id when id.StartsWith("Steal") -> handleSteal eventCtx + | _ -> + task { + let builder = DiscordInteractionResponseBuilder() + builder.IsEphemeral <- true + builder.Content <- $"Incorrect Action identifier {eventCtx.GetInteractionId()}" + do! eventCtx.Respond InteractionResponseType.ChannelMessageWithSource builder |> Async.AwaitTask + } + type StealGame() = inherit ApplicationCommandModule ()