Reorganizing a little
This commit is contained in:
parent
d4e7170be1
commit
248e8ed64d
77
Joebot.fs
Normal file
77
Joebot.fs
Normal file
@ -0,0 +1,77 @@
|
||||
module Joebot.Commands
|
||||
|
||||
open System
|
||||
open System.Threading.Tasks
|
||||
open DSharpPlus
|
||||
open DSharpPlus.Entities
|
||||
open DSharpPlus.EventArgs
|
||||
open DSharpPlus.SlashCommands
|
||||
open Emzi0767.Utilities
|
||||
open Joebot.Types
|
||||
|
||||
let newPlayer (membr : uint64) =
|
||||
let h1 = [| Virus ; Ransom |]
|
||||
let h2 = [| DDos ; Worm |]
|
||||
let h3 = [| Crack ; Injection |]
|
||||
let d1 = [| Firewall ; PortScan |]
|
||||
let d2 = [| Encryption ; Cypher |]
|
||||
let d3 = [| Hardening ; Sanitation |]
|
||||
|
||||
let rand = System.Random(System.Guid.NewGuid().GetHashCode())
|
||||
let getRandom (actions : 'a array) = actions.[rand.Next(0,2)]
|
||||
|
||||
let weapons = [ getRandom h1 ; getRandom h2 ; getRandom h3 ]
|
||||
let shields = [ getRandom d1 ; getRandom d2 ; getRandom d3 ]
|
||||
|
||||
{ DiscordId = membr
|
||||
Weapons = weapons
|
||||
Shields = shields
|
||||
Attacks = []
|
||||
Defenses = []
|
||||
Bank = 0f }
|
||||
|
||||
let constructButtons (actionType : string) (playerInfo : string) (weapons : 'a list) =
|
||||
weapons
|
||||
|> Seq.map (fun hack ->
|
||||
DiscordButtonComponent(
|
||||
ButtonStyle.Primary,
|
||||
$"{actionType}-{hack}-{playerInfo}",
|
||||
$"{hack}"))
|
||||
|
||||
let createSimpleResponseAsync msg (ctx : InteractionContext) =
|
||||
async {
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
builder.Content <- msg
|
||||
builder.AsEphemeral true |> ignore
|
||||
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||
|> Async.AwaitTask
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
let notYetAHackerMsg = createSimpleResponseAsync "You are not currently a hacker, first use the /redpill command to become one"
|
||||
|
||||
let removeExpiredActions timespan (timestamp : 'a -> DateTime) actions =
|
||||
actions
|
||||
|> List.filter (fun act ->
|
||||
if DateTime.UtcNow - (timestamp act) < timespan
|
||||
then true
|
||||
else false)
|
||||
|
||||
let constructEmbed message =
|
||||
let builder = DiscordEmbedBuilder()
|
||||
builder.Color <- Optional(DiscordColor.PhthaloGreen)
|
||||
builder.Description <- message
|
||||
let author = DiscordEmbedBuilder.EmbedAuthor()
|
||||
author.Name <- "Joebot Pro"
|
||||
author.Url <- "https://twitter.com/degenzgame"
|
||||
author.IconUrl <- "https://pbs.twimg.com/profile_images/1473192843359309825/cqjm0VQ4_400x400.jpg"
|
||||
builder.Author <- author
|
||||
builder.Build()
|
||||
|
||||
let calculateDamage (hack : IClass) (protection : IClass) =
|
||||
let hackClass = hack.GetClass()
|
||||
let protectionClass = protection.GetClass()
|
||||
match hackClass , protectionClass with
|
||||
| h , p when h = p -> Weak
|
||||
| _ -> Strong
|
||||
|
157
Program.fs
157
Program.fs
@ -1,157 +1,17 @@
|
||||
open System
|
||||
module Joebot.Program
|
||||
|
||||
open System
|
||||
open System.Threading.Tasks
|
||||
open DSharpPlus
|
||||
open DSharpPlus.Entities
|
||||
open DSharpPlus.EventArgs
|
||||
open DSharpPlus.SlashCommands
|
||||
open Emzi0767.Utilities
|
||||
|
||||
type ActionClass =
|
||||
| Network
|
||||
| Exploit
|
||||
| Penetration
|
||||
|
||||
type IClass = abstract GetClass : unit -> ActionClass
|
||||
|
||||
type Weapon =
|
||||
| Virus
|
||||
| Ransom
|
||||
| Worm
|
||||
| DDos
|
||||
| Crack
|
||||
| Injection
|
||||
interface IClass with
|
||||
member this.GetClass () =
|
||||
match this with
|
||||
| Virus | Ransom -> Exploit
|
||||
| DDos | Worm -> Network
|
||||
| Crack | Injection -> Penetration
|
||||
static member TryParse weapon =
|
||||
match weapon with
|
||||
| "Virus" -> Some Virus
|
||||
| "Ransom" -> Some Ransom
|
||||
| "Worm" -> Some Worm
|
||||
| "DDos" -> Some DDos
|
||||
| "Crack" -> Some Crack
|
||||
| "Injection" -> Some Injection
|
||||
| _ -> None
|
||||
|
||||
|
||||
|
||||
type Shield =
|
||||
| Firewall
|
||||
| PortScan
|
||||
| Encryption
|
||||
| Cypher
|
||||
| Hardening
|
||||
| Sanitation
|
||||
interface IClass with
|
||||
member this.GetClass () =
|
||||
match this with
|
||||
| Firewall | PortScan -> Exploit
|
||||
| Encryption | Cypher -> Network
|
||||
| Hardening | Sanitation -> Penetration
|
||||
static member TryParse shield =
|
||||
match shield with
|
||||
| "Firewall" -> Some Firewall
|
||||
| "PortScan" -> Some PortScan
|
||||
| "Encryption" -> Some Encryption
|
||||
| "Cypher" -> Some Cypher
|
||||
| "Hardening" -> Some Hardening
|
||||
| "Sanitation" -> Some Sanitation
|
||||
| _ -> None
|
||||
|
||||
type HackResult =
|
||||
| Strong
|
||||
| Weak
|
||||
|
||||
|
||||
type DiscordPlayer = {
|
||||
Id : uint64
|
||||
Name : string
|
||||
}
|
||||
|
||||
type Attack = {
|
||||
HackType : Weapon
|
||||
Target : DiscordPlayer
|
||||
Timestamp : DateTime
|
||||
}
|
||||
|
||||
type Defense = {
|
||||
DefenseType : Shield
|
||||
Timestamp : DateTime
|
||||
}
|
||||
|
||||
type Player = {
|
||||
DiscordId : uint64
|
||||
Weapons : Weapon list
|
||||
Shields : Shield list
|
||||
Attacks : Attack list
|
||||
Defenses : Defense list
|
||||
Bank : single
|
||||
}
|
||||
open Joebot.Types
|
||||
open Joebot.Commands
|
||||
|
||||
let mutable players : Player list = []
|
||||
|
||||
let newPlayer (membr : uint64) =
|
||||
let h1 = [| Virus ; Ransom |]
|
||||
let h2 = [| DDos ; Worm |]
|
||||
let h3 = [| Crack ; Injection |]
|
||||
let d1 = [| Firewall ; PortScan |]
|
||||
let d2 = [| Encryption ; Cypher |]
|
||||
let d3 = [| Hardening ; Sanitation |]
|
||||
|
||||
let rand = System.Random(System.Guid.NewGuid().GetHashCode())
|
||||
let getRandom (actions : 'a array) = actions.[rand.Next(0,2)]
|
||||
|
||||
let weapons = [ getRandom h1 ; getRandom h2 ; getRandom h3 ]
|
||||
let shields = [ getRandom d1 ; getRandom d2 ; getRandom d3 ]
|
||||
|
||||
{ DiscordId = membr
|
||||
Weapons = weapons
|
||||
Shields = shields
|
||||
Attacks = []
|
||||
Defenses = []
|
||||
Bank = 0f }
|
||||
|
||||
let constructButtons (actionType : string) (playerInfo : string) (weapons : 'a list) =
|
||||
weapons
|
||||
|> Seq.map (fun hack ->
|
||||
DiscordButtonComponent(
|
||||
ButtonStyle.Primary,
|
||||
$"{actionType}-{hack}-{playerInfo}",
|
||||
$"{hack}"))
|
||||
|
||||
let createSimpleResponseAsync msg (ctx : InteractionContext) =
|
||||
async {
|
||||
let builder = DiscordInteractionResponseBuilder()
|
||||
builder.Content <- msg
|
||||
builder.AsEphemeral true |> ignore
|
||||
do! ctx.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder)
|
||||
|> Async.AwaitTask
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
let notYetAHackerMsg = createSimpleResponseAsync "You are not currently a hacker, first use the /redpill command to become one"
|
||||
|
||||
let removeExpiredActions timespan (timestamp : 'a -> DateTime) actions =
|
||||
actions
|
||||
|> List.filter (fun act ->
|
||||
if DateTime.UtcNow - (timestamp act) < timespan
|
||||
then true
|
||||
else false)
|
||||
|
||||
let constructEmbed message =
|
||||
let builder = DiscordEmbedBuilder()
|
||||
builder.Color <- Optional(DiscordColor.PhthaloGreen)
|
||||
builder.Description <- message
|
||||
let author = DiscordEmbedBuilder.EmbedAuthor()
|
||||
author.Name <- "Joebot Pro"
|
||||
author.Url <- "https://twitter.com/degenzgame"
|
||||
author.IconUrl <- "https://pbs.twimg.com/profile_images/1473192843359309825/cqjm0VQ4_400x400.jpg"
|
||||
builder.Author <- author
|
||||
builder.Build()
|
||||
|
||||
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
|
||||
|
||||
type JoeBot() =
|
||||
@ -286,12 +146,6 @@ type JoeBot() =
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
let calculateDamage (hack : IClass) (protection : IClass) =
|
||||
let hackClass = hack.GetClass()
|
||||
let protectionClass = protection.GetClass()
|
||||
match hackClass , protectionClass with
|
||||
| h , p when h = p -> Weak
|
||||
| _ -> Strong
|
||||
|
||||
let handleAttack (event : ComponentInteractionCreateEventArgs) =
|
||||
let updatePlayer amount attack p = {
|
||||
@ -415,7 +269,6 @@ let handleButtonEvent (client : DiscordClient) (event : ComponentInteractionCrea
|
||||
}
|
||||
} |> Async.StartAsTask
|
||||
:> Task
|
||||
|
||||
let config = DiscordConfiguration()
|
||||
config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk"
|
||||
config.TokenType <- TokenType.Bot
|
||||
|
90
Types.fs
Normal file
90
Types.fs
Normal file
@ -0,0 +1,90 @@
|
||||
module Joebot.Types
|
||||
|
||||
open System
|
||||
|
||||
type ActionClass =
|
||||
| Network
|
||||
| Exploit
|
||||
| Penetration
|
||||
|
||||
type IClass = abstract GetClass : unit -> ActionClass
|
||||
|
||||
type Weapon =
|
||||
| Virus
|
||||
| Ransom
|
||||
| Worm
|
||||
| DDos
|
||||
| Crack
|
||||
| Injection
|
||||
interface IClass with
|
||||
member this.GetClass () =
|
||||
match this with
|
||||
| Virus | Ransom -> Exploit
|
||||
| DDos | Worm -> Network
|
||||
| Crack | Injection -> Penetration
|
||||
static member TryParse weapon =
|
||||
match weapon with
|
||||
| "Virus" -> Some Virus
|
||||
| "Ransom" -> Some Ransom
|
||||
| "Worm" -> Some Worm
|
||||
| "DDos" -> Some DDos
|
||||
| "Crack" -> Some Crack
|
||||
| "Injection" -> Some Injection
|
||||
| _ -> None
|
||||
|
||||
|
||||
|
||||
type Shield =
|
||||
| Firewall
|
||||
| PortScan
|
||||
| Encryption
|
||||
| Cypher
|
||||
| Hardening
|
||||
| Sanitation
|
||||
interface IClass with
|
||||
member this.GetClass () =
|
||||
match this with
|
||||
| Firewall | PortScan -> Exploit
|
||||
| Encryption | Cypher -> Network
|
||||
| Hardening | Sanitation -> Penetration
|
||||
static member TryParse shield =
|
||||
match shield with
|
||||
| "Firewall" -> Some Firewall
|
||||
| "PortScan" -> Some PortScan
|
||||
| "Encryption" -> Some Encryption
|
||||
| "Cypher" -> Some Cypher
|
||||
| "Hardening" -> Some Hardening
|
||||
| "Sanitation" -> Some Sanitation
|
||||
| _ -> None
|
||||
|
||||
type HackResult =
|
||||
| Strong
|
||||
| Weak
|
||||
|
||||
|
||||
type DiscordPlayer = {
|
||||
Id : uint64
|
||||
Name : string
|
||||
}
|
||||
|
||||
type Attack = {
|
||||
HackType : Weapon
|
||||
Target : DiscordPlayer
|
||||
Timestamp : DateTime
|
||||
}
|
||||
|
||||
type Defense = {
|
||||
DefenseType : Shield
|
||||
Timestamp : DateTime
|
||||
}
|
||||
|
||||
type Player = {
|
||||
DiscordId : uint64
|
||||
Weapons : Weapon list
|
||||
Shields : Shield list
|
||||
Attacks : Attack list
|
||||
Defenses : Defense list
|
||||
Bank : single
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
<RootNamespace>discord_bot</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.fs" />
|
||||
<Content Include="challenge.jpg">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
@ -14,5 +13,10 @@
|
||||
<ItemGroup>
|
||||
<ReferencePathWithRefAssemblies Update="\home\joe\.nuget\packages\dsharpplus.slashcommands\4.2.0-nightly-01054\lib\netstandard2.0\DSharpPlus.SlashCommands.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Types.fs" />
|
||||
<Compile Include="Joebot.fs" />
|
||||
<Compile Include="Program.fs" />
|
||||
</ItemGroup>
|
||||
<Import Project=".paket\Paket.Restore.targets" />
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user