- More code cleanup and codestyle updates

- Fixed some possible nullref exceptions
- Methods signatures now have up to 3 parameters before breakaing down each parameter in a separate line
- Method invocations have the same rule, except the first parameter will be in the same line as the invocation to prevent some ugliness when passing lambas as arguments
- Applied many more codestyles
- Extensions folder fully reformatted
This commit is contained in:
Kwoth
2021-12-26 17:28:39 +01:00
parent b85ba177cd
commit d5fd6aae8e
217 changed files with 1017 additions and 1494 deletions

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using System.Collections.Immutable;
using System.Collections.Immutable;
using NadekoBot.Common.Configs;
using NadekoBot.Db;
using Discord.Interactions;
@@ -267,7 +266,7 @@ public class CommandHandler : INService
}
public Task<(bool Success, string Error, CommandInfo Info)> ExecuteCommandAsync(CommandContext context, string input, int argPos, IServiceProvider serviceProvider, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)
=> ExecuteCommand(context, input.Substring(argPos), serviceProvider, multiMatchHandling);
=> ExecuteCommand(context, input[argPos..], serviceProvider, multiMatchHandling);
public async Task<(bool Success, string Error, CommandInfo Info)> ExecuteCommand(CommandContext context, string input, IServiceProvider services, MultiMatchHandling multiMatchHandling = MultiMatchHandling.Exception)

View File

@@ -6,9 +6,7 @@ public class GreetGrouper<T>
private readonly object locker = new();
public GreetGrouper()
{
group = new();
}
=> group = new();
/// <summary>

View File

@@ -27,9 +27,7 @@ public class GreetSettingsService : INService
_bss = bss;
_eb = eb;
GuildConfigsCache = new(
bot.AllGuildConfigs
.ToDictionary(g => g.GuildId, GreetSettings.Create));
GuildConfigsCache = new(bot.AllGuildConfigs.ToDictionary(g => g.GuildId, GreetSettings.Create));
_client.UserJoined += UserJoined;
_client.UserLeft += UserLeft;
@@ -326,10 +324,8 @@ public class GreetSettingsService : INService
public async Task<bool> SetSettings(ulong guildId, GreetSettings settings)
{
if (settings.AutoDeleteByeMessagesTimer > 600 ||
settings.AutoDeleteByeMessagesTimer < 0 ||
settings.AutoDeleteGreetMessagesTimer > 600 ||
settings.AutoDeleteGreetMessagesTimer < 0)
if (settings.AutoDeleteByeMessagesTimer is > 600 or < 0 ||
settings.AutoDeleteGreetMessagesTimer is > 600 or < 0)
{
return false;
}
@@ -510,7 +506,7 @@ public class GreetSettingsService : INService
public async Task SetByeDel(ulong guildId, int timer)
{
if (timer < 0 || timer > 600)
if (timer is < 0 or > 600)
return;
await using var uow = _db.GetDbContext();
@@ -525,7 +521,7 @@ public class GreetSettingsService : INService
public async Task SetGreetDel(ulong id, int timer)
{
if (timer < 0 || timer > 600)
if (timer is < 0 or > 600)
return;
await using var uow = _db.GetDbContext();
@@ -555,7 +551,7 @@ public class GreetSettingsService : INService
public async Task SetBoostDel(ulong guildId, int timer)
{
if (timer < 0 || timer > 600)
if (timer is < 0 or > 600)
throw new ArgumentOutOfRangeException(nameof(timer));
await using var uow = _db.GetDbContext();

View File

@@ -13,10 +13,8 @@ public class EmbedBuilderService : IEmbedBuilderService, INService
private readonly BotConfigService _botConfigService;
public EmbedBuilderService(BotConfigService botConfigService)
{
_botConfigService = botConfigService;
}
=> _botConfigService = botConfigService;
public IEmbedBuilder Create(ICommandContext ctx = null)
=> new DiscordEmbedBuilderWrapper(_botConfigService.Data);

View File

@@ -12,9 +12,7 @@ public sealed class BehaviorExecutor : IBehaviourExecutor, INService
private IEnumerable<IInputTransformer> _transformers;
public BehaviorExecutor(IServiceProvider services)
{
_services = services;
}
=> _services = services;
public void Initialize()
{

View File

@@ -60,9 +60,7 @@ public class CurrencyService : ICurrencyService, INService
}
public Task AddAsync(ulong userId, string reason, long amount, bool gamble = false)
{
return InternalAddAsync(userId, null, null, null, reason, amount, gamble);
}
=> InternalAddAsync(userId, null, null, null, reason, amount, gamble);
public async Task AddAsync(IUser user, string reason, long amount, bool sendMessage = false, bool gamble = false)
{
@@ -141,12 +139,8 @@ public class CurrencyService : ICurrencyService, INService
}
public Task<bool> RemoveAsync(ulong userId, string reason, long amount, bool gamble = false)
{
return InternalRemoveAsync(userId, null, null, null, reason, amount, gamble);
}
=> InternalRemoveAsync(userId, null, null, null, reason, amount, gamble);
public Task<bool> RemoveAsync(IUser user, string reason, long amount, bool sendMessage = false, bool gamble = false)
{
return InternalRemoveAsync(user.Id, user.Username, user.Discriminator, user.AvatarId, reason, amount, gamble);
}
=> InternalRemoveAsync(user.Id, user.Username, user.Discriminator, user.AvatarId, reason, amount, gamble);
}

View File

@@ -74,12 +74,10 @@ public class Localization : ILocalization, INService
}
public void SetDefaultCulture(CultureInfo ci)
{
_bss.ModifyConfig(bs =>
=> _bss.ModifyConfig(bs =>
{
bs.DefaultLocale = ci;
});
}
public void ResetDefaultCulture() =>
SetDefaultCulture(CultureInfo.CurrentCulture);

View File

@@ -69,11 +69,8 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor
=> GetByteData(ImageKeys.RipOverlay);
public byte[] GetCard(string key)
{
// since cards are always local for now, don't cache them
return File.ReadAllBytes(Path.Join(_cardsPath, key + ".jpg"));
}
=> File.ReadAllBytes(Path.Join(_cardsPath, key + ".jpg"));
public async Task OnReadyAsync()
{

View File

@@ -82,12 +82,8 @@ public class RedisLocalDataCache : ILocalDataCache
}
private T Get<T>(string key) where T : class
{
return JsonConvert.DeserializeObject<T>(_db.StringGet($"{_creds.RedisKey()}_localdata_{key}"));
}
=> JsonConvert.DeserializeObject<T>(_db.StringGet($"{_creds.RedisKey()}_localdata_{key}"));
private void Set(string key, object obj)
{
_db.StringSet($"{_creds.RedisKey()}_localdata_{key}", JsonConvert.SerializeObject(obj));
}
=> _db.StringSet($"{_creds.RedisKey()}_localdata_{key}", JsonConvert.SerializeObject(obj));
}

View File

@@ -31,12 +31,10 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
}
public void Die(bool graceful)
{
_coordClient.Die(new()
=> _coordClient.Die(new()
{
Graceful = graceful
});
}
public bool RestartShard(int shardId)
{
@@ -71,9 +69,7 @@ public class RemoteGrpcCoordinator : ICoordinator, IReadyExecutor
}
public async Task Reload()
{
await _coordClient.ReloadAsync(new());
}
=> await _coordClient.ReloadAsync(new());
public Task OnReadyAsync()
{

View File

@@ -31,18 +31,13 @@ public class SingleProcessCoordinator : ICoordinator
}
public void Die(bool graceful = false)
{
Environment.Exit(5);
}
=> Environment.Exit(5);
public bool RestartShard(int shardId)
{
return RestartBot();
}
=> RestartBot();
public IList<ShardStatus> GetAllShardStatuses()
{
return new[]
=> new[]
{
new ShardStatus()
{
@@ -52,15 +47,10 @@ public class SingleProcessCoordinator : ICoordinator
ShardId = _client.ShardId
}
};
}
public int GetGuildCount()
{
return _client.Guilds.Count;
}
=> _client.Guilds.Count;
public Task Reload()
{
return Task.CompletedTask;
}
=> Task.CompletedTask;
}

View File

@@ -7,9 +7,7 @@ public class SoundCloudApiService : INService
private readonly IHttpClientFactory _httpFactory;
public SoundCloudApiService(IHttpClientFactory factory)
{
_httpFactory = factory;
}
=> _httpFactory = factory;
public async Task<SoundCloudVideo> ResolveVideoAsync(string url)
{

View File

@@ -8,9 +8,7 @@ public class StartingGuildsService : IEnumerable<ulong>, INService
private readonly ImmutableList<ulong> _guilds;
public StartingGuildsService(DiscordSocketClient client)
{
this._guilds = client.Guilds.Select(x => x.Id).ToImmutableList();
}
=> this._guilds = client.Guilds.Select(x => x.Id).ToImmutableList();
public IEnumerator<ulong> GetEnumerator() =>
_guilds.GetEnumerator();

View File

@@ -9,9 +9,7 @@ public class YtdlOperation
private readonly string _baseArgString;
public YtdlOperation(string baseArgString)
{
_baseArgString = baseArgString;
}
=> _baseArgString = baseArgString;
private Process CreateProcess(string[] args)
{

View File

@@ -44,10 +44,8 @@ public abstract class ConfigServiceBase<TSettings> : IConfigService
}
private void PublishChange()
{
_pubSub.Pub(_changeKey, _data);
}
=> _pubSub.Pub(_changeKey, _data);
private ValueTask OnChangePublished(TSettings newData)
{
_data = newData;

View File

@@ -3,7 +3,5 @@
public static class StandardConversions
{
public static double CelsiusToFahrenheit(double cel)
{
return (cel * 1.8f) + 32;
}
=> (cel * 1.8f) + 32;
}

View File

@@ -90,9 +90,7 @@ public class BotStrings : IBotStrings
}
public void Reload()
{
_stringsProvider.Reload();
}
=> _stringsProvider.Reload();
}
public class CommandStrings