80 lines
3.3 KiB
Forth
80 lines
3.3 KiB
Forth
module Degenz.Whitelist
|
|
|
|
open System.Threading.Tasks
|
|
open DSharpPlus
|
|
open DSharpPlus.Entities
|
|
open DSharpPlus.EventArgs
|
|
open Degenz.Messaging
|
|
|
|
type WhitelistResult =
|
|
| NotInGame
|
|
| NotAHacker
|
|
| NotEnoughGBT of currentAmount : int<GBT>
|
|
| NotEnoughStock
|
|
| Granted of PlayerData
|
|
| AlreadyWhitelisted
|
|
|
|
let sendInitialEmbed (ctx : IDiscordContext) =
|
|
async {
|
|
try
|
|
let channel = ctx.GetGuild().GetChannel(GuildEnvironment.channelWhitelist)
|
|
let builder = DiscordMessageBuilder()
|
|
let embed = DiscordEmbedBuilder()
|
|
embed.ImageUrl <- "https://s1.gifyu.com/images/whitelist-image-2.gif"
|
|
embed.Title <- "Degenz Game"
|
|
embed.Color <- DiscordColor.White
|
|
embed.Description <- """
|
|
Buy your Whitelist Discord Role below. OG's get to mint more NFTs on Mint day.
|
|
"""
|
|
let! wl = DbService.getStoreItemBySymbol "WHITELIST"
|
|
let! wlOG = DbService.getStoreItemBySymbol "WHITEOG"
|
|
embed.AddField("1x Whitelist", $"Price {Inventory.getBuyPrice wl.Item} $GBT") |> ignore
|
|
embed.AddField("1x OG Whitelist", $"Price {Inventory.getBuyPrice wlOG.Item} $GBT") |> ignore
|
|
builder.AddEmbed embed |> ignore
|
|
let btn1 = DiscordButtonComponent(ButtonStyle.Success, $"Buy-WHITELIST-WHITELIST", $"Buy Whitelist") :> DiscordComponent
|
|
let btn2 = DiscordButtonComponent(ButtonStyle.Success, $"Buy-WHITEOG-WHITELIST", $"Buy OG Whitelist") :> DiscordComponent
|
|
builder.AddComponents [| btn1 ; btn2 |] |> ignore
|
|
|
|
do! GuildEnvironment.botClientRecruit.Value.SendMessageAsync(channel, builder)
|
|
|> Async.AwaitTask
|
|
|> Async.Ignore
|
|
with e ->
|
|
printfn $"Error trying to get channel Whitelist\n\n{e.Message}"
|
|
} |> Async.RunSynchronously
|
|
|
|
let grantWhitelistRole (ctx : IDiscordContext) =
|
|
task {
|
|
let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)
|
|
do! ctx.GetDiscordMember().GrantRoleAsync(role)
|
|
} :> Task
|
|
|
|
let handleButtonEvent _ (event : ComponentInteractionCreateEventArgs) =
|
|
let ctx = DiscordEventContext event :> IDiscordContext
|
|
match event.Id with
|
|
| id when id.StartsWith("Buy") ->
|
|
task {
|
|
let id = ctx.GetInteractionId()
|
|
let itemId = id.Split("-").[1]
|
|
do! Store.handleBuyItem ctx itemId
|
|
do! grantWhitelistRole ctx
|
|
} :> Task
|
|
| id when id.StartsWith("CreateGuildInvite") -> InviteTracker.handleCreateInvite ctx
|
|
| id when id.StartsWith("ShowRecruited") -> InviteTracker.getInvitedUsersForId (ctx.GetDiscordMember()) ctx
|
|
| _ ->
|
|
task {
|
|
let builder = DiscordInteractionResponseBuilder()
|
|
builder.IsEphemeral <- true
|
|
builder.Content <- $"Incorrect Action identifier {ctx.GetInteractionId()}"
|
|
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, builder) |> Async.AwaitTask
|
|
}
|
|
|
|
let setCurrentWhitelistStock amount (ctx : IDiscordContext) =
|
|
task {
|
|
do! Messaging.defer ctx
|
|
let! result = DbService.setItemStock amount "WHITELIST"
|
|
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
|