116 lines
3.7 KiB
Forth
116 lines
3.7 KiB
Forth
|
|
open System.Threading.Tasks
|
|
open DegenzGame.DbService
|
|
open DSharpPlus
|
|
open DSharpPlus.SlashCommands
|
|
open DegenzGame.Shared
|
|
|
|
module Commands =
|
|
let newPlayer nickname (membr : uint64) =
|
|
let h1 = [| Weapon.Virus ; Weapon.Ransom |]
|
|
let h2 = [| Weapon.DDos ; Weapon.Worm |]
|
|
let h3 = [| Weapon.Crack ; Weapon.Injection |]
|
|
let d1 = [| Shield.Firewall ; Shield.PortScan |]
|
|
let d2 = [| Shield.Encryption ; Shield.Cypher |]
|
|
let d3 = [| Shield.Hardening ; Shield.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
|
|
Name = nickname
|
|
Weapons = weapons
|
|
Shields = shields
|
|
Attacks = [||]
|
|
Defenses = [||]
|
|
Bank = 0f }
|
|
|
|
let addHackerRole (ctx : InteractionContext) =
|
|
async {
|
|
let! player = tryFindPlayer ctx.Member.Id
|
|
let! newPlayer =
|
|
match player with
|
|
| Some _ -> async.Return false
|
|
| None ->
|
|
async {
|
|
do! newPlayer ctx.Member.Username ctx.Member.Id
|
|
|> insertNewPlayer
|
|
|
|
for role in ctx.Guild.Roles do
|
|
if role.Value.Name = "Hacker" then
|
|
do! ctx.Member.GrantRoleAsync(role.Value)
|
|
|> Async.AwaitTask
|
|
|
|
return true
|
|
}
|
|
|
|
if newPlayer then
|
|
do! ctx.CreateResponseAsync("You are now an elite haxxor", true)
|
|
|> Async.AwaitTask
|
|
else
|
|
do! ctx.CreateResponseAsync("Already registered as an elite haxxor", true)
|
|
|> Async.AwaitTask
|
|
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
let removeHackerRole (ctx : InteractionContext) =
|
|
async {
|
|
for role in ctx.Member.Roles do
|
|
if role.Name = "Hacker" then
|
|
do! ctx.Member.RevokeRoleAsync(role)
|
|
|> Async.AwaitTask
|
|
|
|
do! removePlayer ctx.Member.Id
|
|
|
|
do! ctx.CreateResponseAsync("You are now lame", true)
|
|
|> Async.AwaitTask
|
|
} |> Async.StartAsTask
|
|
:> Task
|
|
|
|
|
|
type EmptyGlobalCommandToAvoidFamousDuplicateSlashCommandsBug() = inherit ApplicationCommandModule ()
|
|
|
|
type PlayerRegistration() =
|
|
inherit ApplicationCommandModule ()
|
|
|
|
[<SlashCommand("redpill", "Take the redpill and become a hacker")>]
|
|
member _.AddHackerRole (ctx : InteractionContext) = Commands.addHackerRole ctx
|
|
|
|
[<SlashCommand("bluepill", "Take the bluepill and become lame")>]
|
|
member _.RemoveHackerRole (ctx : InteractionContext) = Commands.removeHackerRole ctx
|
|
|
|
|
|
let config = DiscordConfiguration()
|
|
config.Token <- "OTIyNDIyMDIyMTI1MDEwOTU1.YcBOcw.JxfW1CSIwEO7j6RbRFCnPZ-HoTk"
|
|
config.TokenType <- TokenType.Bot
|
|
config.Intents <- DiscordIntents.All
|
|
//config.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
|
|
|
let client = new DiscordClient(config)
|
|
|
|
//client.add_ComponentInteractionCreated(AsyncEventHandler(handleButtonEvent))
|
|
|
|
let slash = client.UseSlashCommands()
|
|
|
|
// My server
|
|
slash.RegisterCommands<PlayerRegistration>(922419263275425832uL);
|
|
// Degenz
|
|
//slash.RegisterCommands<HackerGame>(922414052708327494uL);
|
|
|
|
client.ConnectAsync ()
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|
|
Task.Delay(-1)
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|
|
client.DisconnectAsync ()
|
|
|> Async.AwaitTask
|
|
|> Async.RunSynchronously
|
|
|