slightly updated .time

This commit is contained in:
Toastie (DCS Team) 2024-07-29 18:38:07 +12:00
parent 20e5bbac89
commit 586f5ba4b0
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
2 changed files with 8 additions and 26 deletions

View file

@ -98,24 +98,7 @@ public partial class Searches : EllieModule<SearchesService>
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<SearchesService>
[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);

View file

@ -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);
}
}