Skip to content

Commit

Permalink
refresh supporter commands
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Jan 4, 2025
1 parent 0680e60 commit 3b98b60
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 64 deletions.
75 changes: 21 additions & 54 deletions src/FMBot.Bot/Builders/StaticBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,79 +88,46 @@ public async Task<ResponseModel> DonateAsync(

if (context.ContextUser.UserType == UserType.Supporter || (existingSupporter != null && existingSupporter.Expired != true))
{
response.Embed.WithTitle("Thank you for being a supporter!");
embedDescription.AppendLine("See a list of all your perks below:");
embedDescription.AppendLine("Thank you for being a supporter! See a list of all your perks below:");
}
else
{
response.Embed.WithTitle("Support .fmbot and get supporter");
embedDescription.AppendLine("Support .fmbot and unlock extra perks:");
}

response.Embed.AddField("📈 Get more stats",
"- Your lifetime Last.fm data will be stored for extra stats\n" +
"- See first listen dates, have an expanded profile and advanced recaps\n" +
"- Ability to store your complete Discogs collection");
response.Embed.AddField("📊 More stats, more insights",
"-# Unlock lifetime Last.fm data for deeper analysis. Track first listens, get expanded profiles, expanded commands, your full Discogs collection and more.");

response.Embed.AddField("<:history:1131511469096312914> Import your Spotify and Apple Music history",
"- Use your full Spotify and/or Apple Music listening history together with your Last.fm data\n" +
"- Get the most accurate playcounts and listening time");

response.Embed.AddField("🔥 Expanded judge command",
"- GPT-4o powered compliments and roasts\n" +
"- Increased usage limits and ability to use the command on others");
response.Embed.AddField("<:history:1131511469096312914> Import your history",
"-# Import and use your full Spotify and Apple Music history together with your Last.fm data for the most accurate playcounts, listening time, and insights.");

response.Embed.AddField("<:discoveries:1145740579284713512> Go back in time",
"- View when you discovered artists with the exclusive `discoveries` command\n" +
"- See discovery dates in the `artist`, `album` and `track` commands");
"-# See exactly when you discovered artists, albums, and tracks in commands and the exclusive Discovery command.");

response.Embed.AddField("🎮 Play unlimited games",
"- Remove the daily limit on Jumble and Pixel Jumble and play as much as you want");
"-# Remove the daily limit on Jumble and Pixel Jumble and play as much as you want.");

response.Embed.AddField("⚙️ Customize your commands",
"- Expand your `.fm` footer with extra stats\n" +
"- Add more friends for expanded friend commands\n"+
"- Set your own personal automatic emote reactions");

response.Embed.AddField("⭐ Flex your support",
"- Get a badge in the bot and a role on the [.fmbot server](https://discord.gg/fmbot) with access to sneak peeks\n" +
$"- Higher chance to get featured on Supporter Sundays (next up in {FeaturedService.GetDaysUntilNextSupporterSunday()} {StringExtensions.GetDaysString(FeaturedService.GetDaysUntilNextSupporterSunday())})");
"-# Expand your .fm footer, add more friends, set automatic emoji reactions, and personalize your experience.");

if (existingSupporter != null)
{
var existingSupporterDescription = new StringBuilder();
response.Embed.AddField("🔥 Enhanced judge command",
"-# Get a GPT-4o-powered .judge with higher limits, sharper roasts, and the ability to use it on others.");

var created = DateTime.SpecifyKind(existingSupporter.Created, DateTimeKind.Utc);
var createdValue = ((DateTimeOffset)created).ToUnixTimeSeconds();
existingSupporterDescription.AppendLine($"Activation date: <t:{createdValue}:D>");
response.Embed.AddField("⭐ Exclusive supporter perks",
$"-# Show your support with a badge, gain access to a private [Discord role and channel](https://discord.gg/fmbot), and a higher chance to be featured on Supporter Sunday (next up in {FeaturedService.GetDaysUntilNextSupporterSunday()} {StringExtensions.GetDaysString(FeaturedService.GetDaysUntilNextSupporterSunday())}).");

if (existingSupporter.LastPayment.HasValue)
{
var lastPayment = DateTime.SpecifyKind(existingSupporter.LastPayment.Value, DateTimeKind.Utc);
var lastPaymentValue = ((DateTimeOffset)lastPayment).ToUnixTimeSeconds();
var buttons = new ComponentBuilder();

if (existingSupporter.SubscriptionType != SubscriptionType.Discord)
{
existingSupporterDescription.AppendLine($"Last payment: <t:{lastPaymentValue}:D>");
}
else
{
existingSupporterDescription.AppendLine($"Expiry date: <t:{lastPaymentValue}:D>");
}
}

if (existingSupporter.SubscriptionType.HasValue)
{
existingSupporterDescription.AppendLine($"Subscription type: `{Enum.GetName(existingSupporter.SubscriptionType.Value)}`");
}

existingSupporterDescription.AppendLine($"Name: **{StringExtensions.Sanitize(existingSupporter.Name)}**");

response.Embed.AddField("Your details", existingSupporterDescription.ToString());
if (existingSupporter != null)
{
buttons.WithButton("View current supporter status", style: ButtonStyle.Secondary,
customId: InteractionConstants.SupporterLinks.ManageOverview);
}

response.Embed.WithDescription(embedDescription.ToString());
buttons.WithButton(Constants.GetSupporterButton, style: ButtonStyle.Link,
url: Constants.GetSupporterDiscordLink);

var buttons = new ComponentBuilder().WithButton(Constants.GetSupporterButton, style: ButtonStyle.Link, url: Constants.GetSupporterDiscordLink);
response.Embed.WithDescription(embedDescription.ToString());

response.Components = buttons;

Expand Down
1 change: 1 addition & 0 deletions src/FMBot.Bot/Resources/InteractionConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public static class SupporterLinks
public const string GetPurchaseLink = "supporter-purchase-link";
public const string GetManageLink = "supporter-manage-link";
public const string ViewPerks = "supporter-view-perks";
public const string ManageOverview = "supporter-manage-overview";
}

public const string BotScrobblingEnable = "user-setting-botscrobbling-enable";
Expand Down
140 changes: 130 additions & 10 deletions src/FMBot.Bot/SlashCommands/StaticSlashCommands.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Discord;
Expand All @@ -9,6 +10,7 @@
using FMBot.Bot.Models;
using FMBot.Bot.Resources;
using FMBot.Bot.Services;
using FMBot.Domain.Models;

namespace FMBot.Bot.SlashCommands;

Expand All @@ -21,7 +23,8 @@ public class StaticSlashCommands : InteractionModuleBase
private InteractiveService Interactivity { get; }


public StaticSlashCommands(UserService userService, StaticBuilders staticBuilders, InteractiveService interactivity, SupporterService supporterService)
public StaticSlashCommands(UserService userService, StaticBuilders staticBuilders, InteractiveService interactivity,
SupporterService supporterService)
{
this._userService = userService;
this._staticBuilders = staticBuilders;
Expand All @@ -30,9 +33,10 @@ public StaticSlashCommands(UserService userService, StaticBuilders staticBuilder
}

[SlashCommand("outofsync", "Shows info if your Last.fm isn't up to date with Spotify")]
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel, InteractionContextType.Guild)]
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel,
InteractionContextType.Guild)]
[IntegrationType(ApplicationIntegrationType.UserInstall, ApplicationIntegrationType.GuildInstall)]
public async Task OutOfSyncAsync([Summary("private", "Show info privately?")]bool privateResponse = true)
public async Task OutOfSyncAsync([Summary("private", "Show info privately?")] bool privateResponse = true)
{
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);
var response = StaticBuilders.OutOfSync(new ContextModel(this.Context, contextUser));
Expand All @@ -42,7 +46,8 @@ public async Task OutOfSyncAsync([Summary("private", "Show info privately?")]boo
}

[SlashCommand("getsupporter", "Information about getting supporter or your current subscription")]
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel, InteractionContextType.Guild)]
[CommandContextType(InteractionContextType.BotDm, InteractionContextType.PrivateChannel,
InteractionContextType.Guild)]
[IntegrationType(ApplicationIntegrationType.UserInstall, ApplicationIntegrationType.GuildInstall)]
public async Task GetSupporterAsync()
{
Expand Down Expand Up @@ -80,11 +85,123 @@ public async Task GetSupporterLink(string type)
{
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);

var link = await this._supporterService.GetSupporterCheckoutLink(this.Context.User.Id, contextUser.UserNameLastFM, type);
var link = await this._supporterService.GetSupporterCheckoutLink(this.Context.User.Id,
contextUser.UserNameLastFM, type);

var components = new ComponentBuilder().WithButton($"Get {type} supporter", style: ButtonStyle.Link, url: link, emote: Emoji.Parse("⭐"));
var components = new ComponentBuilder().WithButton($"Get {type} supporter", style: ButtonStyle.Link, url: link,
emote: Emoji.Parse("⭐"));

await RespondAsync($"Click the unique link below to purchase supporter!", ephemeral: true, components: components.Build());
var embed = new EmbedBuilder();
embed.WithColor(DiscordConstants.InformationColorBlue);
var description = new StringBuilder();
description.AppendLine($"**Click the unique link below to purchase supporter!**");
description.AppendLine();

if (SupporterService.IsSupporter(contextUser.UserType))
{
description.AppendLine("⚠️ Note: You currently already have supporter activated on your .fmbot account. ");
}
else
{
description.AppendLine(
"Take your .fmbot experience to the next level with these new features and benefits. Import and use your history, access extra statistics, play unlimited games, support development and much more. Please note that .fmbot is not affiliated with Last.fm.");
}

embed.WithDescription(description.ToString());

await RespondAsync(embed: embed.Build(), ephemeral: true, components: components.Build());
this.Context.LogCommandUsed();
}

[ComponentInteraction($"{InteractionConstants.SupporterLinks.ManageOverview}")]
[UserSessionRequired]
public async Task GetManageOverview()
{
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);
var existingSupporter = await this._supporterService.GetSupporter(contextUser.DiscordUserId);

var embed = new EmbedBuilder();
embed.WithColor(DiscordConstants.InformationColorBlue);
var manageDescription = new StringBuilder();

if (SupporterService.IsSupporter(contextUser.UserType))
{
if (existingSupporter != null)
{
if (existingSupporter.SubscriptionType == SubscriptionType.Discord)
{
manageDescription.AppendLine(
"To manage your subscription, go to your Discord settings and then 'Subscriptions'. At the moment this is only available on Discord desktop and browser, not on mobile. ");
}
else if (existingSupporter.SubscriptionType == SubscriptionType.MonthlyOpenCollective ||
existingSupporter.SubscriptionType == SubscriptionType.YearlyOpenCollective)
{
manageDescription.AppendLine(
"Go to [OpenCollective](https://opencollective.com/) and sign in with the email you used during purchase. After signing in go to 'Manage Contributions' where you can change your subscription.");
}
else if (existingSupporter.SubscriptionType == SubscriptionType.Stripe)
{
manageDescription.AppendLine(
"Todo add stripe stuff");
}
else
{
manageDescription.AppendLine(
"You have lifetime supporter, so there is nothing to manage. Enjoy your supporter!");
}
}
}
else
{
manageDescription.AppendLine(
"You currently don't have an active supporter subscription.");
}

embed.AddField("Managing your subscription", manageDescription.ToString());

if (existingSupporter != null)
{
var existingSupporterDescription = new StringBuilder();

var created = DateTime.SpecifyKind(existingSupporter.Created, DateTimeKind.Utc);
var createdValue = ((DateTimeOffset)created).ToUnixTimeSeconds();
existingSupporterDescription.AppendLine($"Activation date: <t:{createdValue}:D>");

if (existingSupporter.LastPayment.HasValue)
{
var lastPayment = DateTime.SpecifyKind(existingSupporter.LastPayment.Value, DateTimeKind.Utc);
var lastPaymentValue = ((DateTimeOffset)lastPayment).ToUnixTimeSeconds();

if (existingSupporter.SubscriptionType != SubscriptionType.Discord)
{
existingSupporterDescription.AppendLine($"Last payment: <t:{lastPaymentValue}:D>");
}
else
{
existingSupporterDescription.AppendLine($"Expiry date: <t:{lastPaymentValue}:D>");
}
}
else if (existingSupporter.SubscriptionType == SubscriptionType.Discord)
{
existingSupporterDescription.AppendLine($"Expiry date: Unknown.");
}

if (existingSupporter.SubscriptionType.HasValue)
{
existingSupporterDescription.AppendLine(
$"Subscription type: `{Enum.GetName(existingSupporter.SubscriptionType.Value)}`");
}

if (!string.Equals(contextUser.UserNameLastFM, existingSupporter.Name, StringComparison.OrdinalIgnoreCase))
{
existingSupporterDescription.AppendLine(
$"Name: **{StringExtensions.Sanitize(existingSupporter.Name)}**");
}

embed.AddField("Your details", existingSupporterDescription.ToString());
}

await RespondAsync(embed: embed.Build(), ephemeral: true);
this.Context.LogCommandUsed();
}

Expand All @@ -94,11 +211,14 @@ public async Task GetManageLink()
{
var contextUser = await this._userService.GetUserSettingsAsync(this.Context.User);

var link = await this._supporterService.GetSupporterManageLink(this.Context.User.Id, contextUser.UserNameLastFM);
var link = await this._supporterService.GetSupporterManageLink(this.Context.User.Id,
contextUser.UserNameLastFM);

var components = new ComponentBuilder().WithButton("Manage supporter", style: ButtonStyle.Link, url: link, emote: Emoji.Parse("⭐"));
var components = new ComponentBuilder().WithButton("Manage supporter", style: ButtonStyle.Link, url: link,
emote: Emoji.Parse("⭐"));

await RespondAsync("Click the unique link below to manage supporter!", ephemeral: true, components: components.Build());
await RespondAsync("Click the unique link below to manage supporter!", ephemeral: true,
components: components.Build());
this.Context.LogCommandUsed();
}
}

0 comments on commit 3b98b60

Please sign in to comment.