From 08c5c293fa702a31e49846330b53d5cef7f16ded Mon Sep 17 00:00:00 2001 From: Sean Sattler Date: Sun, 8 Dec 2024 13:16:10 +0100 Subject: [PATCH 1/3] A try to fix bot scrobbling (I have no idea what I do here) --- src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs index 19fe1f4c..29bd48c5 100644 --- a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs +++ b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs @@ -31,22 +31,16 @@ 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); + // 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 < 0 || endIndex < 0 || endIndex <= startIndex) + 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; } From da8eda57771c96e27eb977d40452507e975590ba Mon Sep 17 00:00:00 2001 From: Sean Sattler Date: Sun, 8 Dec 2024 13:56:53 +0100 Subject: [PATCH 2/3] A try to fix bot scrobbling (I have still no idea what I do here) --- .../Models/MusicBot/BettyMusicBot.cs | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs index 29bd48c5..3d85db39 100644 --- a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs +++ b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs @@ -29,19 +29,27 @@ public override bool ShouldIgnoreMessage(IUserMessage msg) */ public override string GetTrackQuery(IUserMessage msg) { - var description = msg.Embeds.First().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) + foreach (var embed in msg.Embeds) { - return string.Empty; + 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; + } } - // Extract the song info "SONGTITLE - AUTHOR". - var songByArtist = description.Substring(startIndex, endIndex - startIndex); - return songByArtist; + return string.Empty; } } From 9b6260bcea393a65d69aad826d1f61bb0949a3b7 Mon Sep 17 00:00:00 2001 From: thomkaptein Date: Fri, 3 Jan 2025 15:49:32 +0100 Subject: [PATCH 3/3] fix and adjust betty scrobbling --- .../Models/MusicBot/BettyMusicBot.cs | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs b/src/FMBot.Bot/Models/MusicBot/BettyMusicBot.cs index 3d85db39..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,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;