- 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,6 +1,4 @@
using NadekoBot.Modules.Administration.Services;
namespace NadekoBot.Modules.Utility;
namespace NadekoBot.Modules.Utility;
public partial class Utility
{
@@ -9,9 +7,7 @@ public partial class Utility
private readonly IEnumerable<IConfigService> _settingServices;
public ConfigCommands(IEnumerable<IConfigService> settingServices)
{
_settingServices = settingServices;
}
=> _settingServices = settingServices;
[NadekoCommand, Aliases]
[OwnerOnly]

View File

@@ -54,7 +54,7 @@ public partial class Utility
var embed = _eb.Create().WithOkColor();
foreach (var inv in invites)
{
var expiryString = inv.MaxAge is null || inv.MaxAge == 0 || inv.CreatedAt is null
var expiryString = inv.MaxAge is null or 0 || inv.CreatedAt is null
? "∞"
: (inv.CreatedAt.Value.AddSeconds(inv.MaxAge.Value).UtcDateTime - DateTime.UtcNow)
.ToString(@"d\.hh\:mm\:ss");

View File

@@ -103,15 +103,13 @@ public partial class Utility
}
private async Task ShowQuoteData(Quote data)
{
await ctx.Channel.EmbedAsync(_eb.Create(ctx)
=> await ctx.Channel.EmbedAsync(_eb.Create(ctx)
.WithOkColor()
.WithTitle(GetText(strs.quote_id($"#{data.Id}")))
.AddField(GetText(strs.trigger), data.Keyword)
.AddField(GetText(strs.response), Format.Sanitize(data.Text).Replace("](", "]\\("))
.WithFooter(GetText(strs.created_by($"{data.AuthorName} ({data.AuthorId})")))
).ConfigureAwait(false);
}
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]

View File

@@ -175,11 +175,11 @@ public partial class Utility
private string GetRepeaterInfoString(RunningRepeater runner)
{
var intervalString = Format.Bold(runner.Repeater.Interval.ToPrettyStringHM());
var intervalString = Format.Bold(runner.Repeater.Interval.ToPrettyStringHm());
var executesIn = runner.NextTime < DateTime.UtcNow
? TimeSpan.Zero
: runner.NextTime - DateTime.UtcNow;
var executesInString = Format.Bold(executesIn.ToPrettyStringHM());
var executesInString = Format.Bold(executesIn.ToPrettyStringHm());
var message = Format.Sanitize(runner.Repeater.Message.TrimTo(50));
var description = string.Empty;

View File

@@ -99,7 +99,7 @@ public class RemindService : INService
foreach (var groupName in _regex.GetGroupNames())
{
if (groupName == "0" || groupName== "what") continue;
if (groupName is "0" or "what") continue;
if (string.IsNullOrWhiteSpace(m.Groups[groupName].Value))
{
values[groupName] = 0;

View File

@@ -2,7 +2,6 @@
using Microsoft.EntityFrameworkCore;
using LinqToDB;
using LinqToDB.EntityFrameworkCore;
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models;
@@ -418,7 +417,5 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
}
public bool IsNoRedundant(int repeaterId)
{
return _noRedundant.Contains(repeaterId);
}
=> _noRedundant.Contains(repeaterId);
}

View File

@@ -16,10 +16,8 @@ public sealed class RunningRepeater
}
public void UpdateNextTime()
{
NextTime = DateTime.UtcNow + Repeater.Interval;
}
=> NextTime = DateTime.UtcNow + Repeater.Interval;
private DateTime CalculateInitialExecution()
{
if (Repeater.StartTimeOfDay != null)
@@ -93,12 +91,8 @@ public sealed class RunningRepeater
}
public override bool Equals(object obj)
{
return obj is RunningRepeater rr && rr.Repeater.Id == this.Repeater.Id;
}
=> obj is RunningRepeater rr && rr.Repeater.Id == this.Repeater.Id;
public override int GetHashCode()
{
return this.Repeater.Id;
}
=> this.Repeater.Id;
}

View File

@@ -60,7 +60,7 @@ public class StreamRoleService : INService
/// <returns>Whether the operation was successful</returns>
public async Task<bool> ApplyListAction(StreamRoleListType listType, IGuild guild, AddRemove action, ulong userId, string userName)
{
userName.ThrowIfNull(nameof(userName));
ArgumentNullException.ThrowIfNull(userName, nameof(userName));
var success = false;
await using (var uow = _db.GetDbContext())
@@ -170,8 +170,8 @@ public class StreamRoleService : INService
/// <param name="addRole">Role to add to the user</param>
public async Task SetStreamRole(IRole fromRole, IRole addRole)
{
fromRole.ThrowIfNull(nameof(fromRole));
addRole.ThrowIfNull(nameof(addRole));
ArgumentNullException.ThrowIfNull(fromRole, nameof(fromRole));
ArgumentNullException.ThrowIfNull(addRole, nameof(addRole));
StreamRoleSettings setting;
await using (var uow = _db.GetDbContext())
@@ -304,7 +304,5 @@ public class StreamRoleService : INService
}
private void UpdateCache(ulong guildId, StreamRoleSettings setting)
{
guildSettings.AddOrUpdate(guildId, key => setting, (key, old) => setting);
}
=> guildSettings.AddOrUpdate(guildId, key => setting, (key, old) => setting);
}

View File

@@ -1,5 +1,4 @@
using NadekoBot.Common.Collections;
using NadekoBot.Modules.Help.Services;
using NadekoBot.Modules.Help.Services;
using NadekoBot.Db;
namespace NadekoBot.Modules.Utility.Services;

View File

@@ -154,23 +154,17 @@ public partial class Utility : NadekoModule
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task RoleId([Leftover] IRole role)
{
await ReplyConfirmLocalizedAsync(strs.roleid("🆔", Format.Bold(role.ToString()),
=> await ReplyConfirmLocalizedAsync(strs.roleid("🆔", Format.Bold(role.ToString()),
Format.Code(role.Id.ToString())));
}
[NadekoCommand, Aliases]
public async Task ChannelId()
{
await ReplyConfirmLocalizedAsync(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString())));
}
=> await ReplyConfirmLocalizedAsync(strs.channelid("🆔", Format.Code(ctx.Channel.Id.ToString())));
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ServerId()
{
await ReplyConfirmLocalizedAsync(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString())));
}
=> await ReplyConfirmLocalizedAsync(strs.serverid("🆔", Format.Code(ctx.Guild.Id.ToString())));
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
@@ -180,7 +174,7 @@ public partial class Utility : NadekoModule
const int rolesPerPage = 20;
if (page < 1 || page > 100)
if (page is < 1 or > 100)
return;
if (target != null)