discord-bot-game/Bot/Whitelist.fs

114 lines
4.9 KiB
Forth
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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.Azure
embed.Description <- $"""
**__Requirements:__**
You need to BUY Whitelist with 💰 $GBT
You must also have INVITED at least 1 Degen…
**__To Earn $GBT:__**
1️⃣ Invite 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! wallet = InviteTracker.getWalletAddress (ctx.GetDiscordMember().Id)
let roleId =
match isOg , wallet with
| true , Some _ -> GuildEnvironment.roleWhiteOG
| false , Some _ -> GuildEnvironment.roleWhitelist
| true , None -> GuildEnvironment.roleWhiteOGPending
| false , None -> 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") ->
task {
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true).WithContent("Content")
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder) |> Async.AwaitTask
let! invites = InviteTracker.getInvitedUserCount (ctx.GetDiscordMember().Id)
if invites > 0 then
let! playerResult = DbService.tryFindPlayer (ctx.GetDiscordMember().Id)
match playerResult with
| Some player -> do! Store.buyForPlayer "WHITELIST" player None ctx |> Async.StartAsTask
| None -> do! Messaging.sendFollowUpMessage ctx "You are currently not a hacker, first use the /redpill command to become one"
else
let builder = DiscordFollowupMessageBuilder().AsEphemeral(true)
builder.Content <- $"""
**Degen**, cant you **READ**?!
⚠️ **__Requirements:__** 1x Invited User
To BUY Whitelist you must have **__INVITED__** 1 Degen.
☑️ Go to <#{GuildEnvironment.channelRecruitment}>
☑️ Invite just 1 Degen!
"""
do! ctx.FollowUp(builder)
} :> Task
| 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