diff --git a/Bot/Bot.fsproj b/Bot/Bot.fsproj
index 073b522..d7929c4 100644
--- a/Bot/Bot.fsproj
+++ b/Bot/Bot.fsproj
@@ -13,11 +13,11 @@
-
+
+
-
diff --git a/Bot/DbService.fs b/Bot/DbService.fs
index de6f76d..45e60db 100644
--- a/Bot/DbService.fs
+++ b/Bot/DbService.fs
@@ -1,8 +1,6 @@
module Degenz.DbService
-open System.Security.Cryptography.X509Certificates
-open Degenz.Types
-
+open Degenz
open System
open Npgsql.FSharp
diff --git a/Bot/Embeds.fs b/Bot/Embeds.fs
index be37bb7..c3d7097 100644
--- a/Bot/Embeds.fs
+++ b/Bot/Embeds.fs
@@ -1,7 +1,6 @@
module Degenz.Embeds
open System
-open DSharpPlus
open Degenz.Messaging
open Degenz.Types
open DSharpPlus.Entities
@@ -45,7 +44,7 @@ let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerDat
| Hacking h -> h.HackId = item.Id && h.IsInstigator
| Shielding id -> id = item.Id
| _ -> false)
- let btnColor = Game.getClassButtonColor item.Class
+ let btnColor = WeaponClass.getClassButtonColor item.Class
match action , ignoreCooldown with
| None , _ | Some _ , true ->
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}-{buttonInfo}-{player.Name}", $"{item.Name}")
@@ -64,7 +63,7 @@ let pickDefense actionId player isTrainer =
for s in Player.getShields player |> Array.sortBy (fun i -> i.Power) do
let hours = TimeSpan.FromMinutes(int s.Cooldown).TotalHours
- let against = Game.getGoodAgainst(s.Class) |> snd
+ let against = WeaponClass.getGoodAgainst(s.Class) |> snd
embed.AddField(s.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore
DiscordFollowupMessageBuilder()
@@ -132,19 +131,19 @@ let getBuyItemsEmbed (player : PlayerData) (itemType : ItemType) (store : Item a
| _ ->
embed
// .AddField($"Defensive Strength |", string item.Power, true)
- .AddField($"Strong against |", Game.getGoodAgainst item.Class |> snd |> string, true)
+ .AddField($"Strong against |", WeaponClass.getGoodAgainst item.Class |> snd |> string, true)
.AddField("Active For |", $"{TimeSpan.FromMinutes(int item.Cooldown).Hours} hours", true)
.WithThumbnail(getShieldIcon (enum(item.Id)))
|> ignore
embed
.AddField("Price 💰", (if item.Price = 0 then "Free" else $"{item.Price} $GBT"), true)
- .WithColor(Game.getClassEmbedColor item.Class)
+ .WithColor(WeaponClass.getClassEmbedColor item.Class)
.WithTitle($"{item.Name}")
|> ignore
let button =
if player.Inventory |> Array.exists (fun i -> i.Id = item.Id)
- then DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Own {item.Name}", true)
- else DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Buy {item.Name}")
+ then DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Own {item.Name}", true)
+ else DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Buy-{item.Id}", $"Buy {item.Name}")
embed.Build() , button :> DiscordComponent)
|> Array.unzip
@@ -165,9 +164,9 @@ let getSellEmbed (itemType : ItemType) (player : PlayerData) =
embed
.AddField("Sell For 💰", $"{item.Price} $GBT", true)
.WithTitle($"{item.Name}")
- .WithColor(Game.getClassEmbedColor item.Class)
+ .WithColor(WeaponClass.getClassEmbedColor item.Class)
|> ignore
- let button = DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Sell-{item.Id}", $"Sell {item.Name}")
+ let button = DiscordButtonComponent(WeaponClass.getClassButtonColor item.Class, $"Sell-{item.Id}", $"Sell {item.Name}")
embed.Build() , button :> DiscordComponent)
|> Array.unzip
diff --git a/Bot/GameHelpers.fs b/Bot/GameHelpers.fs
index 3d494ea..0bac34a 100644
--- a/Bot/GameHelpers.fs
+++ b/Bot/GameHelpers.fs
@@ -16,6 +16,7 @@ module Armory =
let getItem itemId = battleItems |> Array.find (fun w -> w.Id = itemId)
module WeaponClass =
+ // TODO: Find a different place to put this
let SameTargetAttackCooldown = System.TimeSpan.FromHours(1)
let getClassButtonColor = function
diff --git a/Bot/GameTypes.fs b/Bot/GameTypes.fs
index 6942873..0151b3d 100644
--- a/Bot/GameTypes.fs
+++ b/Bot/GameTypes.fs
@@ -1,12 +1,6 @@
namespace Degenz
open System
-open System.Threading.Tasks
-open DSharpPlus
-open DSharpPlus.Entities
-open DSharpPlus.EventArgs
-open DSharpPlus.SlashCommands
-open Newtonsoft.Json
[]
module Types =
diff --git a/Bot/Games/HackerBattle.fs b/Bot/Games/HackerBattle.fs
index f58dd28..b710e28 100644
--- a/Bot/Games/HackerBattle.fs
+++ b/Bot/Games/HackerBattle.fs
@@ -8,6 +8,7 @@ open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz
open Degenz.Messaging
+open Degenz.PlayerInteractions
let checkPlayerIsAttackingThemselves defender attacker =
match attacker.DiscordId = defender.DiscordId with
@@ -95,7 +96,7 @@ let updateCombatants successfulHack (attacker : PlayerData) (defender : PlayerDa
}
{ Type = Hacking hackEvent
Timestamp = DateTime.UtcNow
- Cooldown = if isDefenderEvent then int Game.SameTargetAttackCooldown.TotalMinutes * 1 else hack.Cooldown }
+ Cooldown = if isDefenderEvent then int WeaponClass.SameTargetAttackCooldown.TotalMinutes * 1 else hack.Cooldown }
[ DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer prize (event false) attacker
DbService.updatePlayer GuildEnvironment.pgDb <| updatePlayer -prize (event true) defender
@@ -136,7 +137,7 @@ let failedHack (ctx : IDiscordContext) attacker defender hack =
}
let hack (target : DiscordUser) (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerActionWithTarget target ctx (fun attacker defender -> async {
+ executePlayerActionWithTarget target ctx (fun attacker defender -> async {
do! attacker
|> Player.removeExpiredActions
|> checkAlreadyHackedTarget defender
@@ -151,7 +152,7 @@ let hack (target : DiscordUser) (ctx : IDiscordContext) =
})
let handleAttack (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun attacker -> async {
+ executePlayerAction ctx (fun attacker -> async {
let tokens = ctx.GetInteractionId().Split("-")
let hackId = int tokens.[1]
let hack = Armory.getItem hackId
@@ -176,7 +177,7 @@ let handleAttack (ctx : IDiscordContext) =
})
let defend (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
if Player.getShields player |> Array.length > 0 then
let p = Player.removeExpiredActions player
let embed = Embeds.pickDefense "Defend" p false
@@ -187,7 +188,7 @@ let defend (ctx : IDiscordContext) =
})
let handleDefense (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
let tokens = ctx.GetInteractionId().Split("-")
let shieldId = int tokens.[1]
let shield = Armory.getItem shieldId
@@ -218,7 +219,7 @@ let handleDefense (ctx : IDiscordContext) =
})
let arsenal (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
let updatedPlayer = Player.removeExpiredActions player
let builder = DiscordFollowupMessageBuilder()
let embed = DiscordEmbedBuilder()
diff --git a/Bot/Games/RockPaperScissors.fs b/Bot/Games/RockPaperScissors.fs
index 7b93835..8183495 100644
--- a/Bot/Games/RockPaperScissors.fs
+++ b/Bot/Games/RockPaperScissors.fs
@@ -1,6 +1,5 @@
module Degenz.RockPaperScissors
-open System
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
diff --git a/Bot/Games/SlotMachine.fs b/Bot/Games/SlotMachine.fs
index b401381..62f54a3 100644
--- a/Bot/Games/SlotMachine.fs
+++ b/Bot/Games/SlotMachine.fs
@@ -1,7 +1,6 @@
module Degenz.SlotMachine
open System
-open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
open DSharpPlus.SlashCommands
diff --git a/Bot/Games/Store.fs b/Bot/Games/Store.fs
index 3e2efb4..c105a40 100644
--- a/Bot/Games/Store.fs
+++ b/Bot/Games/Store.fs
@@ -7,6 +7,7 @@ open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz
open Degenz.Messaging
+open Degenz.PlayerInteractions
let checkHasSufficientFunds (item : Item) player =
if player.Bank - item.Price >= 0
@@ -29,13 +30,13 @@ let checkHasItemsInArsenal itemType player =
else Error $"You currently have no {itemType}s in your arsenal to sell!"
let buy itemType (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
let itemStore = Embeds.getBuyItemsEmbed player itemType Armory.battleItems
do! ctx.FollowUp itemStore |> Async.AwaitTask
})
let sell itemType (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
match checkHasItemsInArsenal itemType player with
| Ok _ -> let itemStore = Embeds.getSellEmbed itemType player
do! ctx.FollowUp(itemStore) |> Async.AwaitTask
@@ -44,7 +45,7 @@ let sell itemType (ctx : IDiscordContext) =
// TODO: When you buy a shield, prompt the user to activate it
let handleBuyItem (ctx : IDiscordContext) itemId =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
let item = Armory.battleItems |> Array.find (fun w -> w.Id = itemId)
do! player
|> checkHasSufficientFunds item
@@ -58,7 +59,7 @@ let handleBuyItem (ctx : IDiscordContext) itemId =
})
let handleSell (ctx : IDiscordContext) itemId =
- PlayerInteractions.executePlayerAction ctx (fun player -> async {
+ executePlayerAction ctx (fun player -> async {
let item = Armory.getItem itemId
do!
player
diff --git a/Bot/Games/Thief.fs b/Bot/Games/Thief.fs
index 5cdb0fa..fd1a196 100644
--- a/Bot/Games/Thief.fs
+++ b/Bot/Games/Thief.fs
@@ -7,6 +7,7 @@ open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open Degenz.Messaging
+open Degenz.PlayerInteractions
let ThiefCooldown = TimeSpan.FromMinutes(1)
let VictimRecovery = TimeSpan.FromHours(1)
@@ -119,7 +120,7 @@ let calculateWinPercentage amountRequested bank attackerStrength defenderStrengt
//calculateWinPercentage 50 200 100 85
let steal target amount (ctx : IDiscordContext) =
- PlayerInteractions.executePlayerActionWithTarget target ctx (fun thief victim -> async { do!
+ executePlayerActionWithTarget target ctx (fun thief victim -> async { do!
thief
|> checkPlayerIsAttackingThemselves victim
// |> checkVictimStealingCooldown victim
@@ -219,7 +220,7 @@ let handleSteal (ctx : IDiscordContext) =
}
if answer = "yes" then
let targetId = uint64 tokens.[2]
- PlayerInteractions.executePlayerActionWithTargetId true targetId ctx (fun attacker defender -> async {
+ executePlayerActionWithTargetId true targetId ctx (fun attacker defender -> async {
do! attacker
|> Player.removeExpiredActions
// |> checkVictimStealingCooldown defender
diff --git a/Bot/Games/Trainer.fs b/Bot/Games/Trainer.fs
index 781bf57..e8958e9 100644
--- a/Bot/Games/Trainer.fs
+++ b/Bot/Games/Trainer.fs
@@ -4,7 +4,6 @@ open System.Text
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
-open DSharpPlus.EventArgs
open Degenz.Types
open Degenz.Messaging
diff --git a/Bot/Messaging.fs b/Bot/Messaging.fs
index 9a0bfd9..d8298f1 100644
--- a/Bot/Messaging.fs
+++ b/Bot/Messaging.fs
@@ -135,9 +135,3 @@ let updateMessageWithGreyedOutButtons (ctx : IDiscordContext) interactiveMessage
builder.Content <- interactiveMessage.Message
do! ctx.Respond(InteractionResponseType.UpdateMessage, builder) |> Async.AwaitTask
}
-
-let handleResultWithResponse ctx fn (player : Result) =
- match player with
- | Ok p -> fn p
- | Error e -> async { do! sendFollowUpMessage ctx e }
-
diff --git a/Bot/PlayerInteractions.fs b/Bot/PlayerInteractions.fs
index 3122c8c..bfe188e 100644
--- a/Bot/PlayerInteractions.fs
+++ b/Bot/PlayerInteractions.fs
@@ -53,6 +53,11 @@ let executePlayerActionWithTargetId defer (targetId : uint64) (ctx : IDiscordCon
| _ , None -> do! Messaging.sendFollowUpMessage ctx "Your target is not connected to the network, they must join first by using the /redpill command"
} |> Async.StartAsTask :> Task
+let handleResultWithResponse ctx fn (player : Result) =
+ match player with
+ | Ok p -> fn p
+ | Error e -> async { do! Messaging.sendFollowUpMessage ctx e }
+
module Commands =
let newPlayer nickname (membr : uint64) =
let rand = System.Random(System.Guid.NewGuid().GetHashCode())