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,31 +166,42 @@ let private getInvitedUsers userId =
|> Sql.executeAsync (fun read -> read.string "discord_id" |> uint64)
|> Async.AwaitTask
let private createGuildInvite (ctx : IDiscordContext) showWhitelistReward =
let guildInviteEmbed showWhitelistReward =
let rewardMsg =
if showWhitelistReward then
$"**⏀ | Your Mission:**\nUse the link to **recruit** Degenz into Beautopia©.\n\n" +
$"**⌼ | Your Reward:**\nGet awarded **Whitelist**."
else
$"**⏀ | Your Mission:**\nUse the link to share it with Degenz you want to `/recruit`.\n\n" +
$"**⌼ | Your Reward:**\n`Earn {InviteRewardAmount} $GBT` 💰 for every Degen you've `/recruited`."
let embed =
DiscordEmbedBuilder()
.WithDescription(rewardMsg)
.WithImageUrl("https://pbs.twimg.com/profile_banners/1449270642340089856/1640071520/1500x500")
.WithTitle("Recruitment")
let builder =
DiscordFollowupMessageBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
let button = DiscordButtonComponent(ButtonStyle.Success, $"CreateGuildInvite", $"Give it to me") :> DiscordComponent
builder.AddComponents [| button |]
let private showInviteMessage (ctx : IDiscordContext) showWhitelistReward =
task {
let invitesRequired = 5
let rewardMsg =
if showWhitelistReward then
$"**⏀ | Your Mission:**\nUse the link to **recruit** {invitesRequired} Degenz into Beautopia©.\n\n" +
$"**⌼ | Your Reward:**\nGet awarded **Whitelist**."
else
$"**⏀ | Your Mission:**\nUse the link to share it with Degenz you want to `/recruit`.\n\n" +
$"**⌼ | Your Reward:**\n`Earn {InviteRewardAmount} $GBT` 💰 for every Degen you've `/recruited`."
let embed =
DiscordEmbedBuilder()
.WithDescription(rewardMsg)
.WithImageUrl("https://pbs.twimg.com/profile_banners/1449270642340089856/1640071520/1500x500")
.WithTitle("Recruitment")
let builder =
DiscordInteractionResponseBuilder()
.AddEmbed(embed)
.AsEphemeral(true)
let button = DiscordButtonComponent(ButtonStyle.Success, $"CreateGuildInvite", $"Give it to me") :> DiscordComponent
builder.AddComponents [| button |] |> ignore
do! ctx.Respond(InteractionResponseType.ChannelMessageWithSource, builder)
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
let private listServerInvites (ctx : IDiscordContext) = task {
@ -330,14 +341,13 @@ let tryGrantWhitelist (ctx : IDiscordContext) =
match! DbService.tryFindPlayer user.Id with
| Some player ->
let role = ctx.GetGuild().GetRole(GuildEnvironment.roleWhitelist)
if player.Active then
if Seq.contains role user.Roles then
return AlreadyWhitelisted
if Seq.contains role user.Roles then
return AlreadyWhitelisted
elif player.Active then
if int player.Bank >= WhitelistPrice then
return Granted player
else
if int player.Bank >= WhitelistPrice then
return Granted player
else
return NotEnoughGBT (int player.Bank)
return NotEnoughGBT (int player.Bank)
else
return NotInGame
| None -> return NotInGame
@ -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}>
"""
| NotEnoughGBT total ->
builder.AddComponents([ DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now", true) :> DiscordComponent ]) |> ignore
builder.Content <- $"""
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
"""
| Granted _ ->
let button = DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now") :> DiscordComponent
builder.AddComponents([ button ]) |> ignore
builder.AddComponents([ DiscordButtonComponent(ButtonStyle.Success, $"BuyWhitelist", $"Buy Now") :> DiscordComponent ]) |> ignore
builder.Content <- """
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")>]
member this.CreateInvite (ctx : InteractionContext) =
createGuildInvite (DiscordInteractionContext ctx) false
showInviteMessage (DiscordInteractionContext ctx) false
[<SlashCommand("recruited", "Get total invites from a specific user")>]
member this.ListInvitedPeople (ctx : InteractionContext) =