Several improvements to invite and whitelist

This commit is contained in:
Joseph Ferano 2022-03-25 13:47:47 +07:00
parent a8ab4a6abd
commit 58ac186a0a

View File

@ -166,12 +166,10 @@ let private getInvitedUsers userId =
|> Sql.executeAsync (fun read -> read.string "discord_id" |> uint64) |> Sql.executeAsync (fun read -> read.string "discord_id" |> uint64)
|> Async.AwaitTask |> Async.AwaitTask
let private createGuildInvite (ctx : IDiscordContext) showWhitelistReward = let guildInviteEmbed showWhitelistReward =
task {
let invitesRequired = 5
let rewardMsg = let rewardMsg =
if showWhitelistReward then if showWhitelistReward then
$"**⏀ | Your Mission:**\nUse the link to **recruit** {invitesRequired} Degenz into Beautopia©.\n\n" + $"**⏀ | Your Mission:**\nUse the link to **recruit** Degenz into Beautopia©.\n\n" +
$"**⌼ | Your Reward:**\nGet awarded **Whitelist**." $"**⌼ | Your Reward:**\nGet awarded **Whitelist**."
else else
$"**⏀ | Your Mission:**\nUse the link to share it with Degenz you want to `/recruit`.\n\n" + $"**⏀ | Your Mission:**\nUse the link to share it with Degenz you want to `/recruit`.\n\n" +
@ -183,14 +181,27 @@ let private createGuildInvite (ctx : IDiscordContext) showWhitelistReward =
.WithTitle("Recruitment") .WithTitle("Recruitment")
let builder = let builder =
DiscordInteractionResponseBuilder() DiscordFollowupMessageBuilder()
.AddEmbed(embed) .AddEmbed(embed)
.AsEphemeral(true) .AsEphemeral(true)
let button = DiscordButtonComponent(ButtonStyle.Success, $"CreateGuildInvite", $"Give it to me") :> DiscordComponent let button = DiscordButtonComponent(ButtonStyle.Success, $"CreateGuildInvite", $"Give it to me") :> DiscordComponent
builder.AddComponents [| button |] |> ignore builder.AddComponents [| button |]
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, builder)
let private showInviteMessage (ctx : IDiscordContext) showWhitelistReward =
task {
let builder = DiscordInteractionResponseBuilder().AsEphemeral(true)
do! ctx.Respond(InteractionResponseType.DeferredChannelMessageWithSource, builder)
match! DbService.tryFindPlayer (ctx.GetDiscordMember().Id) with
| Some player ->
let ( result , hackerRole ) = ctx.GetGuild().Roles.TryGetValue(GuildEnvironment.roleHacker)
match player.Active , result && Seq.contains hackerRole (ctx.GetDiscordMember().Roles) with
| true , true -> do! ctx.FollowUp(guildInviteEmbed showWhitelistReward)
| false , _ -> do! sendFollowUpMessage ctx $"You're not in the game! Go to <#{GuildEnvironment.channelShelters}> NOW to get assigned a private bunk, and **JOIN THE GAME!**"
| _ , false -> do! sendFollowUpMessage ctx $"You still haven't completed training! Go to <#{GuildEnvironment.channelTraining}> NOW to become a **HACKER**!"
| None ->
do! sendFollowUpMessage ctx $"You're not in the game! Go to <#{GuildEnvironment.channelShelters}> NOW to get assigned a private bunk, and **JOIN THE GAME!**"
} :> Task } :> Task
let private listServerInvites (ctx : IDiscordContext) = task { let private listServerInvites (ctx : IDiscordContext) = task {
@ -330,10 +341,9 @@ let tryGrantWhitelist (ctx : IDiscordContext) =
match! DbService.tryFindPlayer user.Id with match! DbService.tryFindPlayer user.Id with
| Some player -> | Some player ->
let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist) let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)
if player.Active then
if Seq.contains role user.Roles then if Seq.contains role user.Roles then
return AlreadyWhitelisted return AlreadyWhitelisted
else elif player.Active then
if int player.Bank >= WhitelistPrice then if int player.Bank >= WhitelistPrice then
return Granted player return Granted player
else else
@ -365,6 +375,7 @@ Go to <#{GuildEnvironment.channelShelters}> NOW to get assigned a private bunk,
Come hang with all the other VIP Degenz in the <#{GuildEnvironment.channelElite}> Come hang with all the other VIP Degenz in the <#{GuildEnvironment.channelElite}>
""" """
| NotEnoughGBT total -> | NotEnoughGBT total ->
builder.AddComponents([ DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now", true) :> DiscordComponent ]) |> ignore
builder.Content <- $""" builder.Content <- $"""
You don't have enough **$GBT** to buy a WHITELIST spot! You don't have enough **$GBT** to buy a WHITELIST spot!
@ -381,8 +392,7 @@ Go earn more $GBT, and come back when you have `{WhitelistPrice} $GBT`!
Good luck Degen Good luck Degen
""" """
| Granted _ -> | Granted _ ->
let button = DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now") :> DiscordComponent builder.AddComponents([ DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now") :> DiscordComponent ]) |> ignore
builder.AddComponents([ button ]) |> ignore
builder.Content <- """ builder.Content <- """
Look at you Degen, you played Big Brothers games and made it out alive! Look at you Degen, you played Big Brothers games and made it out alive!
@ -479,7 +489,7 @@ type Inviter() =
[<SlashCommand("recruit", "Recruit another user to this discord and earn rewards")>] [<SlashCommand("recruit", "Recruit another user to this discord and earn rewards")>]
member this.CreateInvite (ctx : InteractionContext) = member this.CreateInvite (ctx : InteractionContext) =
createGuildInvite (DiscordInteractionContext ctx) false showInviteMessage (DiscordInteractionContext ctx) false
[<SlashCommand("recruited", "Get total invites from a specific user")>] [<SlashCommand("recruited", "Get total invites from a specific user")>]
member this.ListInvitedPeople (ctx : InteractionContext) = member this.ListInvitedPeople (ctx : InteractionContext) =