More common refactorings like renaming variables, removing empty statements and unused variables, etc

This commit is contained in:
Kwoth
2022-01-09 16:46:08 +01:00
parent 2ce3262d59
commit f07a855912
75 changed files with 447 additions and 465 deletions

View File

@@ -10,7 +10,7 @@ public class CryptoService : INService
private readonly IHttpClientFactory _httpFactory;
private readonly IBotCredentials _creds;
private readonly SemaphoreSlim getCryptoLock = new(1, 1);
private readonly SemaphoreSlim _getCryptoLock = new(1, 1);
public CryptoService(IDataCache cache, IHttpClientFactory httpFactory, IBotCredentials creds)
{
@@ -52,7 +52,7 @@ public class CryptoService : INService
public async Task<List<CryptoResponseData>> CryptoData()
{
await getCryptoLock.WaitAsync();
await _getCryptoLock.WaitAsync();
try
{
var fullStrData = await _cache.GetOrAddCachedDataAsync("nadeko:crypto_data",
@@ -81,7 +81,7 @@ public class CryptoService : INService
"",
TimeSpan.FromHours(1));
return JsonConvert.DeserializeObject<CryptoResponse>(fullStrData).Data;
return JsonConvert.DeserializeObject<CryptoResponse>(fullStrData)?.Data ?? new();
}
catch (Exception ex)
{
@@ -90,7 +90,7 @@ public class CryptoService : INService
}
finally
{
getCryptoLock.Release();
_getCryptoLock.Release();
}
}
}

View File

@@ -10,7 +10,7 @@ public partial class Searches
[Group]
public partial class FeedCommands : NadekoSubmodule<FeedsService>
{
private static readonly Regex YtChannelRegex =
private static readonly Regex _ytChannelRegex =
new(@"youtube\.com\/(?:c\/|channel\/|user\/)?(?<channelid>[a-zA-Z0-9\-]{1,})");
[Cmd]
@@ -18,7 +18,7 @@ public partial class Searches
[UserPerm(GuildPerm.ManageMessages)]
public partial Task YtUploadNotif(string url, [Leftover] ITextChannel channel = null)
{
var m = YtChannelRegex.Match(url);
var m = _ytChannelRegex.Match(url);
if (!m.Success) return ReplyErrorLocalizedAsync(strs.invalid_input);
var channelId = m.Groups["channelid"].Value;
@@ -38,7 +38,7 @@ public partial class Searches
channel ??= (ITextChannel)ctx.Channel;
try
{
var feeds = await FeedReader.ReadAsync(url);
await FeedReader.ReadAsync(url);
}
catch (Exception ex)
{

View File

@@ -115,7 +115,6 @@ public partial class Searches
[Cmd]
public async partial Task Osu5(string user, [Leftover] string mode = null)
{
;
if (string.IsNullOrWhiteSpace(_creds.OsuApiKey))
{
await SendErrorAsync("An osu! API key is required.");

View File

@@ -46,7 +46,7 @@ public class SearchesService : INService
private readonly NadekoRandom _rng;
private readonly List<string> _yomamaJokes;
private readonly object yomamaLock = new();
private readonly object _yomamaLock = new();
private int yomamaJokeIndex;
public SearchesService(
@@ -224,9 +224,11 @@ public class SearchesService : INService
using var req = new HttpRequestMessage(HttpMethod.Get,
"http://api.timezonedb.com/v2.1/get-time-zone?"
+ $"key={_creds.TimezoneDbApiKey}&format=json&"
+ "by=position&"
+ $"lat={geoData.Lat}&lng={geoData.Lon}");
+ $"key={_creds.TimezoneDbApiKey}"
+ $"&format=json"
+ $"&by=position"
+ $"&lat={geoData.Lat}"
+ $"&lng={geoData.Lon}");
using var geoRes = await http.SendAsync(req);
var resString = await geoRes.Content.ReadAsStringAsync();
var timeObj = JsonConvert.DeserializeObject<TimeZoneResult>(resString);
@@ -274,7 +276,7 @@ public class SearchesService : INService
public Task<string> GetYomamaJoke()
{
string joke;
lock (yomamaLock)
lock (_yomamaLock)
{
if (yomamaJokeIndex >= _yomamaJokes.Count)
{
@@ -428,8 +430,6 @@ public class SearchesService : INService
public async Task<int> GetSteamAppIdByName(string query)
{
var redis = _cache.Redis;
var db = redis.GetDatabase();
const string steamGameIdsKey = "steam_names_to_appid";
// var exists = await db.KeyExistsAsync(steamGameIdsKey);

View File

@@ -59,7 +59,7 @@ public partial class Searches
[UserPerm(GuildPerm.Administrator)]
public async partial Task StreamsClear()
{
var count = _service.ClearAllStreams(ctx.Guild.Id);
await _service.ClearAllStreams(ctx.Guild.Id);
await ReplyConfirmLocalizedAsync(strs.streams_cleared);
}

View File

@@ -116,7 +116,7 @@ public sealed class StreamNotificationService : INService
return;
var deleteGroups = failingStreams.GroupBy(x => x.Type)
.ToDictionary(x => x.Key, x => x.Select(x => x.Name).ToList());
.ToDictionary(x => x.Key, x => x.Select(y => y.Name).ToList());
using var uow = _db.GetDbContext();
foreach (var kvp in deleteGroups)

View File

@@ -1,5 +1,4 @@
#nullable disable
namespace NadekoBot.Modules.Searches.Services;
// public class YtTrackService : INService
// {

View File

@@ -1,22 +0,0 @@
#nullable disable
namespace NadekoBot.Modules.Searches.Common;
//
// public class TwitchResponse
// {
// public List<StreamApiData> Data { get; set; }
//
// public class StreamApiData
// {
// public string Id { get; set; }
// public string UserId { get; set; }
// public string UserName { get; set; }
// public string GameId { get; set; }
// public string Type { get; set; }
// public string Title { get; set; }
// public int ViewerCount { get; set; }
// public string Language { get; set; }
// public string ThumbnailUrl { get; set; }
// public DateTime StartedAt { get; set; }
// }
// }