60 lines
2.6 KiB
Forth

module Degenz.Admin
open System.Threading.Tasks
open DSharpPlus
open DSharpPlus.Entities
open DSharpPlus.EventArgs
open DSharpPlus.SlashCommands
open DSharpPlus.SlashCommands.Attributes
open Degenz.Messaging
type InitEmbeds =
| Dojo = 0
| Whitelist = 1
| Slots = 2
let handleGuildDownloadReady (_ : DiscordClient) (event : GuildDownloadCompletedEventArgs) =
task {
let ( _ , guild ) = event.Guilds.TryGetValue(GuildEnvironment.guildId)
let! commands = guild.GetApplicationCommandsAsync()
let ( _ , adminRole ) = guild.Roles.TryGetValue(GuildEnvironment.roleAdmin)
let permission = DiscordApplicationCommandPermission(adminRole, true)
let commands = commands |> Seq.map (fun com -> DiscordGuildApplicationCommandPermissions(com.Id, [ permission ]))
do! guild.BatchEditApplicationCommandPermissionsAsync(commands) |> Async.AwaitTask |> Async.Ignore
} :> Task
let sendEmbed embed (ctx : IDiscordContext) =
task {
match embed with
| InitEmbeds.Dojo -> Trainer.sendInitialEmbed ctx
| InitEmbeds.Whitelist -> InviteTracker.sendInitialEmbed ctx
| InitEmbeds.Slots -> SlotMachine.sendInitialEmbedFromSlashCommand ctx
| _ -> ()
do! Messaging.sendSimpleResponse ctx "Sent!"
} :> Task
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", false)>]
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", false)>]
member this.SetStock (ctx : InteractionContext, [<Option("amount", "Set the amount of WL available for purchase")>] amount : int64) =
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.setWhitelistStock (int amount))
[<SlashCommand("admin-send-embed", "Set whitelist stock", false)>]
member this.SendEmbedToChannel (ctx : InteractionContext, [<Option("embed", "Which embed to send")>] embed : InitEmbeds) =
enforceAdmin (DiscordInteractionContext ctx) (sendEmbed embed)