Skip to content

Commit

Permalink
improve text and show index on login
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Jan 12, 2025
1 parent 42bcba1 commit e409abd
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 26 deletions.
8 changes: 2 additions & 6 deletions src/FMBot.Bot/Builders/ImportBuilders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public async Task<ResponseModel> GetSpotifyImportInstructions(ContextModel conte
var importDescription = new StringBuilder();

importDescription.AppendLine("1. Download the file Spotify provided");
importDescription.AppendLine($"2. Use `/import spotify` slash command and add the `.zip` file as an attachment through the options");
importDescription.AppendLine($"2. Use the `/import spotify` slash command and add the `.zip` file as an attachment through the options");
importDescription.AppendLine("3. Having issues? You can also attach each `.json` file separately");
response.Embed.AddField($"{DiscordConstants.Imports} Importing your data into .fmbot",
importDescription.ToString());
Expand Down Expand Up @@ -166,7 +166,7 @@ public async Task<ResponseModel> GetAppleMusicImportInstructions(ContextModel co
var importDescription = new StringBuilder();
importDescription.AppendLine("1. Download the file Apple provided");
importDescription.AppendLine(
"2. Use `/import applemusic` slash command and add the `.zip` file as an attachment through the options");
"2. Use the `/import applemusic` slash command and add the `.zip` file as an attachment through the options");
importDescription.AppendLine(
"3. Got multiple zip files? You can try them all until one succeeds. Only one of them contains your play history");
importDescription.AppendLine(
Expand Down Expand Up @@ -323,10 +323,6 @@ public async Task<ResponseModel> ImportModify(ContextModel context, int userId)
noteDescription.AppendLine(
"Because you have selected the mode **Imports, then full Last.fm** not all imports might be used. This mode only uses your imports up until you started scrobbling on Last.fm.");
}
else
{

}

if (noteDescription.Length > 0)
{
Expand Down
50 changes: 38 additions & 12 deletions src/FMBot.Bot/Builders/UserBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,13 @@ public static ResponseModel BotScrobblingAsync(ContextModel context)

response.Embed.WithDescription(
"Bot scrobbling allows you to automatically scrobble music from Discord music bots to your Last.fm account. " +
"For this to work properly you need to make sure .fmbot can see the voice channel and use a supported music bot.\n\n" +
"For this to work properly fmbot needs to be in the server, you need to make sure it can see the voice channel and you must use a supported music bot.\n\n" +
"Only tracks that already exist on Last.fm will be scrobbled. The bot reads the 'Now Playing' message a bot sends and tries to retrieve the artist and track name from there.");

response.Components = new ComponentBuilder()
.WithButton("Enable", InteractionConstants.BotScrobblingEnable, style: ButtonStyle.Success, new Emoji("✅"))
.WithButton("Disable", InteractionConstants.BotScrobblingDisable, style: ButtonStyle.Danger,
new Emoji("✖️"))
.WithButton("Supported music bots", style: ButtonStyle.Link, url: "https://fmbot.xyz/botscrobbling/");
.WithButton("Enable", InteractionConstants.BotScrobblingEnable, style: ButtonStyle.Primary)
.WithButton("Disable", InteractionConstants.BotScrobblingDisable, style: ButtonStyle.Secondary)
.WithButton("Supported music bots", style: ButtonStyle.Link, url: "https://fmbot.xyz/botscrobbling/#currently-supported-bots");

return response;
}
Expand Down Expand Up @@ -251,26 +250,52 @@ public static ResponseModel StartLogin(User contextUser, string authToken, strin
return response;
}

public static ResponseModel LoginSuccess(User newContextUser)
public enum LoginState
{
SuccessNoIndex,
SuccessPendingIndex,
SuccessIndexComplete
}

public static ResponseModel LoginSuccess(User newContextUser, LoginState loginState)
{
var response = new ResponseModel
{
ResponseType = ResponseType.Embed
};

response.Embed.WithColor(DiscordConstants.SuccessColorGreen);
var description =
$"✅ You have been logged in to .fmbot with the username [{newContextUser.UserNameLastFM}]({LastfmUrlExtensions.GetUserUrl(newContextUser.UserNameLastFM)})!\n\n" +
$"Use the button below to configure your settings and to customize your .fmbot experience.\n\n" +
$"Please note that .fmbot is not affiliated with Last.fm.";
var description = new StringBuilder();
switch (loginState)
{
case LoginState.SuccessNoIndex:
description.AppendLine(
$"✅ You have been logged in to .fmbot with the username [{newContextUser.UserNameLastFM}]({LastfmUrlExtensions.GetUserUrl(newContextUser.UserNameLastFM)})!");
break;
case LoginState.SuccessPendingIndex:
description.AppendLine(
$"{DiscordConstants.Loading} Fetching Last.fm data for [{newContextUser.UserNameLastFM}]({LastfmUrlExtensions.GetUserUrl(newContextUser.UserNameLastFM)})...");
break;
case LoginState.SuccessIndexComplete:
description.AppendLine(
$"✅ You have been logged in to .fmbot with the username [{newContextUser.UserNameLastFM}]({LastfmUrlExtensions.GetUserUrl(newContextUser.UserNameLastFM)})!");
break;
default:
throw new ArgumentOutOfRangeException(nameof(loginState), loginState, null);
}

description.AppendLine();
description.AppendLine($"Use the button below to start configuring your settings and to customize your .fmbot experience.");
description.AppendLine();
description.AppendLine($"Please note that .fmbot is not affiliated with Last.fm.");

response.Components = new ComponentBuilder()
.WithButton("Settings", style: ButtonStyle.Secondary, customId: InteractionConstants.User.Settings,
emote: new Emoji("⚙️"))
.WithButton("Add .fmbot", style: ButtonStyle.Link,
url: "https://discord.com/oauth2/authorize?client_id=356268235697553409");

response.Embed.WithDescription(description);
response.Embed.WithDescription(description.ToString());
return response;
}

Expand Down Expand Up @@ -1740,7 +1765,8 @@ public async Task<ResponseModel> ManageAlts(ContextModel context)
embedDescription.AppendLine("- Transfer data (streaks, featured history and imports) and delete account");
embedDescription.AppendLine("- Only delete account");
embedDescription.AppendLine();
embedDescription.AppendLine(".fmbot is not affiliated with Last.fm. No Last.fm data can be modified, transferred or deleted with this command.");
embedDescription.AppendLine(
".fmbot is not affiliated with Last.fm. No Last.fm data can be modified, transferred or deleted with this command.");

response.Embed.WithDescription(embedDescription.ToString());

Expand Down
38 changes: 30 additions & 8 deletions src/FMBot.Bot/SlashCommands/UserSlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,17 +288,35 @@ await RespondAsync(null, [loginUrlResponse.Embed.Build()], ephemeral: true,
if (loginSuccess)
{
var newUserSettings = await this._userService.GetUserSettingsAsync(this.Context.User);

var indexUser = contextUser == null ||
!string.Equals(contextUser.UserNameLastFM, newUserSettings.UserNameLastFM,
StringComparison.CurrentCultureIgnoreCase);

var loginSuccessResponse =
UserBuilder.LoginSuccess(newUserSettings);
UserBuilder.LoginSuccess(newUserSettings,
indexUser ? UserBuilder.LoginState.SuccessPendingIndex : UserBuilder.LoginState.SuccessNoIndex);

await FollowupAsync(null, [loginSuccessResponse.Embed.Build()], ephemeral: true,
components: loginSuccessResponse.Components.Build());
await this.Context.Interaction.ModifyOriginalResponseAsync(m =>
{
m.Components = loginSuccessResponse.Components.Build();
m.Embed = loginSuccessResponse.Embed.Build();
});
this.Context.LogCommandUsed();

if (contextUser == null || !string.Equals(contextUser.UserNameLastFM, newUserSettings.UserNameLastFM,
StringComparison.CurrentCultureIgnoreCase))

if (indexUser)
{
await this._indexService.IndexUser(newUserSettings);

loginSuccessResponse =
UserBuilder.LoginSuccess(newUserSettings, UserBuilder.LoginState.SuccessIndexComplete);

await this.Context.Interaction.ModifyOriginalResponseAsync(m =>
{
m.Components = loginSuccessResponse.Components.Build();
m.Embed = loginSuccessResponse.Embed.Build();
});
}

if (this.Context.Guild != null)
Expand Down Expand Up @@ -1350,7 +1368,9 @@ public async Task DeleteAltConfirmed(string transferData, string targetUserId)

var components =
new ComponentBuilder().WithButton(
transferData == "true" ? "Successfully transferred data and deleted alt" : "Successfully deleted alt",
transferData == "true"
? "Successfully transferred data and deleted alt"
: "Successfully deleted alt",
customId: "0", disabled: true, style: ButtonStyle.Success);
await this.Context.Interaction.ModifyOriginalResponseAsync(m => { m.Components = components.Build(); });

Expand Down Expand Up @@ -1462,7 +1482,8 @@ public async Task ImportInstructionsSpotify()
try
{
var response =
await this._importBuilders.GetSpotifyImportInstructions(new ContextModel(this.Context, contextUser), true);
await this._importBuilders.GetSpotifyImportInstructions(new ContextModel(this.Context, contextUser),
true);

await this.Context.UpdateInteractionEmbed(response);
this.Context.LogCommandUsed(response.CommandResponse);
Expand All @@ -1482,7 +1503,8 @@ public async Task ImportInstructionsAppleMusic()
try
{
var response =
await this._importBuilders.GetAppleMusicImportInstructions(new ContextModel(this.Context, contextUser), true);
await this._importBuilders.GetAppleMusicImportInstructions(new ContextModel(this.Context, contextUser),
true);

await this.Context.UpdateInteractionEmbed(response);
this.Context.LogCommandUsed(response.CommandResponse);
Expand Down

0 comments on commit e409abd

Please sign in to comment.