Using pattern matching for nulls where applicable, discarded unused lambda parameters, cleaned up some classes. Unignored ServerLog commands which was mistakenly ignored due to a .gitignore rule

This commit is contained in:
Kwoth
2022-01-01 08:44:51 +01:00
parent f81f9fadd3
commit 9b4eb21321
91 changed files with 1591 additions and 224 deletions

View File

@@ -61,7 +61,7 @@ public class CommandHandler : INService
GLOBAL_COMMANDS_COOLDOWN,
GLOBAL_COMMANDS_COOLDOWN);
_prefixes = bot.AllGuildConfigs.Where(x => x.Prefix != null)
_prefixes = bot.AllGuildConfigs.Where(x => x.Prefix is not null)
.ToDictionary(x => x.GuildId, x => x.Prefix)
.ToConcurrent();
}
@@ -111,7 +111,7 @@ public class CommandHandler : INService
public async Task ExecuteExternal(ulong? guildId, ulong channelId, string commandText)
{
if (guildId != null)
if (guildId is not null)
{
var guild = _client.GetGuild(guildId.Value);
if (guild?.GetChannel(channelId) is not SocketTextChannel channel)
@@ -210,7 +210,7 @@ public class CommandHandler : INService
{
#if !GLOBAL_NADEKO
// track how many messagges each user is sending
UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (key, old) => ++old);
UserMessagesSent.AddOrUpdate(usrMsg.Author.Id, 1, (_, old) => ++old);
#endif
var channel = msg.Channel;
@@ -221,7 +221,7 @@ public class CommandHandler : INService
catch (Exception ex)
{
Log.Warning(ex, "Error in CommandHandler");
if (ex.InnerException != null)
if (ex.InnerException is not null)
Log.Warning(ex.InnerException, "Inner Exception of the error in CommandHandler");
}
});
@@ -260,10 +260,10 @@ public class CommandHandler : INService
return;
}
if (error != null)
if (error is not null)
{
LogErroredExecution(error, usrMsg, channel as ITextChannel, blockTime, startTime);
if (guild != null)
if (guild is not null)
await CommandErrored(info, channel as ITextChannel, error);
}
}
@@ -384,7 +384,7 @@ public class CommandHandler : INService
var chosenOverload = successfulParses[0];
var execResult = (ExecuteResult)await chosenOverload.Key.ExecuteAsync(context, chosenOverload.Value, services);
if (execResult.Exception != null
if (execResult.Exception is not null
&& (execResult.Exception is not HttpException he
|| he.DiscordCode != DiscordErrorCode.InsufficientPermissions))
Log.Warning(execResult.Exception, "Command Error");

View File

@@ -40,7 +40,7 @@ public class Localization : ILocalization, INService
return cultureInfo;
})
.Where(x => x.Value != null));
.Where(x => x.Value is not null));
}
public void SetGuildCulture(IGuild guild, CultureInfo ci)
@@ -61,7 +61,7 @@ public class Localization : ILocalization, INService
uow.SaveChanges();
}
GuildCultureInfos.AddOrUpdate(guildId, ci, (id, old) => ci);
GuildCultureInfos.AddOrUpdate(guildId, ci, (_, _) => ci);
}
public void RemoveGuildCulture(IGuild guild)

View File

@@ -38,7 +38,7 @@ public class RedisCache : IDataCache
{
var _db = Redis.GetDatabase();
byte[] x = await _db.StringGetAsync("image_" + key);
return (x != null, x);
return (x is not null, x);
}
public Task SetImageDataAsync(Uri key, byte[] data)
@@ -51,7 +51,7 @@ public class RedisCache : IDataCache
{
var _db = Redis.GetDatabase();
string x = await _db.StringGetAsync("anime_" + key);
return (x != null, x);
return (x is not null, x);
}
public Task SetAnimeDataAsync(string key, string data)
@@ -64,7 +64,7 @@ public class RedisCache : IDataCache
{
var _db = Redis.GetDatabase();
string x = await _db.StringGetAsync("novel_" + key);
return (x != null, x);
return (x is not null, x);
}
public Task SetNovelDataAsync(string key, string data)
@@ -156,7 +156,7 @@ public class RedisCache : IDataCache
public bool TryGetEconomy(out string data)
{
var _db = Redis.GetDatabase();
if ((data = _db.StringGet($"{_redisKey}_economy")) != null) return true;
if ((data = _db.StringGet($"{_redisKey}_economy")) is not null) return true;
return false;
}

View File

@@ -132,7 +132,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
return Task.CompletedTask;
};
_botlistTimer = new(async state =>
_botlistTimer = new(async _ =>
{
if (string.IsNullOrWhiteSpace(_creds.BotListToken))
return;

View File

@@ -67,7 +67,7 @@ public class YtdlOperation
process.Start();
string line;
while ((line = await process.StandardOutput.ReadLineAsync()) != null)
while ((line = await process.StandardOutput.ReadLineAsync()) is not null)
yield return line;
}
}