discord-bot-game/Bot/Whitelist.fs
2022-05-11 22:41:39 +07:00

85 lines
3.5 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://s1.gifyu.com/images/whitelist-image-2.gif"
embed.Title <- "Degenz Game Whitelist"
embed.Color <- DiscordColor.White
embed.Description <- """
In **Beautopia ©** you BUY Whitelist with 💰 $GBT...
__To earn $GBT You Can:__
1️⃣ Recruit other Degenz into the server in #🙋invite
2️⃣ Be helpful & chat in #💬general-chat to level up!
3️⃣ Complete Quests inside #🕹quests
"""
let! wl = DbService.getStoreItemBySymbol "WHITELIST"
let! wlOG = DbService.getStoreItemBySymbol "WHITEOG"
embed.AddField("1x Whitelist", $"Price `{Inventory.getBuyPrice wl.Item} $GBT`", true) |> ignore
embed.AddField("1x OG Whitelist", $"Price `{Inventory.getBuyPrice wlOG.Item} $GBT`", true) |> 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