Fixed around 140 wrong namings and other refactorings which were marked as warnings

This commit is contained in:
Kwoth
2022-01-08 11:51:41 +01:00
parent a6330119e8
commit 2ce3262d59
109 changed files with 698 additions and 760 deletions

View File

@@ -74,7 +74,7 @@ public class CommandMapService : IInputTransformer, INService
try
{
var toDelete = await channel.SendConfirmAsync(_eb, $"{input} => {newInput}");
var _ = Task.Run(async () =>
_= Task.Run(async () =>
{
await Task.Delay(1500);
await toDelete.DeleteAsync(new() { RetryMode = RetryMode.AlwaysRetry });

View File

@@ -12,7 +12,7 @@ public partial class Utility
[Group]
public partial class QuoteCommands : NadekoSubmodule
{
private const string _prependExport =
private const string PREPEND_EXPORT =
@"# Keys are keywords, Each key has a LIST of quotes in the following format:
# - id: Alphanumeric id used for commands related to the quote. (Note, when using .quotesimport, a new id will be generated.)
# an: Author name
@@ -279,7 +279,7 @@ public partial class Utility
var exprsDict = quotes.GroupBy(x => x.Keyword)
.ToDictionary(x => x.Key, x => x.Select(ExportedQuote.FromModel));
var text = _prependExport + _exportSerializer.Serialize(exprsDict).UnescapeUnicodeCodePoints();
var text = PREPEND_EXPORT + _exportSerializer.Serialize(exprsDict).UnescapeUnicodeCodePoints();
await using var stream = await text.ToStream();
await ctx.Channel.SendFileAsync(stream, "quote-export.yml");

View File

@@ -11,20 +11,20 @@ public class StreamRoleService : INService
{
private readonly DbService _db;
private readonly DiscordSocketClient _client;
private readonly ConcurrentDictionary<ulong, StreamRoleSettings> guildSettings;
private readonly ConcurrentDictionary<ulong, StreamRoleSettings> _guildSettings;
public StreamRoleService(DiscordSocketClient client, DbService db, Bot bot)
{
_db = db;
_client = client;
guildSettings = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.StreamRole)
_guildSettings = bot.AllGuildConfigs.ToDictionary(x => x.GuildId, x => x.StreamRole)
.Where(x => x.Value is { Enabled: true })
.ToConcurrent();
_client.GuildMemberUpdated += Client_GuildMemberUpdated;
var _ = Task.Run(async () =>
_= Task.Run(async () =>
{
try
{
@@ -39,10 +39,10 @@ public class StreamRoleService : INService
private Task Client_GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> cacheable, SocketGuildUser after)
{
var _ = Task.Run(async () =>
_= Task.Run(async () =>
{
//if user wasn't streaming or didn't have a game status at all
if (guildSettings.TryGetValue(after.Guild.Id, out var setting)) await RescanUser(after, setting);
if (_guildSettings.TryGetValue(after.Guild.Id, out var setting)) await RescanUser(after, setting);
});
return Task.CompletedTask;
@@ -51,6 +51,7 @@ public class StreamRoleService : INService
/// <summary>
/// Adds or removes a user from a blacklist or a whitelist in the specified guild.
/// </summary>
/// <param name="listType">List type</param>
/// <param name="guild">Guild</param>
/// <param name="action">Add or rem action</param>
/// <param name="userId">User's Id</param>
@@ -97,7 +98,6 @@ public class StreamRoleService : INService
var toRemove = streamRoleSettings.Blacklist.FirstOrDefault(x => x.Equals(userObj));
if (toRemove is not null)
{
success = true;
success = streamRoleSettings.Blacklist.Remove(toRemove);
}
}
@@ -123,7 +123,7 @@ public class StreamRoleService : INService
/// <returns>The keyword set</returns>
public async Task<string> SetKeyword(IGuild guild, string keyword)
{
keyword = keyword?.Trim()?.ToLowerInvariant();
keyword = keyword?.Trim().ToLowerInvariant();
await using (var uow = _db.GetDbContext())
{
@@ -145,7 +145,7 @@ public class StreamRoleService : INService
/// <returns>The keyword set</returns>
public string GetKeyword(ulong guildId)
{
if (guildSettings.TryGetValue(guildId, out var outSetting))
if (_guildSettings.TryGetValue(guildId, out var outSetting))
return outSetting.Keyword;
StreamRoleSettings setting;
@@ -193,7 +193,8 @@ public class StreamRoleService : INService
/// <summary>
/// Stops the stream role feature on the specified guild.
/// </summary>
/// <param name="guildId">Guild's Id</param>
/// <param name="guild">Guild</param>
/// <param name="cleanup">Whether to rescan users</param>
public async Task StopStreamRole(IGuild guild, bool cleanup = false)
{
await using (var uow = _db.GetDbContext())
@@ -205,7 +206,7 @@ public class StreamRoleService : INService
await uow.SaveChangesAsync();
}
if (guildSettings.TryRemove(guild.Id, out var setting) && cleanup)
if (_guildSettings.TryRemove(guild.Id, out _) && cleanup)
await RescanUsers(guild);
}
@@ -231,7 +232,7 @@ public class StreamRoleService : INService
if (addRole is null)
{
await StopStreamRole(user.Guild);
Log.Warning("Stream role in server {0} no longer exists. Stopping.", setting.AddRoleId);
Log.Warning("Stream role in server {RoleId} no longer exists. Stopping", setting.AddRoleId);
return;
}
@@ -239,7 +240,7 @@ public class StreamRoleService : INService
if (!user.RoleIds.Contains(addRole.Id))
{
await user.AddRoleAsync(addRole);
Log.Information("Added stream role to user {0} in {1} server",
Log.Information("Added stream role to user {User} in {Server} server",
user.ToString(),
user.Guild.ToString());
}
@@ -266,7 +267,7 @@ public class StreamRoleService : INService
throw new StreamRoleNotFoundException();
await user.RemoveRoleAsync(addRole);
Log.Information("Removed stream role from the user {0} in {1} server",
Log.Information("Removed stream role from the user {User} in {Server} server",
user.ToString(),
user.Guild.ToString());
}
@@ -281,7 +282,7 @@ public class StreamRoleService : INService
private async Task RescanUsers(IGuild guild)
{
if (!guildSettings.TryGetValue(guild.Id, out var setting))
if (!_guildSettings.TryGetValue(guild.Id, out var setting))
return;
var addRole = guild.GetRole(setting.AddRoleId);
@@ -299,5 +300,5 @@ public class StreamRoleService : INService
}
private void UpdateCache(ulong guildId, StreamRoleSettings setting)
=> guildSettings.AddOrUpdate(guildId, _ => setting, (_, _) => setting);
=> _guildSettings.AddOrUpdate(guildId, _ => setting, (_, _) => setting);
}

View File

@@ -11,17 +11,14 @@ public class ConverterService : INService
private readonly Timer _currencyUpdater;
private readonly TimeSpan _updateInterval = new(12, 0, 0);
private readonly DbService _db;
private readonly IDataCache _cache;
private readonly IHttpClientFactory _httpFactory;
public ConverterService(
DiscordSocketClient client,
DbService db,
IDataCache cache,
IHttpClientFactory factory)
{
_db = db;
_cache = cache;
_httpFactory = factory;

View File

@@ -81,7 +81,7 @@ public partial class Utility : NadekoModule
if (ctx.Guild is not SocketGuild socketGuild)
{
Log.Warning("Can't cast guild to socket guild.");
Log.Warning("Can't cast guild to socket guild");
return;
}
@@ -154,7 +154,15 @@ public partial class Utility : NadekoModule
var builder = new StringBuilder();
var user = who == MeOrBot.Me ? (IGuildUser)ctx.User : ((SocketGuild)ctx.Guild).CurrentUser;
var perms = user.GetPermissions((ITextChannel)ctx.Channel);
foreach (var p in perms.GetType().GetProperties().Where(p => !p.GetGetMethod().GetParameters().Any()))
foreach (var p in perms.GetType()
.GetProperties()
.Where(static p =>
{
var method = p.GetGetMethod();
if (method is null)
return false;
return !method.GetParameters().Any();
}))
builder.AppendLine($"{p.Name} : {p.GetValue(perms, null)}");
await SendConfirmAsync(builder.ToString());
}
@@ -355,7 +363,10 @@ public partial class Utility : NadekoModule
if (page < 0)
return;
var guilds = await Task.Run(() => _client.Guilds.OrderBy(g => g.Name).Skip(page * 15).Take(15));
var guilds = _client.Guilds.OrderBy(g => g.Name)
.Skip(page * 15)
.Take(15)
.ToList();
if (!guilds.Any())
{