From 58ac186a0aba13935c853d2f7b3fcab13b2effdf Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Fri, 25 Mar 2022 13:47:47 +0700 Subject: [PATCH] Several improvements to invite and whitelist --- Bot/InviteTracker.fs | 76 +++++++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/Bot/InviteTracker.fs b/Bot/InviteTracker.fs index 8fb8adc..0840164 100644 --- a/Bot/InviteTracker.fs +++ b/Bot/InviteTracker.fs @@ -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 Brother’s games and made it out alive! @@ -479,7 +489,7 @@ type Inviter() = [] member this.CreateInvite (ctx : InteractionContext) = - createGuildInvite (DiscordInteractionContext ctx) false + showInviteMessage (DiscordInteractionContext ctx) false [] member this.ListInvitedPeople (ctx : InteractionContext) =