Scan command

This commit is contained in:
Joseph Ferano 2022-04-05 14:09:16 +07:00
parent 152ff8c110
commit 9b5c3ef81e
2 changed files with 43 additions and 1 deletions

View File

@ -237,6 +237,20 @@ let addPlayerEvent (did : uint64) (playerEvent : PlayerEvent) =
|> Sql.executeNonQueryAsync |> Sql.executeNonQueryAsync
|> Async.AwaitTask |> Async.AwaitTask
let getRandomHackablePlayers (did : uint64) =
connStr
|> Sql.connect
|> Sql.parameters [ "did", Sql.string (string did) ]
|> Sql.query """
SELECT discord_id, display_name FROM "user"
JOIN user_achievements_achievement uaa ON "user".id = uaa.user_id
JOIN achievement a ON uaa.achievement_id = a.id AND a.symbol = 'FINISHED_TRAINER'
WHERE "user".in_game = true AND gbt > 20 AND "user".discord_id != @did
ORDER BY random() LIMIT 5
"""
|> Sql.executeAsync (fun read -> {| Id = read.string "discord_id" |> uint64 ; Name = read.string "display_name" |})
|> Async.AwaitTask
let getWhitelistItem () = let getWhitelistItem () =
connStr connStr
|> Sql.connect |> Sql.connect

View File

@ -227,6 +227,30 @@ let handleDefense (ctx : IDiscordContext) =
}) })
}) })
let scan (ctx : IDiscordContext) =
executePlayerAction ctx (fun _ -> async {
let! targets = DbService.getRandomHackablePlayers (ctx.GetDiscordMember().Id)
let sb = StringBuilder()
let mutable count = 0
for t in targets do
count <- count + 1
sb.AppendLine($"{count}.) <@{t.Id}>") |> ignore
let msg =
if targets.Length > 0 then
$"**Targets Connected to the Network:**\n\n These are 5 targets you can attempt to hack right now... let's hope they're not shielded!\n\n{sb}"
else
$"There don't seem to be any targets available right now"
let embed =
DiscordEmbedBuilder()
.WithColor(DiscordColor.Green)
.WithDescription(msg)
let builder =
DiscordFollowupMessageBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
do! ctx.FollowUp(builder) |> Async.AwaitTask
})
let arsenal (ctx : IDiscordContext) = let arsenal (ctx : IDiscordContext) =
executePlayerAction ctx (fun player -> async { executePlayerAction ctx (fun player -> async {
let updatedPlayer = Player.removeExpiredActions player let updatedPlayer = Player.removeExpiredActions player
@ -297,7 +321,11 @@ type HackerGame() =
[<SlashCommand("shield", "Create a passive shield that will protect you for a certain time")>] [<SlashCommand("shield", "Create a passive shield that will protect you for a certain time")>]
member this.ShieldCommand (ctx : InteractionContext) = member this.ShieldCommand (ctx : InteractionContext) =
enforceChannels (DiscordInteractionContext ctx) Trainer.defend defend enforceChannels (DiscordInteractionContext ctx) Trainer. defend
[<SlashCommand("scan", "Find 5 targets connected to the network we can try to hack")>]
member this.ScanCommand (ctx : InteractionContext) =
enforceChannels (DiscordInteractionContext ctx) scan scan
// [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>] // [<SlashCommand("test-autocomplete", "Create a passive defense that will last 24 hours")>]
member this.TestAutoComplete (ctx : InteractionContext) = member this.TestAutoComplete (ctx : InteractionContext) =