New admin command
This commit is contained in:
parent
ea1faaa9a5
commit
c9551e411f
86
Bot/Admin.fs
86
Bot/Admin.fs
@ -1,5 +1,7 @@
|
|||||||
module Degenz.Admin
|
module Degenz.Admin
|
||||||
|
|
||||||
|
open System
|
||||||
|
open System.IO
|
||||||
open System.Threading.Tasks
|
open System.Threading.Tasks
|
||||||
open DSharpPlus
|
open DSharpPlus
|
||||||
open DSharpPlus.Entities
|
open DSharpPlus.Entities
|
||||||
@ -7,6 +9,7 @@ open DSharpPlus.EventArgs
|
|||||||
open DSharpPlus.SlashCommands
|
open DSharpPlus.SlashCommands
|
||||||
open DSharpPlus.SlashCommands.Attributes
|
open DSharpPlus.SlashCommands.Attributes
|
||||||
open Degenz.Messaging
|
open Degenz.Messaging
|
||||||
|
open Npgsql.FSharp
|
||||||
|
|
||||||
type InitEmbeds =
|
type InitEmbeds =
|
||||||
| Dojo = 0
|
| Dojo = 0
|
||||||
@ -34,6 +37,77 @@ let sendEmbed embed (ctx : IDiscordContext) =
|
|||||||
do! Messaging.sendSimpleResponse ctx "Sent!"
|
do! Messaging.sendSimpleResponse ctx "Sent!"
|
||||||
} :> Task
|
} :> Task
|
||||||
|
|
||||||
|
let getAllReactions (msg : DiscordMessage) =
|
||||||
|
task {
|
||||||
|
let mutable listOfUsers = ResizeArray<DiscordUser>(512)
|
||||||
|
|
||||||
|
for reaction in msg.Reactions do
|
||||||
|
let mutable count = 0
|
||||||
|
for r in 0..reaction.Count / 100 do
|
||||||
|
let rs =
|
||||||
|
if count > 0 then
|
||||||
|
msg.GetReactionsAsync(reaction.Emoji, 100, listOfUsers.[listOfUsers.Count - 1].Id) |> Async.AwaitTask |> Async.RunSynchronously
|
||||||
|
else
|
||||||
|
msg.GetReactionsAsync(reaction.Emoji, 100) |> Async.AwaitTask |> Async.RunSynchronously
|
||||||
|
listOfUsers.AddRange(rs)
|
||||||
|
printfn $"Emoji {reaction.Emoji.Name} - {reaction.Count} - Total users: {rs.Count} - Page {count}"
|
||||||
|
count <- count + 1
|
||||||
|
do! Async.Sleep 2000
|
||||||
|
|
||||||
|
return
|
||||||
|
listOfUsers
|
||||||
|
|> List.ofSeq
|
||||||
|
|> List.map (fun (user : DiscordUser) ->
|
||||||
|
{| Id = user.Id ; FullName = $"{user.Username}#{user.Discriminator}" |})
|
||||||
|
|> List.distinctBy (fun u -> u.Id)
|
||||||
|
|> List.map (fun user -> $"{user.Id},{user.FullName}")
|
||||||
|
|> String.concat "\n"
|
||||||
|
|> (+) "Discord Id Num,Username\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
let getUserInvites userIds =
|
||||||
|
GuildEnvironment.connectionString
|
||||||
|
|> Sql.connect
|
||||||
|
|> Sql.parameters [ "dids" , Sql.stringArray (userIds |> List.toArray) ]
|
||||||
|
|> Sql.query """
|
||||||
|
SELECT usr.display_name, inviter, count(invite_id) AS total_invites FROM invite
|
||||||
|
JOIN invited_user iu ON invite.id = iu.invite_id
|
||||||
|
JOIN "user" usr ON invite.inviter = usr.discord_id
|
||||||
|
WHERE iu.accepted = true AND inviter = ANY (ARRAY[@dids]::char varying[])
|
||||||
|
GROUP BY inviter, usr.display_name
|
||||||
|
ORDER BY total_invites DESC;
|
||||||
|
"""
|
||||||
|
|> Sql.executeAsync (fun read -> {| Username = read.string "display_name" ; DiscordId = read.string "discord_id" |> uint64 ; TotalInvites = read.int "total_invites" |})
|
||||||
|
|> Async.AwaitTask
|
||||||
|
|
||||||
|
|
||||||
|
let getMessageReactions (channel : DiscordChannel) (message : string) (ctx : IDiscordContext) =
|
||||||
|
task {
|
||||||
|
do! Messaging.defer ctx
|
||||||
|
let ( result , mId ) = UInt64.TryParse(message)
|
||||||
|
if result then
|
||||||
|
let! msg = channel.GetMessageAsync(message |> uint64) |> Async.AwaitTask
|
||||||
|
let! reactions = getAllReactions msg
|
||||||
|
let builder = DiscordFollowupMessageBuilder()
|
||||||
|
use ms = new MemoryStream(Text.Encoding.ASCII.GetBytes(reactions)) :> Stream
|
||||||
|
let dict = Collections.Generic.Dictionary()
|
||||||
|
dict.Add("users.csv", ms)
|
||||||
|
builder.AddFiles(dict) |> ignore
|
||||||
|
do! ctx.FollowUp(builder)
|
||||||
|
else
|
||||||
|
do! Messaging.sendSimpleResponse ctx $"The message ID provided was not a valid: {message}"
|
||||||
|
} :> Task
|
||||||
|
|
||||||
|
//let getUserInvitesTable (channel : DiscordChannel) (message : string) (ctx : IDiscordContext) =
|
||||||
|
let getUserInvitesTable (ctx : IDiscordContext) =
|
||||||
|
task {
|
||||||
|
do! Messaging.defer ctx
|
||||||
|
let! invites = getUserInvites [ "90588624566886400" ; "822834227467780136" ]
|
||||||
|
let builder = DiscordFollowupMessageBuilder()
|
||||||
|
builder.Content <- $"%A{invites}"
|
||||||
|
do! ctx.FollowUp(builder)
|
||||||
|
} :> Task
|
||||||
|
|
||||||
type AdminBot() =
|
type AdminBot() =
|
||||||
inherit ApplicationCommandModule ()
|
inherit ApplicationCommandModule ()
|
||||||
|
|
||||||
@ -46,7 +120,7 @@ type AdminBot() =
|
|||||||
|
|
||||||
[<SlashCommand("admin-invites", "Get total invites from a specific user", false)>]
|
[<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) =
|
member this.GetAttributions (ctx : InteractionContext, [<Option("player", "The player you want to check")>] user : DiscordUser) =
|
||||||
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.getInvitedUsersForId)
|
enforceAdmin (DiscordInteractionContext ctx) (InviteTracker.getInvitedUsersForId user)
|
||||||
|
|
||||||
[<SlashCommand("admin-whitelist-stock", "Set whitelist stock", false)>]
|
[<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) =
|
member this.SetStock (ctx : InteractionContext, [<Option("amount", "Set the amount of WL available for purchase")>] amount : int64) =
|
||||||
@ -56,4 +130,14 @@ type AdminBot() =
|
|||||||
member this.SendEmbedToChannel (ctx : InteractionContext, [<Option("embed", "Which embed to send")>] embed : InitEmbeds) =
|
member this.SendEmbedToChannel (ctx : InteractionContext, [<Option("embed", "Which embed to send")>] embed : InitEmbeds) =
|
||||||
enforceAdmin (DiscordInteractionContext ctx) (sendEmbed embed)
|
enforceAdmin (DiscordInteractionContext ctx) (sendEmbed embed)
|
||||||
|
|
||||||
|
[<SlashCommand("admin-get-msg-reactions", "Set whitelist stock", false)>]
|
||||||
|
member this.GetMessageReactions (ctx : InteractionContext,
|
||||||
|
[<Option("channel", "The channel where the message is")>] channel : DiscordChannel,
|
||||||
|
[<Option("message-id", "The ID of the message with all the reactions")>] messageId : string) =
|
||||||
|
enforceAdmin (DiscordInteractionContext ctx) (getMessageReactions channel messageId)
|
||||||
|
|
||||||
|
[<SlashCommand("admin-get-invites-table", "Invites Table", false)>]
|
||||||
|
member this.GetInvitesTable (ctx : InteractionContext) =
|
||||||
|
enforceAdmin (DiscordInteractionContext ctx) getUserInvitesTable
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user