diff --git a/src/FMBot.Bot/Builders/ImportBuilders.cs b/src/FMBot.Bot/Builders/ImportBuilders.cs index b32d66c3..1cc2997e 100644 --- a/src/FMBot.Bot/Builders/ImportBuilders.cs +++ b/src/FMBot.Bot/Builders/ImportBuilders.cs @@ -1,3 +1,4 @@ +using System; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -7,6 +8,7 @@ using FMBot.Bot.Resources; using FMBot.Bot.Services; using FMBot.Domain; +using FMBot.Domain.Attributes; using FMBot.Domain.Enums; using FMBot.Domain.Models; @@ -223,4 +225,114 @@ public async Task GetImportedYears(int userId, PlaySource playSource) return years.Length > 0 ? years.ToString() : null; } + + public async Task ImportModify(ContextModel context, int userId) + { + var response = new ResponseModel + { + ResponseType = ResponseType.Embed, + }; + + var importSetting = new SelectMenuBuilder() + .WithPlaceholder("Select modification") + .WithCustomId(InteractionConstants.ImportModify) + .WithMinValues(1) + .WithMaxValues(1); + + var allPlays = await this._playService.GetAllUserPlays(userId, false); + var hasImported = allPlays.Any(a => + a.PlaySource == PlaySource.SpotifyImport || a.PlaySource == PlaySource.AppleMusicImport); + + if (!hasImported && context.ContextUser.DataSource == DataSource.LastFm) + { + importSetting.IsDisabled = true; + } + + foreach (var option in ((DataSource[])Enum.GetValues(typeof(DataSource)))) + { + var name = option.GetAttribute().Name; + var description = option.GetAttribute().Description; + var value = Enum.GetName(option); + + var active = context.ContextUser.DataSource == option; + + importSetting.AddOption(new SelectMenuOptionBuilder(name, value, description, isDefault: active)); + } + + response.Components = new ComponentBuilder().WithSelectMenu(importSetting); + + response.Embed.WithAuthor("Modify your .fmbot imports"); + response.Embed.WithColor(DiscordConstants.InformationColorBlue); + + var importSource = "import data"; + if (allPlays.Any(a => a.PlaySource == PlaySource.AppleMusicImport) && + allPlays.Any(a => a.PlaySource == PlaySource.SpotifyImport)) + { + importSource = "Apple Music & Spotify"; + } + else if (allPlays.Any(a => a.PlaySource == PlaySource.AppleMusicImport)) + { + importSource = "Apple Music"; + } + else if (allPlays.Any(a => a.PlaySource == PlaySource.SpotifyImport)) + { + importSource = "Spotify"; + } + + var embedDescription = new StringBuilder(); + + embedDescription.AppendLine("Modify your imported .fmbot data with the options below."); + embedDescription.AppendLine(); + embedDescription.AppendLine("Please keep in mind that this only modifies imports that are stored in .fmbot. Importing in .fmbot works by combining imported plays together with Last.fm scrobbles."); + embedDescription.AppendLine(); + embedDescription.AppendLine("No Last.fm data can be changed or removed with this command."); + + embedDescription.AppendLine($"- {allPlays.Count(c => c.PlaySource == PlaySource.LastFm)} Last.fm scrobbles"); + embedDescription.AppendLine(); + + embedDescription.AppendLine($"**Full Imports, then Last.fm**"); + embedDescription.AppendLine($"- Uses your full {importSource} history and adds Last.fm afterwards"); + embedDescription.AppendLine("- Plays from other music apps you scrobbled to Last.fm will not be included"); + + if (!hasImported) + { + embedDescription.AppendLine(); + embedDescription.AppendLine( + "Run the `/import spotify` command to see how to request your data and to get started with imports. " + + "After importing you'll be able to change these settings."); + } + else + { + embedDescription.AppendLine(); + embedDescription.AppendLine($"**Total counts**"); + if (allPlays.Any(a => a.PlaySource == PlaySource.AppleMusicImport)) + { + embedDescription.AppendLine( + $"- {allPlays.Count(c => c.PlaySource == PlaySource.AppleMusicImport)} imported Apple Music plays"); + } + + if (allPlays.Any(a => a.PlaySource == PlaySource.SpotifyImport)) + { + embedDescription.AppendLine( + $"- {allPlays.Count(c => c.PlaySource == PlaySource.SpotifyImport)} imported Spotify plays"); + } + + embedDescription.AppendLine( + $"- {allPlays.Count(c => c.PlaySource == PlaySource.LastFm)} Last.fm scrobbles"); + + var playResult = + await this._playService.GetPlaysWithDataSource(userId, context.ContextUser.DataSource); + embedDescription.AppendLine(); + embedDescription.AppendLine($"**Data in use with your selected mode**"); + embedDescription.Append( + $"- {playResult.Count(c => c.PlaySource == PlaySource.SpotifyImport || c.PlaySource == PlaySource.AppleMusicImport)} imports + "); + embedDescription.Append( + $"{playResult.Count(c => c.PlaySource == PlaySource.LastFm)} scrobbles = "); + embedDescription.Append($"{playResult.Count} plays"); + } + + response.Embed.WithDescription(embedDescription.ToString()); + + return response; + } } diff --git a/src/FMBot.Bot/Handlers/ClientLogHandler.cs b/src/FMBot.Bot/Handlers/ClientLogHandler.cs index eee6e016..39f77dab 100644 --- a/src/FMBot.Bot/Handlers/ClientLogHandler.cs +++ b/src/FMBot.Bot/Handlers/ClientLogHandler.cs @@ -12,6 +12,7 @@ using FMBot.Domain.Models; using Microsoft.Extensions.Caching.Memory; using Serilog; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously namespace FMBot.Bot.Handlers; diff --git a/src/FMBot.Bot/Handlers/CommandHandler.cs b/src/FMBot.Bot/Handlers/CommandHandler.cs index f726c479..547f982d 100644 --- a/src/FMBot.Bot/Handlers/CommandHandler.cs +++ b/src/FMBot.Bot/Handlers/CommandHandler.cs @@ -20,6 +20,7 @@ using Microsoft.Extensions.Options; using Prometheus; using Serilog; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously namespace FMBot.Bot.Handlers; diff --git a/src/FMBot.Bot/Handlers/InteractionHandler.cs b/src/FMBot.Bot/Handlers/InteractionHandler.cs index 739d8527..60637046 100644 --- a/src/FMBot.Bot/Handlers/InteractionHandler.cs +++ b/src/FMBot.Bot/Handlers/InteractionHandler.cs @@ -17,6 +17,7 @@ using Microsoft.Extensions.Caching.Memory; using Prometheus; using Serilog; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously namespace FMBot.Bot.Handlers; diff --git a/src/FMBot.Bot/Handlers/UserEventHandler.cs b/src/FMBot.Bot/Handlers/UserEventHandler.cs index 0e870c77..ed579547 100644 --- a/src/FMBot.Bot/Handlers/UserEventHandler.cs +++ b/src/FMBot.Bot/Handlers/UserEventHandler.cs @@ -12,6 +12,7 @@ using FMBot.Persistence.Domain.Models; using Microsoft.Extensions.Options; using Serilog; +#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously namespace FMBot.Bot.Handlers; diff --git a/src/FMBot.Bot/TextCommands/LastFM/PlayCommands.cs b/src/FMBot.Bot/TextCommands/LastFM/PlayCommands.cs index a243e532..3d4856a4 100644 --- a/src/FMBot.Bot/TextCommands/LastFM/PlayCommands.cs +++ b/src/FMBot.Bot/TextCommands/LastFM/PlayCommands.cs @@ -271,7 +271,6 @@ public async Task YearAsync([Remainder] string extraOptions = null) [Summary("Shows a recap")] [UsernameSetRequired] [CommandCategories(CommandCategory.Tracks, CommandCategory.Albums, CommandCategory.Artists)] - [ExcludeFromHelp] [Alias("rcp", "wrapped")] public async Task RecapAsync([Remainder] string extraOptions = null) {