discord-bot-game/Bot/Embeds.fs

188 lines
8.2 KiB
Forth

module Degenz.Embeds
open System
open DSharpPlus.EventArgs
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 getHackIcon = function
| HackId.Virus -> "https://s10.gifyu.com/images/Virus-icon.jpg"
| HackId.RemoteAccess -> "https://s10.gifyu.com/images/Mind-Control-Degenz-V2-min.jpg"
| HackId.Worm -> "https://s10.gifyu.com/images/WormBugAttack_Degenz-min.jpg"
| _ -> hackGif
let getShieldIcon = function
| ShieldId.Firewall -> "https://s10.gifyu.com/images/Defense-GIF-1-Degenz-1.jpg"
| ShieldId.Encryption -> "https://s10.gifyu.com/images/Encryption-Degenz-V2-1-min.jpg"
| ShieldId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.jpg"
| _ -> shieldGif
let getHackGif = function
| HackId.Virus -> "https://s10.gifyu.com/images/Attack-DegenZ-1.gif"
| HackId.RemoteAccess -> "https://s10.gifyu.com/images/Mind-Control-Degenz-V2-min.gif"
| HackId.Worm -> "https://s10.gifyu.com/images/WormBugAttack_Degenz-min.gif"
| _ -> hackGif
let getShieldGif = function
| ShieldId.Firewall -> "https://s10.gifyu.com/images/Defense-GIF-1-Degenz-min.gif"
| ShieldId.Encryption -> "https://s10.gifyu.com/images/Encryption-Degenz-V2-1-min.gif"
| ShieldId.Cypher -> "https://s10.gifyu.com/images/Cypher-Smaller.gif"
| _ -> shieldGif
let constructButtons (actionId: string) (buttonInfo : string) (player: PlayerData) itemType isTrainer =
player
|> Player.getItems itemType
|> Array.map (fun item ->
let action =
player.Actions
|> Array.tryFind (fun i -> i.ActionId = item.Id)
match action , isTrainer with
| None , _ | Some _ , true ->
DiscordButtonComponent(Game.getClassButtonColor item.Class, $"{actionId}-{item.Id}-{buttonInfo}", $"{item.Name}")
| Some act , false ->
let c = ((Armory.getItem act.ActionId).Cooldown)
let time = Messaging.getShortTimeText (TimeSpan.FromMinutes(int c)) act.Timestamp
DiscordButtonComponent(Game.getClassButtonColor item.Class, $"{actionId}-{item.Id}", $"{item.Name} ({time} left)", true))
|> Seq.cast<DiscordComponent>
let pickDefense actionId player isTrainer =
let buttons = constructButtons actionId (string player.DiscordId) player ItemType.Shield isTrainer
let embed =
DiscordEmbedBuilder()
.WithTitle("Shields")
.WithDescription("Pick a shield to protect yourself from hacks")
.WithImageUrl(shieldGif)
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbed(embed)
.AsEphemeral(true)
let pickHack actionId attacker defender isTrainer =
let buttons = constructButtons actionId $"{defender.DiscordId}-{defender.Name}" attacker ItemType.Hack isTrainer
let embed =
DiscordEmbedBuilder()
.WithTitle("Hacks")
.WithDescription($"Pick the hack that you want to use against {defender.Name}")
.WithImageUrl(hackGif)
DiscordFollowupMessageBuilder()
.AddComponents(buttons)
.AddEmbed(embed.Build())
.AsEphemeral true
let responseSuccessfulHack earnedMoney (targetId : uint64) (hack : BattleItem) =
let embed = DiscordEmbedBuilder()
embed.ImageUrl <- getHackGif (enum<HackId>(hack.Id))
embed.Title <- "Hack Attack"
embed.Description <- $"You successfully hacked <@{targetId}> using {hack.Name}"
+ (if earnedMoney then $", and stole {Game.HackPrize} 💰$GBT from them!" else "!")
DiscordFollowupMessageBuilder()
.AddEmbed(embed.Build())
.AsEphemeral(true)
let responseCreatedShield (shield : BattleItem) =
let embed = DiscordEmbedBuilder().WithImageUrl(getShieldGif (enum<ShieldId>(shield.Id)))
embed.Title <- "Mounted Shield"
embed.Description <- $"Mounted {shield.Name} shield for {TimeSpan.FromMinutes(int shield.Cooldown).Hours} hours"
DiscordFollowupMessageBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
let eventSuccessfulHack (event : ComponentInteractionCreateEventArgs) target prize =
DiscordMessageBuilder()
.WithContent($"{event.User.Username} successfully hacked <@{target.DiscordId}> for a total of {prize} GoodBoyTokenz")
let getBuyItemsEmbed (player : PlayerData) (itemType : ItemType) (store : BattleItem array) =
let embeds , buttons =
store
|> Array.filter (fun i -> i.Type = itemType)
|> Array.map (fun item ->
let embed = DiscordEmbedBuilder()
match item.Type with
| Hack ->
embed
.AddField($"Weak Against |", Game.getGoodAgainst item.Class |> fst |> string , true)
.AddField("Cooldown |", $"{TimeSpan.FromMinutes(int item.Cooldown).Minutes} minutes", true)
.WithThumbnail(getHackIcon (enum<HackId>(item.Id)))
|> ignore
| Shield ->
embed
.AddField($"Strong Against |", Game.getGoodAgainst item.Class |> snd |> string , true)
.AddField("Active For |", $"{TimeSpan.FromMinutes(int item.Cooldown).Hours} hours", true)
.WithThumbnail(getShieldIcon (enum<ShieldId>(item.Id)))
|> ignore
embed
.AddField("Cost 💰", $"{item.Cost} $GBT", true)
.WithColor(Game.getClassEmbedColor item.Class)
.WithTitle($"{item.Name}")
|> ignore
let button =
if player.Arsenal |> 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}")
embed.Build() , button :> DiscordComponent)
|> Array.unzip
DiscordFollowupMessageBuilder()
.AddEmbeds(embeds)
.AddComponents(buttons)
.AsEphemeral(true)
let getSellItemsEmbed (itemType : ItemType) (player : PlayerData) =
let embeds , buttons =
player.Arsenal
|> Array.filter (fun i -> i.Type = itemType)
|> Array.map (fun item ->
let embed = DiscordEmbedBuilder()
match item.Type with
| Hack -> embed.WithThumbnail(getHackIcon (enum<HackId>(item.Id))) |> ignore
| Shield -> embed.WithThumbnail(getShieldIcon (enum<ShieldId>(item.Id))) |> ignore
embed
.AddField("Sell For 💰", $"{item.Cost} $GBT", true)
.WithColor(Game.getClassEmbedColor item.Class)
.WithTitle($"{item.Name}")
|> ignore
let button = DiscordButtonComponent(Game.getClassButtonColor item.Class, $"Sell-{item.Id}", $"Sell {item.Name}")
embed.Build() , button :> DiscordComponent)
|> Array.unzip
DiscordFollowupMessageBuilder()
.AddEmbeds(embeds)
.AddComponents(buttons)
.AsEphemeral(true)
let getArsenalEmbed (player : PlayerData) =
DiscordFollowupMessageBuilder()
.AsEphemeral(true)
.AddEmbed(
DiscordEmbedBuilder()
.AddField( "Arsenal", Arsenal.statusFormat player ))
let getAchievementEmbed (player : PlayerData) description achievement =
let embed = DiscordEmbedBuilder()
GuildEnvironment.botUserHackerBattle
|> Option.iter (fun bot ->
embed.Author <- DiscordEmbedBuilder.EmbedAuthor()
embed.Author.Name <- bot.Username
embed.Author.IconUrl <- bot.AvatarUrl)
DiscordFollowupMessageBuilder()
.AddEmbed(
// TODO: We can add a Reward field but we'd need to keep track of what the player was awarded
embed.WithTitle("Achievement Unlocked!")
.WithDescription(description)
.WithColor(DiscordColor.Gold)
// .AddField("Achievement", $"🏆 {achievement}")
.AddField("Achievement", $"{achievement}")
// TODO: Once we add another achievement, fix this
.WithImageUrl("https://s10.gifyu.com/images/MasterTraining_Degenz.gif"))
.AsEphemeral(true)