85 lines
3.4 KiB
Forth
85 lines
3.4 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://s8.gifyu.com/images/whitelist-banner-smaller2.gif"
|
|
embed.Title <- "Degenz Game Whitelist"
|
|
embed.Color <- DiscordColor.White
|
|
embed.Description <- $"""
|
|
You need to **BUY** Whitelist with 💰 $GBT...
|
|
|
|
**__To Earn $GBT:__**
|
|
1️⃣ Recruit Degenz in <#{GuildEnvironment.channelRecruitment}>
|
|
2️⃣ Chat to level up in the <#{GuildEnvironment.channelGeneral}>
|
|
3️⃣ Complete fun quests inside <#{GuildEnvironment.channelQuests}>
|
|
"""
|
|
builder.AddEmbed embed |> ignore
|
|
let btn1 = DiscordButtonComponent(ButtonStyle.Success, $"GimmeWhitelist", $"Buy Whitelist") :> DiscordComponent
|
|
builder.AddComponents [| btn1 |] |> 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 isOg (ctx : IDiscordContext) =
|
|
task {
|
|
let roleId = if isOg then GuildEnvironment.roleWhiteOGPending else GuildEnvironment.roleWhitelistPending
|
|
let role = ctx.GetGuild().GetRole(roleId)
|
|
let user = ctx.GetDiscordMember()
|
|
do! user.GrantRoleAsync(role)
|
|
} :> Task
|
|
|
|
let handleButtonEvent _ (event : ComponentInteractionCreateEventArgs) =
|
|
let ctx = DiscordEventContext event :> IDiscordContext
|
|
match event.Id with
|
|
| id when id.StartsWith("GimmeWhitelist") -> Store.buy "WHITELIST" None ctx
|
|
| id when id.StartsWith("Buy") ->
|
|
task {
|
|
let id = ctx.GetInteractionId()
|
|
let itemId = id.Split("-").[1]
|
|
let dispatch ctx = grantWhitelistRole (itemId = "WHITEOG") ctx
|
|
|
|
do! Store.handleBuyItem dispatch ctx itemId
|
|
} :> Task
|
|
| id when id.StartsWith("CreateGuildInvite") -> InviteTracker.handleCreateInvite ctx
|
|
| id when id.StartsWith("ShowRecruited") -> InviteTracker.getInvitedUsersForId (ctx.GetDiscordMember()) ctx
|
|
| id when id.StartsWith("WalletStatus") -> InviteTracker.showWalletStatus 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
|