Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A try to fix bot scrobbling (I have no idea what I do here) #297

Merged
merged 4 commits into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 24 additions & 19 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,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;
}
}
Loading