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

Fix Listen bot scrobbling #299

Merged
merged 2 commits into from
Feb 13, 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
32 changes: 20 additions & 12 deletions src/FMBot.Bot/Models/MusicBot/ListenMusicBot.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System.Linq;
using Discord;
using System.Linq;

namespace FMBot.Bot.Models.MusicBot;

internal partial class ListenMusicBot : MusicBot
{
private const string NowPlaying = "Now Playing";
private const string ListenBotUrl = "https://listenbot.site";
private const string ListenBotImageUrl = "https://i.imgur.com/Bes7wpk.png";

public ListenMusicBot() : base("Listen")
{
}
Expand All @@ -17,26 +19,32 @@ public override bool ShouldIgnoreMessage(IUserMessage msg)
return true;
}

var title = msg.Embeds.First().Title;
return string.IsNullOrEmpty(title) || !title.Contains(NowPlaying);
var embed = msg.Embeds.First();

// Check if it's a Listen bot embed based on the constant URL and image
return embed.Url != ListenBotUrl ||
embed.Image?.Url != ListenBotImageUrl;
}

/**
* Example:
* Mall Grab - [Menace II Society](https://help.soundcloud.com/hc/en-us/articles/4402636813979-What-are-SoundCloud-s-copyright-policies)
* Title: "I Feel It Coming (feat. Daft Punk)"
* Description: "-# The Weeknd"
* Returns: "I Feel It Coming The Weeknd"
*/
public override string GetTrackQuery(IUserMessage msg)
{
var content = msg.Embeds.First().Description;

if (string.IsNullOrWhiteSpace(content))
var embed = msg.Embeds.First();

if (string.IsNullOrWhiteSpace(embed.Title) ||
string.IsNullOrWhiteSpace(embed.Description))
{
return string.Empty;
}

return ListenMusicBotRegex().Replace(msg.Embeds.First().Description, "$1");
// Remove the "-# " prefix from the description to get the artist name
var artist = embed.Description.Replace("-# ", "").Trim();

return $"{embed.Title} {artist}";
}

[System.Text.RegularExpressions.GeneratedRegex(@"\[(.*?)\]\(.*?\)")]
private static partial System.Text.RegularExpressions.Regex ListenMusicBotRegex();
}
Loading