discord-bot-game/Bot/Embeds.fs

146 lines
6.5 KiB
Forth

module Degenz.Embeds
open System
open Degenz.Messaging
open Degenz.Types
open DSharpPlus.Entities
let hackGif = "https://s10.gifyu.com/images/Hacker-Degenz-V20ce8eb832734aa62-min.gif"
let shieldGif = "https://s10.gifyu.com/images/Defense-Degenz-V2-min.gif"
let getItemIcon id =
match enum<ItemId>(id) with
| ItemId.Virus -> "https://s10.gifyu.com/images/Virus-icon.jpg"
| ItemId.RemoteAccess -> "https://s10.gifyu.com/images/Mind-Control-Degenz-V2-min.jpg"
| ItemId.Worm -> "https://s10.gifyu.com/images/WormBugAttack_Degenz-min.jpg"
| ItemId.Firewall -> "https://s10.gifyu.com/images/Defense-GIF-1-Degenz-1.jpg"
| ItemId.Encryption -> "https://s10.gifyu.com/images/Encryption-Degenz-V2-1-min.jpg"
| ItemId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.jpg"
| _ -> hackGif
let getItemGif id =
match enum<ItemId>(id) with
| ItemId.Virus -> "https://s10.gifyu.com/images/Attack-DegenZ-1.gif"
| ItemId.RemoteAccess -> "https://s10.gifyu.com/images/Mind-Control-Degenz-V2-min.gif"
| ItemId.Worm -> "https://s10.gifyu.com/images/WormBugAttack_Degenz-min.gif"
| ItemId.Firewall -> "https://s10.gifyu.com/images/Defense-GIF-1-Degenz-min.gif"
| ItemId.Encryption -> "https://s10.gifyu.com/images/Encryption-Degenz-V2-1-min.gif"
| ItemId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.gif"
| _ -> hackGif
let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) (items : Inventory) ignoreCooldown =
items
|> List.map (fun item ->
let action =
player.Events
|> List.tryFind (fun event ->
match event.Type with
| Hacking h -> h.HackId = item.Id && h.IsInstigator
| Shielding id -> id = item.Id
| _ -> false)
let btnColor = WeaponClass.getClassButtonColor item
match action , ignoreCooldown with
| None , _ | Some _ , true ->
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}-{buttonInfo}-{player.Name}", $"{item.Name}")
| Some event , false ->
let time = Messaging.getShortTimeText (TimeSpan.FromMinutes(int event.Cooldown)) event.Timestamp
DiscordButtonComponent(btnColor, $"{actionId}-{item.Id}", $"{item.Name} ({time} left)", true))
|> Seq.cast<DiscordComponent>
let pickDefense actionId player isTrainer =
let shieldItems =
player.Inventory
|> Inventory.getItemsByType ItemType.Shield
|> List.sortBy (fun item -> item.Id)
let buttons = constructButtons actionId (string player.DiscordId) player shieldItems isTrainer
let embed =
DiscordEmbedBuilder()
.WithTitle("Shield Defense")
.WithDescription("Pick a shield to protect yourself from hacks")
for shield in Inventory.getShields player.Inventory do
let hours = TimeSpan.FromMinutes(int shield.Cooldown).TotalHours |> int
let against = WeaponClass.getGoodAgainst(shield.Class) |> snd
embed.AddField(shield.Item.Name, $"Active {hours} hours\nDefeats {against}", true) |> ignore
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(shieldGif).Build() ; embed.Build() ])
.AsEphemeral(true)
let pickHack actionId attacker defender isTrainer =
let hackItems =
attacker.Inventory
|> Inventory.getItemsByType ItemType.Hack
|> List.sortBy (fun item -> item.Id)
let buttons = constructButtons actionId $"{defender.DiscordId}-{defender.Name}" attacker hackItems isTrainer
let stealMsg = if not isTrainer then $"{defender.Name} has **{defender.Bank} $GBT** we can take from them. " else ""
let embed =
DiscordEmbedBuilder()
.WithTitle("Hack Attack")
.WithDescription($"{stealMsg}Pick the hack you want to use.")
if not isTrainer then
for hack in Inventory.getHacks attacker.Inventory do
let amount = if hack.Power > int defender.Bank then int defender.Bank else hack.Power
embed.AddField(hack.Item.Name, $"Cooldown {hack.Cooldown} mins\nExtract {amount} $GBT", true) |> ignore
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbeds([ DiscordEmbedBuilder().WithImageUrl(hackGif).Build() ; embed.Build() ])
.AsEphemeral true
let responseSuccessfulHack earnedMoney (targetId : uint64) amountTaken (hack : HackItem) =
let embed =
DiscordEmbedBuilder()
.WithImageUrl(getItemGif hack.Item.Id)
.WithTitle("Hack Attack")
.WithDescription($"You successfully hacked <@{targetId}> using {hack.Item.Name}"
+ (if earnedMoney then $", and took {amountTaken} 💰$GBT from them!" else "!"))
DiscordFollowupMessageBuilder()
.AddEmbed(embed.Build())
.AsEphemeral(true)
let responseCreatedShield (shield : ShieldItem) =
let embed = DiscordEmbedBuilder().WithImageUrl(getItemGif shield.Item.Id)
embed.Title <- "Mounted Shield"
embed.Description <- $"Mounted {shield.Item.Name} shield for {TimeSpan.FromMinutes(int shield.Cooldown).TotalHours} hours"
DiscordFollowupMessageBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
let eventSuccessfulHack (ctx : IDiscordContext) target prize =
DiscordMessageBuilder()
.WithContent($"{ctx.GetDiscordMember().Username} successfully hacked <@{target.DiscordId}> and took {prize} GoodBoyTokenz")
let getArsenalEmbed (player : PlayerData) =
DiscordFollowupMessageBuilder()
.AsEphemeral(true)
.AddEmbed(
DiscordEmbedBuilder()
.AddField( "Arsenal", Arsenal.statusFormat player ))
let getAchievementEmbed rewards description achievement =
let embed = DiscordEmbedBuilder()
GuildEnvironment.botClientHacker
|> Option.iter (fun bot ->
embed.Author <- DiscordEmbedBuilder.EmbedAuthor()
embed.Author.Name <- bot.CurrentUser.Username
embed.Author.IconUrl <- bot.CurrentUser.AvatarUrl)
DiscordFollowupMessageBuilder()
.AddEmbed(
embed.WithTitle("Achievement Unlocked!")
.WithDescription(description)
.WithColor(DiscordColor.Gold)
// .AddField("Achievement", $"🏆 {achievement}")
.AddField("Achievement", $"{achievement}", true)
.AddField("Gifts", rewards |> String.concat "\n", true)
// TODO: Once we add another achievement, fix this
.WithImageUrl("https://s10.gifyu.com/images/MasterTraining_Degenz.gif"))
.AsEphemeral(true)