Skip to content

Commit

Permalink
fix and adjust betty scrobbling
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Jan 3, 2025
1 parent 31f9f01 commit 9b6260b
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace FMBot.Bot.Models.MusicBot;
internal class BettyMusicBot : MusicBot
{
private const string NowPlaying = "・Now Playing";

public BettyMusicBot() : base("Betty", false, trackNameFirst: true)
{
}
Expand All @@ -24,30 +25,32 @@ public override bool ShouldIgnoreMessage(IUserMessage msg)
}

/**
* Example:
* :voice:・Now Playing **[Escape - Jacob Vallen](https://discord.gg/XXXXX 'An invite link to the support server')**
* Example:
* <:voice:1005912303503421471>・Now Playing **iluv - Effy**
*/
public override string GetTrackQuery(IUserMessage msg)
{
foreach (var embed in msg.Embeds)
{
if (embed.Description != null && embed.Description.StartsWith(":voice:・Now Playing", StringComparison.Ordinal))
{
var description = embed.Description;

// Look for the start and end indices of the song info within **SONGTITLE - AUTHOR**.
int startIndex = description.IndexOf("Now Playing **", StringComparison.Ordinal) + "Now Playing **".Length;
int endIndex = description.IndexOf("**", startIndex, StringComparison.Ordinal);

if (startIndex < "Now Playing **".Length || endIndex < 0 || endIndex <= startIndex)
{
return string.Empty;
}

// Extract the song info "SONGTITLE - AUTHOR".
var songByArtist = description.Substring(startIndex, endIndex - startIndex);
return songByArtist;
if (embed.Description == null ||
!embed.Description.Contains(NowPlaying, StringComparison.OrdinalIgnoreCase))
{
continue;
}

// Look for the start and end indices of the song info within **SONGTITLE - AUTHOR**.
var startIndex = embed.Description.IndexOf("Now Playing **", StringComparison.OrdinalIgnoreCase) +
"Now Playing **".Length;
var endIndex = embed.Description.IndexOf("**", startIndex, StringComparison.OrdinalIgnoreCase);

if (startIndex < "Now Playing **".Length || endIndex < 0 || endIndex <= startIndex)
{
return string.Empty;
}

// Extract the song info "SONGTITLE - AUTHOR".
var songByArtist = embed.Description.Substring(startIndex, endIndex - startIndex);
return songByArtist;
}

return string.Empty;
Expand Down

0 comments on commit 9b6260b

Please sign in to comment.