Kotz's editorconfig styles slightly modified. Target typed new usage. Brackets in expressions used for clarity.

This commit is contained in:
Kwoth
2021-12-26 02:52:09 +01:00
parent 68741ec484
commit d18f9429c6
172 changed files with 921 additions and 494 deletions

View File

@@ -13,7 +13,7 @@ public class ExportedExpr
public string[] React;
public static ExportedExpr FromModel(CustomReaction cr)
=> new ExportedExpr()
=> new()
{
Res = cr.Response,
Id = ((kwum)cr.Id).ToString(),

View File

@@ -13,8 +13,8 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
_clientFactory = clientFactory;
}
private bool AdminInGuildOrOwnerInDm() => ctx.Guild is null && _creds.IsOwner(ctx.User)
|| ctx.Guild != null && ((IGuildUser)ctx.User).GuildPermissions.Administrator;
private bool AdminInGuildOrOwnerInDm() => (ctx.Guild is null && _creds.IsOwner(ctx.User))
|| (ctx.Guild != null && ((IGuildUser)ctx.User).GuildPermissions.Administrator);
[NadekoCommand, Aliases]
public async Task AddCustReact(string key, [Leftover] string message)
@@ -33,7 +33,7 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText(strs.new_cust_react))
.WithDescription($"#{(kwum)cr.Id}")
.WithDescription($"#{cr.Id}")
.AddField(GetText(strs.trigger), key)
.AddField(GetText(strs.response), message.Length > 1024 ? GetText(strs.redacted_too_long) : message)
).ConfigureAwait(false);
@@ -46,13 +46,13 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
if (string.IsNullOrWhiteSpace(message) || id < 0)
return;
if (channel is null && !_creds.IsOwner(ctx.User) || channel != null && !((IGuildUser)ctx.User).GuildPermissions.Administrator)
if ((channel is null && !_creds.IsOwner(ctx.User)) || (channel != null && !((IGuildUser)ctx.User).GuildPermissions.Administrator))
{
await ReplyErrorLocalizedAsync(strs.insuff_perms).ConfigureAwait(false);
return;
}
var cr = await _service.EditAsync(ctx.Guild?.Id, (int)id, message).ConfigureAwait(false);
var cr = await _service.EditAsync(ctx.Guild?.Id, id, message).ConfigureAwait(false);
if (cr != null)
{
await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor()
@@ -112,7 +112,7 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
[NadekoCommand, Aliases]
public async Task ShowCustReact(kwum id)
{
var found = _service.GetCustomReaction(ctx.Guild?.Id, (int)id);
var found = _service.GetCustomReaction(ctx.Guild?.Id, id);
if (found is null)
{
@@ -138,7 +138,7 @@ public class CustomReactions : NadekoModule<CustomReactionsService>
return;
}
var cr = await _service.DeleteAsync(ctx.Guild?.Id, (int)id);
var cr = await _service.DeleteAsync(ctx.Guild?.Id, id);
if (cr != null)
{

View File

@@ -22,12 +22,12 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
Message,
}
private readonly object _gcrWriteLock = new object();
private readonly object _gcrWriteLock = new();
private readonly TypedKey<CustomReaction> _gcrAddedKey = new TypedKey<CustomReaction>("gcr.added");
private readonly TypedKey<int> _gcrDeletedkey = new TypedKey<int>("gcr.deleted");
private readonly TypedKey<CustomReaction> _gcrEditedKey = new TypedKey<CustomReaction>("gcr.edited");
private readonly TypedKey<bool> _crsReloadedKey = new TypedKey<bool>("crs.reloaded");
private readonly TypedKey<CustomReaction> _gcrAddedKey = new("gcr.added");
private readonly TypedKey<int> _gcrDeletedkey = new("gcr.deleted");
private readonly TypedKey<CustomReaction> _gcrEditedKey = new("gcr.edited");
private readonly TypedKey<bool> _crsReloadedKey = new("crs.reloaded");
private const string MentionPh = "%bot.mention%";
// it is perfectly fine to have global customreactions as an array
@@ -119,8 +119,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
public Task OnReadyAsync()
=> ReloadInternal(_bot.GetCurrentGuildIds());
private ValueTask OnCrsShouldReload(bool _)
=> new ValueTask(ReloadInternal(_bot.GetCurrentGuildIds()));
private ValueTask OnCrsShouldReload(bool _) => new(ReloadInternal(_bot.GetCurrentGuildIds()));
private ValueTask OnGcrAdded(CustomReaction c)
{
@@ -257,7 +256,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
if (toDelete is null)
return null;
if (toDelete.IsGlobal() && guildId is null || guildId == toDelete.GuildId)
if ((toDelete.IsGlobal() && guildId is null) || guildId == toDelete.GuildId)
{
uow.CustomReactions.Remove(toDelete);
await uow.SaveChangesAsync();
@@ -290,7 +289,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
if (!ready)
return null;
if (!(umsg.Channel is SocketTextChannel channel))
if (umsg.Channel is not SocketTextChannel channel)
return null;
var content = umsg.Content.Trim().ToLowerInvariant();