Add Red music bot support (and fix a small null reference bug)#268
Add Red music bot support (and fix a small null reference bug)#268w-biggs wants to merge 3 commits intofmbot-discord:devfrom
Conversation
There was a problem hiding this comment.
Hey, thanks for the PR. It would work, but I'm still going to request some changes.
I try to keep the amount of user/guildsettings as low as possible for simplicity and complexity sake. So I would rather not add a guild setting for the name. Instead I would propose to check the bot for either a name or a role to determine if it is the Red music bot.
So for example we can determine if a music bot is Red by:
- The name starts with 'red'
- Or it has a role called 'red music bot'
Doing a role check is fairly straightforward, for example:
if (context.User is IGuildUser guildUser)
{
var role = context.Guild.Roles.FirstOrDefault(x => string.Equals(x.Name, "red music bot", StringComparison.OrdinalIgnoreCase));
if (role != null && guildUser.RoleIds.Contains(role.Id))
{
}
}
A role is easy to add for any server staff and it would still allow custom names for the bot itself.
Another point is the checking with the Last.fm API if the artist - track is reversed. I don't think we can do that, it would use too many API calls. Instead I'd suggest to use the GetTrackFromDatabase method to check if both versions exist. If one does and the other does not you know which one is right.
Let me know if you have any other questions, happy to DM as well (Frikandel on Discord)
|
Sorry for the delay, I'll try to work on those changes within the next week! |
This PR adds support for Red as a music bot.
The way that I've done this integration (since Red is a self-hosted bot) is to make the name of the bot configurable via
.configuration. If this would be better done some other way I'd be happy to make changes to that effect.Additionally, a issue I've run into is that artist and song title will sometimes be reversed (especially if the upload channel is the name of the artist, or a "topic channel"); this PR adds a check for which order has the most listeners on Last.fm and uses the one that's higher. If that's too big of a change, it might make sense to check for "- Topic" specifically and flip the artist/title around only if it's a topic channel (which will miss more wrong-way-around scrobbles, but be a smaller change.)
I also fixed #267 in the process (which was preventing me from running the bot in the first place.)
(I'd also be happy to DM anyone an invite link for my personal Red bot instance for testing, if needed)