LiveSplit / SpeedrunComSharp

A .NET Library that can be used to interact with the Speedrun.com API
MIT License
32 stars 9 forks source link

Issue pulling a specific leaderboard #10

Closed Roopert83 closed 6 years ago

Roopert83 commented 6 years ago

I'm attempting to pull all five of the SMB1 leaderboards. I can pull four of them just fine, but I can't pull the one for the Warpless category.

The following does not work and gives me an "ArgumentException: role" error.

// Warpless
var srClient = new SpeedrunComClient();
var leaderboard = srClient.Leaderboards.GetLeaderboardForFullGameCategory("om1m3625", "wdmz042q", 500, null, null, EmulatorsFilter.NotSet, false, null, null, null);

These all work for me:

// Any%
var srClient = new SpeedrunComClient();
var leaderboard = srClient.Leaderboards.GetLeaderboardForFullGameCategory("om1m3625", "w20p0zkn", 500, null, null, EmulatorsFilter.NotSet, false, null, null, null);
// Minus World Ending
var srClient = new SpeedrunComClient();
var leaderboard = srClient.Leaderboards.GetLeaderboardForFullGameCategory("om1m3625", "xd1em828", 500, null, null, EmulatorsFilter.NotSet, false, null, null, null);
// All-Stars Any%
var srClient = new SpeedrunComClient();
var leaderboard = srClient.Leaderboards.GetLeaderboardForFullGameCategory("om1m3625", "mke8vjk6", 500, null, null, EmulatorsFilter.NotSet, false, null, null, null);
// All-Stars Warpless
var srClient = new SpeedrunComClient();
var leaderboard = srClient.Leaderboards.GetLeaderboardForFullGameCategory("om1m3625", "5dwv95kg", 500, null, null, EmulatorsFilter.NotSet, false, null, null, null);
Roopert83 commented 6 years ago

I have discovered the problem and have a fix for it. Authorblues broke the program because he's a content moderator and that's not defined in this project. I added it myself, compiled it and it now runs with no issues.

Here are the relevant sections of code in which I made changes to include Content Moderator:

User.cs

private static UserRole parseUserRole(string role)
        {
            switch (role)
            {
                case "banned":
                    return UserRole.Banned;
                case "user":
                    return UserRole.User;
                case "trusted":
                    return UserRole.Trusted;
                case "moderator":
                    return UserRole.Moderator;
                case "admin":
                    return UserRole.Admin;
                case "programmer":
                    return UserRole.Programmer;
                case "contentmoderator":
                    return UserRole.ContentModerator;
            }

            throw new ArgumentException("role");
        }

UserRole.cs

namespace SpeedrunComSharp
{
    public enum UserRole
    {
        Banned, User, Trusted, Moderator, Admin, Programmer, ContentModerator
    }
}