Merge branch 'staging'
This commit is contained in:
commit
2404fd42db
24
Bot/Admin.fs
Normal file
24
Bot/Admin.fs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module Degenz.Admin
|
||||||
|
|
||||||
|
open System.Threading.Tasks
|
||||||
|
open DSharpPlus.Entities
|
||||||
|
open DSharpPlus.SlashCommands
|
||||||
|
open Degenz.Messaging
|
||||||
|
|
||||||
|
type AdminBot() =
|
||||||
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
|
let enforceAdmin (ctx : IDiscordContext) (adminFn : IDiscordContext -> Task) =
|
||||||
|
let isAdmin = Seq.exists (fun (role : DiscordRole) -> role.Id = GuildEnvironment.roleAdmin) (ctx.GetDiscordMember().Roles)
|
||||||
|
if isAdmin then
|
||||||
|
adminFn ctx
|
||||||
|
else
|
||||||
|
Messaging.sendSimpleResponse ctx $"You are not admin" |> Async.StartAsTask :> Task
|
||||||
|
|
||||||
|
[<SlashCommand("admin-invites", "Get total invites from a specific user")>]
|
||||||
|
member this.GetAttributions (ctx : InteractionContext, [<Option("player", "The player you want to check")>] user : DiscordUser) =
|
||||||
|
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.getInvitedUsersForId)
|
||||||
|
|
||||||
|
[<SlashCommand("admin-whitelist-stock", "Set whitelist stock")>]
|
||||||
|
member this.SetStock (ctx : InteractionContext, [<Option("amount", "Set the amount of WL available for purchase")>] amount : int64) =
|
||||||
|
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setWhitelistStock (int amount))
|
@ -16,6 +16,7 @@ let hackerBattleConfig = DiscordConfiguration()
|
|||||||
let storeConfig = DiscordConfiguration()
|
let storeConfig = DiscordConfiguration()
|
||||||
let stealConfig = DiscordConfiguration()
|
let stealConfig = DiscordConfiguration()
|
||||||
let inviterConfig = DiscordConfiguration()
|
let inviterConfig = DiscordConfiguration()
|
||||||
|
let adminConfig = DiscordConfiguration()
|
||||||
//let slotMachineConfig = DiscordConfiguration()
|
//let slotMachineConfig = DiscordConfiguration()
|
||||||
//hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
//hackerBattleConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
||||||
//storeConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
//storeConfig.MinimumLogLevel <- Microsoft.Extensions.Logging.LogLevel.Trace
|
||||||
@ -32,16 +33,21 @@ stealConfig.Intents <- DiscordIntents.All
|
|||||||
inviterConfig.TokenType <- TokenType.Bot
|
inviterConfig.TokenType <- TokenType.Bot
|
||||||
inviterConfig.Intents <- DiscordIntents.All
|
inviterConfig.Intents <- DiscordIntents.All
|
||||||
|
|
||||||
|
adminConfig.TokenType <- TokenType.Bot
|
||||||
|
adminConfig.Intents <- DiscordIntents.All
|
||||||
|
|
||||||
hackerBattleConfig.Token <- GuildEnvironment.tokenHackerBattle
|
hackerBattleConfig.Token <- GuildEnvironment.tokenHackerBattle
|
||||||
storeConfig.Token <- GuildEnvironment.tokenStore
|
storeConfig.Token <- GuildEnvironment.tokenStore
|
||||||
stealConfig.Token <- GuildEnvironment.tokenSteal
|
stealConfig.Token <- GuildEnvironment.tokenSteal
|
||||||
inviterConfig.Token <- GuildEnvironment.tokenInviter
|
inviterConfig.Token <- GuildEnvironment.tokenInviter
|
||||||
|
adminConfig.Token <- GuildEnvironment.tokenAdmin
|
||||||
//slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE")
|
//slotMachineConfig.Token <- Environment.GetEnvironmentVariable("BOT_SLOT_MACHINE")
|
||||||
|
|
||||||
let hackerBattleBot = new DiscordClient(hackerBattleConfig)
|
let hackerBattleBot = new DiscordClient(hackerBattleConfig)
|
||||||
let storeBot = new DiscordClient(storeConfig)
|
let storeBot = new DiscordClient(storeConfig)
|
||||||
let stealBot = new DiscordClient(stealConfig)
|
let stealBot = new DiscordClient(stealConfig)
|
||||||
let inviterBot = new DiscordClient(inviterConfig)
|
let inviterBot = new DiscordClient(inviterConfig)
|
||||||
|
let adminBot = new DiscordClient(adminConfig)
|
||||||
//let slotMachineBot = new DiscordClient(slotMachineConfig)
|
//let slotMachineBot = new DiscordClient(slotMachineConfig)
|
||||||
|
|
||||||
//let clients = [| hackerBattleBot ; storeBot ; slotMachineBot |]
|
//let clients = [| hackerBattleBot ; storeBot ; slotMachineBot |]
|
||||||
@ -49,12 +55,14 @@ let hackerCommands = hackerBattleBot.UseSlashCommands()
|
|||||||
let storeCommands = storeBot.UseSlashCommands()
|
let storeCommands = storeBot.UseSlashCommands()
|
||||||
let stealCommands = stealBot.UseSlashCommands()
|
let stealCommands = stealBot.UseSlashCommands()
|
||||||
let inviterCommands = inviterBot.UseSlashCommands()
|
let inviterCommands = inviterBot.UseSlashCommands()
|
||||||
|
let adminCommands = adminBot.UseSlashCommands()
|
||||||
//let sc3 = slotMachineBot.UseSlashCommands()
|
//let sc3 = slotMachineBot.UseSlashCommands()
|
||||||
|
|
||||||
hackerCommands.RegisterCommands<HackerBattle.HackerGame>(guild);
|
hackerCommands.RegisterCommands<HackerBattle.HackerGame>(guild);
|
||||||
storeCommands.RegisterCommands<Store.Store>(guild);
|
storeCommands.RegisterCommands<Store.Store>(guild);
|
||||||
stealCommands.RegisterCommands<Thief.StealGame>(guild);
|
stealCommands.RegisterCommands<Thief.StealGame>(guild);
|
||||||
inviterCommands.RegisterCommands<InviteTracker.Inviter>(guild);
|
inviterCommands.RegisterCommands<InviteTracker.Inviter>(guild);
|
||||||
|
adminCommands.RegisterCommands<Admin.AdminBot>(guild);
|
||||||
//hackerCommands.RegisterCommands<RPSGame>(guild);
|
//hackerCommands.RegisterCommands<RPSGame>(guild);
|
||||||
//sc3.RegisterCommands<SlotMachine>(guild);
|
//sc3.RegisterCommands<SlotMachine>(guild);
|
||||||
|
|
||||||
@ -95,6 +103,7 @@ GuildEnvironment.botUserArmory <- Some storeBot.CurrentUser
|
|||||||
inviterBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
|
inviterBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
|
||||||
GuildEnvironment.botClientRecruit <- Some inviterBot
|
GuildEnvironment.botClientRecruit <- Some inviterBot
|
||||||
|
|
||||||
|
adminBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
|
||||||
//stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
|
//stealBot.ConnectAsync() |> Async.AwaitTask |> Async.RunSynchronously
|
||||||
|
|
||||||
let rec loop areBotsRunning =
|
let rec loop areBotsRunning =
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
<Compile Include="Games\Store.fs" />
|
<Compile Include="Games\Store.fs" />
|
||||||
<Compile Include="Games\Trainer.fs" />
|
<Compile Include="Games\Trainer.fs" />
|
||||||
<Compile Include="Games\HackerBattle.fs" />
|
<Compile Include="Games\HackerBattle.fs" />
|
||||||
|
<Compile Include="Admin.fs" />
|
||||||
<Compile Include="Bot.fs" />
|
<Compile Include="Bot.fs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="..\.paket\Paket.Restore.targets" />
|
<Import Project="..\.paket\Paket.Restore.targets" />
|
||||||
|
@ -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
|
||||||
@ -259,3 +273,18 @@ let updateWhitelistStock () = async {
|
|||||||
return true
|
return true
|
||||||
with _ -> return false
|
with _ -> return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let setWhitelistStock amount = async {
|
||||||
|
try
|
||||||
|
do! connStr
|
||||||
|
|> Sql.connect
|
||||||
|
|> Sql.parameters [ ( "amount" , Sql.int amount ) ]
|
||||||
|
|> Sql.query """
|
||||||
|
UPDATE item SET stock = @amount WHERE symbol = 'WHITELIST'
|
||||||
|
"""
|
||||||
|
|> Sql.executeNonQueryAsync
|
||||||
|
|> Async.AwaitTask
|
||||||
|
|> Async.Ignore
|
||||||
|
return true
|
||||||
|
with _ -> return false
|
||||||
|
}
|
||||||
|
@ -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) =
|
||||||
|
@ -22,6 +22,7 @@ let tokenSteal = getVar "TOKEN_STEAL"
|
|||||||
let tokenHackerBattle = getVar "TOKEN_HACKER_BATTLE"
|
let tokenHackerBattle = getVar "TOKEN_HACKER_BATTLE"
|
||||||
let tokenStore = getVar "TOKEN_STORE"
|
let tokenStore = getVar "TOKEN_STORE"
|
||||||
let tokenInviter = getVar "TOKEN_INVITER"
|
let tokenInviter = getVar "TOKEN_INVITER"
|
||||||
|
let tokenAdmin = getVar "TOKEN_ADMINBOT"
|
||||||
let tokenMixpanel = getVar "TOKEN_MIXPANEL"
|
let tokenMixpanel = getVar "TOKEN_MIXPANEL"
|
||||||
let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE"
|
let channelEventsHackerBattle = getId "CHANNEL_EVENTS_HACKER_BATTLE"
|
||||||
let channelTraining = getId "CHANNEL_TRAINING"
|
let channelTraining = getId "CHANNEL_TRAINING"
|
||||||
@ -44,6 +45,7 @@ let roleTrainee = getId "ROLE_TRAINEE"
|
|||||||
let roleHacker = getId "ROLE_HACKER"
|
let roleHacker = getId "ROLE_HACKER"
|
||||||
let rolePrisoner = getId "ROLE_PRISONER"
|
let rolePrisoner = getId "ROLE_PRISONER"
|
||||||
let roleWhitelist = getId "ROLE_WHITELIST"
|
let roleWhitelist = getId "ROLE_WHITELIST"
|
||||||
|
let roleAdmin = getId "ROLE_ADMIN"
|
||||||
|
|
||||||
let mutable botUserHackerBattle : DiscordUser option = None
|
let mutable botUserHackerBattle : DiscordUser option = None
|
||||||
let mutable botUserArmory : DiscordUser option = None
|
let mutable botUserArmory : DiscordUser option = None
|
||||||
|
@ -153,7 +153,7 @@ let private getInviteAttributions userId =
|
|||||||
|> Sql.executeRowAsync (fun read -> read.int "count")
|
|> Sql.executeRowAsync (fun read -> read.int "count")
|
||||||
|> Async.AwaitTask
|
|> Async.AwaitTask
|
||||||
|
|
||||||
let private getInvitedUsers userId =
|
let getInvitedUsers userId =
|
||||||
connStr
|
connStr
|
||||||
|> Sql.connect
|
|> Sql.connect
|
||||||
|> Sql.parameters [ "did" , Sql.string (string userId) ]
|
|> Sql.parameters [ "did" , Sql.string (string userId) ]
|
||||||
@ -232,37 +232,39 @@ let private listServerInvites (ctx : IDiscordContext) = task {
|
|||||||
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, msg)
|
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
let private getAttributions (ctx : IDiscordContext) userId = task {
|
let getAttributions userId (ctx : IDiscordContext) =
|
||||||
let! total = getInviteAttributions(userId)
|
task {
|
||||||
let msg =
|
let! total = getInviteAttributions(userId)
|
||||||
DiscordInteractionResponseBuilder()
|
let msg =
|
||||||
.AsEphemeral(true)
|
DiscordInteractionResponseBuilder()
|
||||||
.WithContent($"<@{userId}> has invited {total} people")
|
.AsEphemeral(true)
|
||||||
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, msg)
|
.WithContent($"<@{userId}> has invited {total} people")
|
||||||
}
|
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, msg)
|
||||||
|
} :> Task
|
||||||
|
|
||||||
let private getInvitedUsersForId (ctx : IDiscordContext) = task {
|
let getInvitedUsersForId (ctx : IDiscordContext) =
|
||||||
let! users = getInvitedUsers (ctx.GetDiscordMember().Id)
|
task {
|
||||||
let! total = getInvitedUserCount (ctx.GetDiscordMember().Id)
|
do! Messaging.defer ctx
|
||||||
let sb = StringBuilder()
|
let! users = getInvitedUsers (ctx.GetDiscordMember().Id)
|
||||||
let mutable count = 0
|
let! total = getInvitedUserCount (ctx.GetDiscordMember().Id)
|
||||||
for user in users do
|
let sb = StringBuilder()
|
||||||
count <- count + 1
|
let mutable count = 0
|
||||||
sb.AppendLine($"{count}.) <@{user}>") |> ignore
|
for user in users do
|
||||||
let msg =
|
count <- count + 1
|
||||||
let str =
|
sb.AppendLine($"{count}.) <@{user}>") |> ignore
|
||||||
if users.Length > 0 then
|
let msg =
|
||||||
$"**Total Recruited:** `{total} Degenz`\n**Total Earned:** `{total * InviteRewardAmount} 💰$GBT`\n\n**Last 10 users recruited:**\n{sb}"
|
let str =
|
||||||
else
|
if users.Length > 0 then
|
||||||
$"You haven't recruited anyone yet, use the `/recruit` command to get the recruitment link"
|
$"**Total Recruited:** `{total} Degenz`\n**Total Earned:** `{total * InviteRewardAmount} 💰$GBT`\n\n**Last 10 users recruited:**\n{sb}"
|
||||||
DiscordInteractionResponseBuilder()
|
else
|
||||||
.AsEphemeral(true)
|
$"You haven't recruited anyone yet, use the `/recruit` command to get the recruitment link"
|
||||||
.WithContent(str)
|
DiscordFollowupMessageBuilder()
|
||||||
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, msg)
|
.AsEphemeral(true)
|
||||||
let user = ctx.GetDiscordMember()
|
.WithContent(str)
|
||||||
let channel = ctx.GetChannel()
|
do! ctx.FollowUp(msg)
|
||||||
do! Analytics.recruitedCommand total user.Id user.Username channel
|
let user = ctx.GetDiscordMember()
|
||||||
}
|
do! Analytics.recruitedCommand total user.Id user.Username (ctx.GetChannel())
|
||||||
|
} :> Task
|
||||||
|
|
||||||
let clearInvites (ctx : IDiscordContext) = task {
|
let clearInvites (ctx : IDiscordContext) = task {
|
||||||
let! invites = ctx.GetGuild().GetInvitesAsync()
|
let! invites = ctx.GetGuild().GetInvitesAsync()
|
||||||
@ -581,6 +583,16 @@ let handleGuildMemberAdded _ (eventArgs : GuildMemberAddEventArgs) =
|
|||||||
do! processNewUser eventArgs
|
do! processNewUser eventArgs
|
||||||
} :> Task
|
} :> Task
|
||||||
|
|
||||||
|
let rec setWhitelistStock amount (ctx : IDiscordContext) =
|
||||||
|
task {
|
||||||
|
do! Messaging.defer ctx
|
||||||
|
let! result = DbService.setWhitelistStock amount
|
||||||
|
if result then
|
||||||
|
do! Messaging.sendFollowUpMessage ctx $"Set Whitelist stock to {amount}"
|
||||||
|
else
|
||||||
|
do! Messaging.sendFollowUpMessage ctx $"Error setting WL to {amount}, make sure it's greater than 0"
|
||||||
|
} :> Task
|
||||||
|
|
||||||
type Inviter() =
|
type Inviter() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
@ -596,10 +608,6 @@ type Inviter() =
|
|||||||
member this.ListServerInvites (ctx : InteractionContext) =
|
member this.ListServerInvites (ctx : InteractionContext) =
|
||||||
listServerInvites (DiscordInteractionContext ctx)
|
listServerInvites (DiscordInteractionContext ctx)
|
||||||
|
|
||||||
// [<SlashCommand("invites-attributions", "Get total invites from a specific user")>]
|
|
||||||
member this.getAttributions (ctx : InteractionContext, [<Option("player", "The player you want to check")>] user : DiscordUser) =
|
|
||||||
getAttributions (DiscordInteractionContext ctx) user.Id
|
|
||||||
|
|
||||||
// [<SlashCommand("invites-clear", "Get total invites from a specific user")>]
|
// [<SlashCommand("invites-clear", "Get total invites from a specific user")>]
|
||||||
member this.ClearInvites (ctx : InteractionContext) =
|
member this.ClearInvites (ctx : InteractionContext) =
|
||||||
clearInvites (DiscordInteractionContext ctx)
|
clearInvites (DiscordInteractionContext ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user