Example #1
0
        public static void NoScrobblesFoundErrorResponse(this EmbedBuilder embed, LastResponseStatus apiResponse, string prfx)
        {
            embed.WithTitle("Error while attempting get Last.FM information");
            switch (apiResponse)
            {
            case LastResponseStatus.Failure:
                embed.WithDescription("Can't retrieve scrobbles because Last.FM is having issues. Please try again later. \n" +
                                      "Please note that .fmbot isn't affiliated with Last.FM.");
                break;

            case LastResponseStatus.MissingParameters:
                embed.WithDescription("You or the user you're searching for has no scrobbles/artists on their profile, or Last.FM is having issues. Please try again later. \n \n" +
                                      $"Recently changed your Last.FM username? Please change it here too using `{prfx}set`. \n" +
                                      $"For more info on your settings, use `{prfx}set help`.");
                break;

            default:
                embed.WithDescription(
                    "You or the user you're searching for has no scrobbles/artists on their profile, or Last.FM is having issues. Please try again later.");
                break;
            }

            embed.WithThumbnailUrl("https://www.last.fm/static/images/marvin.e51495403de9.png");
            embed.WithColor(DiscordConstants.WarningColorOrange);
        }
Example #2
0
        public static void NoScrobblesFoundErrorResponse(this EmbedBuilder embed, LastResponseStatus apiResponse, ICommandContext context, Logger.Logger logger)
        {
            embed.WithTitle("Error while attempting get Last.FM information");
            switch (apiResponse)
            {
            case LastResponseStatus.Failure:
                embed.WithDescription("Can't retrieve scrobbles because Last.FM is having issues. Please try again later. \n" +
                                      "Please note that .fmbot isn't affiliated with Last.FM.");
                break;

            case LastResponseStatus.MissingParameters:
                embed.WithDescription("You or the user you're searching for has no scrobbles/artists on their profile, or Last.FM is having issues. Please try again later. \n \n" +
                                      "Recently changed your Last.FM username? Please change it here too using `.fmset`. \n" +
                                      "For more info on your settings, use `.fmset help`.");
                break;

            default:
                embed.WithDescription(
                    "You or the user you're searching for has no scrobbles/artists on their profile, or Last.FM is having issues. Please try again later.");
                break;
            }

            embed.WithThumbnailUrl("https://www.last.fm/static/images/marvin.e51495403de9.png");
            embed.WithColor(Constants.WarningColorOrange);
            logger.LogError($"No scrobbles found for user, error code {apiResponse}", context.Message.Content, context.User.Username, context.Guild?.Name, context.Guild?.Id);
        }
Example #3
0
        public async Task <bool> Login()
        {
            _appLoaderService.Show(_locService["AppLoader_PleaseWait"]);

            LastResponseStatus code = await _lastFmLoginService.LoginAsync(LoginText, PasswordText);

            switch (code)
            {
            case LastResponseStatus.Successful:
                _appLoaderService.Hide();
                return(true);

            case LastResponseStatus.BadAuth:
                _dialogsService.Show(_locService["Message_Login_InvalidAccount_Text"],
                                     _locService["Message_Login_AuthorizationFailed_Title"]);
                break;

            case LastResponseStatus.Unknown:
                _dialogsService.Show(_locService["Message_Login_LfConnectionError_Text"],
                                     _locService["Message_Login_AuthorizationFailed_Title"]);
                break;

            default:
                _dialogsService.Show(String.Format(_locService["Message_Login_UnknownError_Text"], code),
                                     _locService["Message_Login_AuthorizationFailed_Title"]);
                break;
            }

            _appLoaderService.Hide();
            return(false);
        }
Example #4
0
 protected override Task<LastResponseStatus> CacheAsync(IEnumerable<Scrobble> scrobbles, LastResponseStatus originalResponseStatus)
 {
     // TODO cache originalResponse - reason to cache
     return Task.Run(() =>
     {
         Cache(scrobbles);
         return LastResponseStatus.Cached;
     });
 }
Example #5
0
        public static T CreateErrorResponse <T>(LastResponseStatus status) where T : LastResponse, new()
        {
            var r = new T
            {
                Status = status
            };

            return(r);
        }
Example #6
0
        public static PageResponse <T> CreateErrorResponse(LastResponseStatus status)
        {
            var r = new PageResponse <T>
            {
                Status = status
            };

            r.AddDefaultPageInfo();

            return(r);
        }
        private static ServiceRequestResult ParseRequestResult(LastResponseStatus status)
        {
            switch (status)
            {
            case LastResponseStatus.Successful:
                return(ServiceRequestResult.Success);

            case LastResponseStatus.BadAuth:
                return(ServiceRequestResult.InvalidCredentials);

            case LastResponseStatus.Failure:
            case LastResponseStatus.RequestFailed:
            case LastResponseStatus.ServiceDown:
                return(ServiceRequestResult.RemoteServerUnreachable);

            default:
                return(ServiceRequestResult.InternalError);
            }
        }
Example #8
0
        /// <summary>
        /// TODO see issue #5
        /// </summary>
        /// <param name="json">String of JSON</param>
        /// <param name="status">Enum indicating the Status, Unknown if there is no Status</param>
        /// <returns>True when the JSON could be parsed and it didn't describe a known Last.Fm Status.</returns>
        public static bool IsResponseValid(string json, out LastResponseStatus status)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                status = LastResponseStatus.Unknown;
                return(false);
            }

            JObject jo;

            try
            {
                jo = JsonConvert.DeserializeObject <JObject>(json);
            }
            catch (JsonException)
            {
                status = LastResponseStatus.Unknown;
                return(false);
            }

            var codeString = jo.Value <string>("error");

            if (string.IsNullOrWhiteSpace(codeString) && json.Length > 1)
            {
                status = LastResponseStatus.Successful;
                return(true);
            }

            status = LastResponseStatus.Unknown;

            int code;

            if (Int32.TryParse(codeString, out code))
            {
                status = (LastResponseStatus)code;
            }

            return(false);
        }
Example #9
0
 protected override Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobble, LastResponseStatus originalResponseStatus)
 {
     return(Task.FromResult(originalResponseStatus));
 }
Example #10
0
        protected override async Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobbles, LastResponseStatus reason)
        {
            // TODO cache reason
            var db = GetConnection();
            await db.InsertAllAsync(scrobbles);

            return(LastResponseStatus.Cached);
        }
Example #11
0
 public ScrobbleResponse(LastResponseStatus status)
 {
     Status = status;
 }
Example #12
0
 protected override Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobbles, LastResponseStatus originalResponseStatus)
 {
     // TODO cache originalResponse - reason to cache
     return(Task.Run(() =>
     {
         Cache(scrobbles);
         return LastResponseStatus.Cached;
     }));
 }
Example #13
0
 protected abstract Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobble, LastResponseStatus reason);
Example #14
0
        /// <summary>
        /// TODO see issue #5
        /// </summary>
        /// <param name="json">String of JSON</param>
        /// <param name="status">Enum indicating the Status, Unknown if there is no Status</param>
        /// <returns>True when the JSON could be parsed and it didn't describe a known Last.Fm Status.</returns>
        public static bool IsResponseValid(string json, out LastResponseStatus status)
        {
            if (string.IsNullOrWhiteSpace(json))
            {
                status = LastResponseStatus.Unknown;
                return false;
            }

            JObject jo;
            try
            {
                jo = JsonConvert.DeserializeObject<JObject>(json);
            }
            catch (JsonException)
            {
                status = LastResponseStatus.Unknown;
                return false;
            }

            var codeString = jo.Value<string>("error");
            if (string.IsNullOrWhiteSpace(codeString) && json.Length > 1)
            {
                status = LastResponseStatus.Successful;
                return true;
            }

            status = LastResponseStatus.Unknown;

            int code;
            if (Int32.TryParse(codeString, out code))
            {
                status = (LastResponseStatus) code;
            }

            return false;
        }
Example #15
0
 protected override Task<LastResponseStatus> CacheAsync(IEnumerable<Scrobble> scrobble, LastResponseStatus originalResponseStatus)
 {
     return Task.FromResult(originalResponseStatus);
 }
Example #16
0
 public ScrobbleResponse(LastResponseStatus status)
 {
     Status = status;
 }
Example #17
0
 protected override Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobbles, LastResponseStatus reason)
 {
     foreach (var scrobble in scrobbles)
     {
         _scrobbles.Add(scrobble);
     }
     return(Task.FromResult(LastResponseStatus.Cached));
 }
Example #18
0
 protected abstract Task <LastResponseStatus> CacheAsync(IEnumerable <Scrobble> scrobble, LastResponseStatus originalResponseStatus);
Example #19
0
 protected abstract Task<LastResponseStatus> CacheAsync(IEnumerable<Scrobble> scrobble, LastResponseStatus originalResponseStatus);