discord-bot-game/Bot/Embeds.fs
2022-02-27 15:12:30 +07:00

192 lines
8.6 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 ignoreCooldown =
items
|> List.map (fun item ->
let action =
player.Events
|> Array.tryFind (fun i ->
match i.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 |> Player.getShieldItems
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 (item,sClass,cooldown) in Player.getShields player do
let hours = TimeSpan.FromMinutes(int cooldown).TotalHours
let against = WeaponClass.getGoodAgainst(sClass) |> snd
embed.AddField(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 |> Player.getHackItems
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 (item,power,hClass,cooldown) in Player.getHacks attacker do
let amount = if power > int defender.Bank then int defender.Bank else power
embed.AddField(item.Name, $"Cooldown {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 : Item) =
let embed =
DiscordEmbedBuilder()
.WithImageUrl(getItemGif hack.Id)
.WithTitle("Hack Attack")
.WithDescription($"You successfully hacked <@{targetId}> using {hack.Name}"
+ (if earnedMoney then $", and took {amountTaken} 💰$GBT from them!" else "!"))
DiscordFollowupMessageBuilder()
.AddEmbed(embed.Build())
.AsEphemeral(true)
let responseCreatedShield ((item,_,cooldown) : ShieldItem) =
let embed = DiscordEmbedBuilder().WithImageUrl(getItemGif item.Id)
embed.Title <- "Mounted Shield"
embed.Description <- $"Mounted {item.Name} shield for {TimeSpan.FromMinutes(int cooldown).Hours} 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 getBuyItemsEmbed (playerInventory : Inventory) (storeInventory : Inventory) =
let embeds , buttons =
storeInventory
|> List.map (fun item ->
let embed = DiscordEmbedBuilder()
match item.Type with
| Hack(power,_,cooldown) ->
embed.AddField($"$GBT Reward |", string power, true)
.AddField("Cooldown |", $"{TimeSpan.FromMinutes(int cooldown).Minutes} minutes", true)
.WithThumbnail(getItemIcon item.Id)
|> ignore
| Shield(shieldClass,cooldown) ->
embed.AddField($"Strong against |", WeaponClass.getGoodAgainst shieldClass |> snd |> string, true)
// .AddField($"Defensive Strength |", string item.Power, true)
.AddField("Active For |", $"{TimeSpan.FromMinutes(int cooldown).Hours} hours", true)
.WithThumbnail(getItemIcon item.Id)
|> ignore
| _ -> ()
embed
.AddField("Price 💰", (if item.Price = 0<GBT> then "Free" else $"{item.Price} $GBT"), true)
.WithColor(WeaponClass.getClassEmbedColor item)
.WithTitle($"{item.Name}")
|> ignore
let button =
if playerInventory |> List.exists (fun i -> i.Id = item.Id)
then DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Own {item.Name}", true)
else DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Buy-{item.Id}", $"Buy {item.Name}")
( embed.Build() , button :> DiscordComponent ))
|> List.unzip
DiscordFollowupMessageBuilder()
.AddEmbeds(embeds)
.AddComponents(buttons)
.AsEphemeral(true)
let getSellEmbed (items : Item list) =
let embeds , buttons =
items
|> List.map (fun item ->
DiscordEmbedBuilder()
.AddField("Sell For 💰", $"{item.Price} $GBT", true)
.WithTitle($"{item.Name}")
.WithColor(WeaponClass.getClassEmbedColor item)
.Build()
, DiscordButtonComponent(WeaponClass.getClassButtonColor item, $"Sell-{id}", $"Sell {item.Name}") :> DiscordComponent)
|> List.unzip
DiscordFollowupMessageBuilder()
.AddEmbeds(embeds)
.AddComponents(buttons)
.AsEphemeral(true)
let getArsenalEmbed (player : PlayerData) =
DiscordFollowupMessageBuilder()
.AsEphemeral(true)
.AddEmbed(
DiscordEmbedBuilder()
.AddField( "Arsenal", Arsenal.statusFormat player ))
let getAchievementEmbed rewards 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(
embed.WithTitle("Achievement Unlocked!")
.WithDescription(description)
.WithColor(DiscordColor.Gold)
// .AddField("Achievement", $"🏆 {achievement}")
.AddField("Achievement", $"{achievement}", true)
.AddField("Rewards", rewards |> String.concat "\n", true)
// TODO: Once we add another achievement, fix this
.WithImageUrl("https://s10.gifyu.com/images/MasterTraining_Degenz.gif"))
.AsEphemeral(true)