diff --git a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs index 19fe1f4c..220a70a9 100644 --- a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs +++ b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs @@ -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) { } @@ -24,30 +25,34 @@ 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) { - var description = msg.Embeds.First().Description; - - // Find the index of the newline character and truncate the string if it exists because this would display the next song which we dont need. - int newlineIndex = description.IndexOf('\n'); - if (newlineIndex != -1) - { - description = description.Substring(0, newlineIndex); - } - - // Find the start and end indices of the song info within **[ ]**. - int startIndex = description.IndexOf("**[", StringComparison.Ordinal) + 3; - int endIndex = description.IndexOf("](", StringComparison.Ordinal); - - if (startIndex < 0 || endIndex < 0 || endIndex <= startIndex) + foreach (var embed in msg.Embeds) { - return string.Empty; + 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; } - var songByArtist = description.Substring(startIndex, endIndex - startIndex); - return songByArtist; + return string.Empty; } }