- 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 Microsoft.EntityFrameworkCore;
using NadekoBot.Common.Collections;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;

View File

@@ -155,7 +155,5 @@ public static class GuildConfigExtensions
}
public static void SetAutoAssignableRoles(this GuildConfig gc, IEnumerable<ulong> roles)
{
gc.AutoAssignRoleIds = roles.JoinWith(',');
}
=> gc.AutoAssignRoleIds = roles.Join(',');
}

View File

@@ -33,9 +33,7 @@ DELETE FROM Clubs;";
private readonly DbService _db;
public DangerousCommandsService(DbService db)
{
_db = db;
}
=> _db = db;
public async Task<int> ExecuteSql(string sql)
{

View File

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

View File

@@ -2,7 +2,6 @@
using System.Threading.Channels;
using LinqToDB;
using Microsoft.Extensions.Caching.Memory;
using NadekoBot.Common.Collections;
using NadekoBot.Common.ModuleBehaviors;
namespace NadekoBot.Modules.Administration.Services;

View File

@@ -1,6 +1,5 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Caching.Memory;
using NadekoBot.Common.Collections;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;
using NadekoBot.Modules.Administration.Common;
@@ -23,24 +22,16 @@ public sealed class DummyLogCommandService : ILogCommandService
}
public Task LogServer(ulong guildId, ulong channelId, bool actionValue)
{
return Task.CompletedTask;
}
=> Task.CompletedTask;
public bool LogIgnore(ulong guildId, ulong itemId, IgnoredItemType itemType)
{
return false;
}
=> false;
public LogSetting GetGuildLogSettings(ulong guildId)
{
return default;
}
=> default;
public bool Log(ulong guildId, ulong? channelId, LogType type)
{
return false;
}
=> false;
}
public sealed class LogCommandService : ILogCommandService
@@ -150,9 +141,7 @@ public sealed class LogCommandService : ILogCommandService
}
public void AddDeleteIgnore(ulong messageId)
{
_ignoreMessageIds.Add(messageId);
}
=> _ignoreMessageIds.Add(messageId);
public bool LogIgnore(ulong gid, ulong itemId, IgnoredItemType itemType)
{
@@ -1172,7 +1161,7 @@ public sealed class LogCommandService : ILogCommandService
break;
}
if (!id.HasValue || id == 0)
if (id is null or 0)
{
UnsetLogSetting(guild.Id, logChannelType);
return null;

View File

@@ -1,5 +1,4 @@
using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.Collections;
using NadekoBot.Services.Database.Models;
using NadekoBot.Db;

View File

@@ -317,7 +317,11 @@ public class ProtectionService : INService
{
if (_antiSpamGuilds.TryRemove(guildId, out var removed))
{
removed.UserStats.ForEach(x => x.Value.Dispose());
foreach (var (_, val) in removed.UserStats)
{
val.Dispose();
}
using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)
.ThenInclude(x => x.IgnoredChannels));

View File

@@ -1,22 +1,19 @@
using NadekoBot.Common.Collections;
namespace NadekoBot.Modules.Administration.Services;
namespace NadekoBot.Modules.Administration.Services;
public class PruneService : INService
{
//channelids where prunes are currently occuring
private readonly ConcurrentHashSet<ulong> _pruningGuilds = new();
private readonly TimeSpan twoWeeks = TimeSpan.FromDays(14);
private readonly TimeSpan _twoWeeks = TimeSpan.FromDays(14);
private readonly ILogCommandService _logService;
public PruneService(ILogCommandService logService)
{
this._logService = logService;
}
=> this._logService = logService;
public async Task PruneWhere(ITextChannel channel, int amount, Func<IMessage, bool> predicate)
{
channel.ThrowIfNull(nameof(channel));
ArgumentNullException.ThrowIfNull(channel, nameof(channel));
if (amount <= 0)
throw new ArgumentOutOfRangeException(nameof(amount));
@@ -38,7 +35,7 @@ public class PruneService : INService
{
_logService.AddDeleteIgnore(x.Id);
if (DateTime.UtcNow - x.CreatedAt < twoWeeks)
if (DateTime.UtcNow - x.CreatedAt < _twoWeeks)
bulkDeletable.Add(x);
else
singleDeletable.Add(x);

View File

@@ -135,9 +135,7 @@ public class RoleCommandsService : INService
}
public bool Get(ulong id, out IndexedCollection<ReactionRoleMessage> rrs)
{
return _models.TryGetValue(id, out rrs);
}
=> _models.TryGetValue(id, out rrs);
public bool Add(ulong id, ReactionRoleMessage rrm)
{

View File

@@ -27,9 +27,7 @@ public class SelfAssignedRolesService : INService
}
public SelfAssignedRolesService(DbService db)
{
_db = db;
}
=> _db = db;
public bool AddNew(ulong guildId, IRole role, int group)
{

View File

@@ -123,12 +123,10 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
}
private Timer TimerFromAutoCommand(AutoCommand x)
{
return new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
=> new(async obj => await ExecuteCommand((AutoCommand) obj).ConfigureAwait(false),
x,
x.Interval * 1000,
x.Interval * 1000);
}
private async Task ExecuteCommand(AutoCommand cmd)
{
@@ -366,8 +364,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
}
private void HandleStatusChanges()
{
_pubSub.Sub(_activitySetKey, async data =>
=> _pubSub.Sub(_activitySetKey, async data =>
{
try
{
@@ -378,7 +375,6 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
Log.Warning(ex, "Error setting activity");
}
});
}
public Task SetGameAsync(string game, ActivityType type)
=> _pubSub.Pub(_activitySetKey, new() {Name = game, Link = null, Type = type});

View File

@@ -300,7 +300,7 @@ WHERE GuildId={guildId}
public bool WarnPunish(ulong guildId, int number, PunishmentAction punish, StoopidTime time, IRole role = null)
{
// these 3 don't make sense with time
if ((punish == PunishmentAction.Softban || punish == PunishmentAction.Kick || punish == PunishmentAction.RemoveRoles) && time != null)
if (punish is PunishmentAction.Softban or PunishmentAction.Kick or PunishmentAction.RemoveRoles && time != null)
return false;
if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49)))
return false;
@@ -427,8 +427,7 @@ WHERE GuildId={guildId}
public SmartText GetBanUserDmEmbed(ICommandContext context, IGuildUser target, string defaultMessage,
string banReason, TimeSpan? duration)
{
return GetBanUserDmEmbed(
=> GetBanUserDmEmbed(
(DiscordSocketClient) context.Client,
(SocketGuild) context.Guild,
(IGuildUser) context.User,
@@ -436,7 +435,6 @@ WHERE GuildId={guildId}
defaultMessage,
banReason,
duration);
}
public SmartText GetBanUserDmEmbed(DiscordSocketClient client, SocketGuild guild,
IGuildUser moderator, IGuildUser target, string defaultMessage, string banReason, TimeSpan? duration)