diff --git a/src/EllieBot/Modules/Searches/Searches.cs b/src/EllieBot/Modules/Searches/Searches.cs index b9e189b..dfd1a8a 100644 --- a/src/EllieBot/Modules/Searches/Searches.cs +++ b/src/EllieBot/Modules/Searches/Searches.cs @@ -98,24 +98,7 @@ public partial class Searches : EllieModule var (data, err) = await _service.GetTimeDataAsync(query); if (err is not null) { - LocStr errorKey; - switch (err) - { - case TimeErrors.ApiKeyMissing: - errorKey = strs.api_key_missing; - break; - case TimeErrors.InvalidInput: - errorKey = strs.invalid_input; - break; - case TimeErrors.NotFound: - errorKey = strs.not_found; - break; - default: - errorKey = strs.error_occured; - break; - } - - await Response().Error(errorKey).SendAsync(); + await HandleErrorAsync(err.Value); return; } @@ -479,8 +462,7 @@ public partial class Searches : EllieModule [RequireContext(ContextType.Guild)] public async Task Avatar([Leftover] IGuildUser usr = null) { - if (usr is null) - usr = (IGuildUser)ctx.User; + usr ??= (IGuildUser)ctx.User; var avatarUrl = usr.RealAvatarUrl(2048); diff --git a/src/EllieBot/Modules/Searches/SearchesService.cs b/src/EllieBot/Modules/Searches/SearchesService.cs index 4cdd5e8..f7406cf 100644 --- a/src/EllieBot/Modules/Searches/SearchesService.cs +++ b/src/EllieBot/Modules/Searches/SearchesService.cs @@ -104,26 +104,26 @@ public class SearchesService : IEService } } - public Task<((string Address, DateTime Time, string TimeZoneName), TimeErrors?)> GetTimeDataAsync(string arg) + public Task<((string Address, DateTime Time, string TimeZoneName), ErrorType?)> GetTimeDataAsync(string arg) => GetTimeDataFactory(arg); //return _cache.GetOrAddCachedDataAsync($"ellie_time_{arg}", // GetTimeDataFactory, // arg, // TimeSpan.FromMinutes(1)); - private async Task<((string Address, DateTime Time, string TimeZoneName), TimeErrors?)> GetTimeDataFactory( + private async Task<((string Address, DateTime Time, string TimeZoneName), ErrorType?)> GetTimeDataFactory( string query) { query = query.Trim(); if (string.IsNullOrEmpty(query)) - return (default, TimeErrors.InvalidInput); + return (default, ErrorType.InvalidInput); var locIqKey = _creds.GetCreds().LocationIqApiKey; var tzDbKey = _creds.GetCreds().TimezoneDbApiKey; if (string.IsNullOrWhiteSpace(locIqKey) || string.IsNullOrWhiteSpace(tzDbKey)) - return (default, TimeErrors.ApiKeyMissing); + return (default, ErrorType.ApiKeyMissing); try { @@ -147,7 +147,7 @@ public class SearchesService : IEService if (responses is null || responses.Length == 0) { Log.Warning("Geocode lookup failed for: {Query}", query); - return (default, TimeErrors.NotFound); + return (default, ErrorType.NotFound); } var geoData = responses[0]; @@ -171,7 +171,7 @@ public class SearchesService : IEService catch (Exception ex) { Log.Error(ex, "Weather error: {Message}", ex.Message); - return (default, TimeErrors.NotFound); + return (default, ErrorType.NotFound); } }