39 lines
1.9 KiB
Forth
39 lines
1.9 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
|
|
|
|
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
|
|
|
|
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))
|