diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 0f0e9df03..869dc5879 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -226,7 +226,7 @@ public sealed class Bot clientReady.TrySetResult(true); try { - foreach (var chan in (await Client.GetDMChannelsAsync().ConfigureAwait(false))) + foreach (var chan in await Client.GetDMChannelsAsync().ConfigureAwait(false)) { await chan.CloseAsync().ConfigureAwait(false); } @@ -281,7 +281,7 @@ public sealed class Bot GuildConfig gc; await using (var uow = _db.GetDbContext()) { - gc = uow.GuildConfigsForId(arg.Id); + gc = uow.GuildConfigsForId(arg.Id, null); } await JoinedGuild.Invoke(gc).ConfigureAwait(false); }); diff --git a/src/NadekoBot/Common/Attributes/OwnerOnlyAttribute.cs b/src/NadekoBot/Common/Attributes/OwnerOnlyAttribute.cs index 88c49877b..ae9d884b7 100644 --- a/src/NadekoBot/Common/Attributes/OwnerOnlyAttribute.cs +++ b/src/NadekoBot/Common/Attributes/OwnerOnlyAttribute.cs @@ -13,6 +13,6 @@ public sealed class OwnerOnlyAttribute : PreconditionAttribute { var creds = services.GetRequiredService().GetCreds(); - return Task.FromResult((creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner"))); + return Task.FromResult(creds.IsOwner(context.User) || context.Client.CurrentUser.Id == context.User.Id ? PreconditionResult.FromSuccess() : PreconditionResult.FromError("Not owner")); } } \ No newline at end of file diff --git a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs b/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs index 35934791a..17538d18f 100644 --- a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs +++ b/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs @@ -345,7 +345,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ICollection : IReadOnlyCollection, ICollection (now - old) > TimeSpan.FromHours(1) ? now : old); + (key, old) => now - old > TimeSpan.FromHours(1) ? now : old); // means that this entry was just added - download the users if (added == now) diff --git a/src/NadekoBot/Common/NadekoModule.cs b/src/NadekoBot/Common/NadekoModule.cs index 5c8d56a58..b533c7df1 100644 --- a/src/NadekoBot/Common/NadekoModule.cs +++ b/src/NadekoBot/Common/NadekoModule.cs @@ -99,7 +99,7 @@ public abstract class NadekoModule : ModuleBase { dsc.MessageReceived += MessageReceived; - if ((await Task.WhenAny(userInputTask.Task, Task.Delay(10000)).ConfigureAwait(false)) != userInputTask.Task) + if (await Task.WhenAny(userInputTask.Task, Task.Delay(10000)).ConfigureAwait(false) != userInputTask.Task) { return null; } diff --git a/src/NadekoBot/Common/NadekoRandom.cs b/src/NadekoBot/Common/NadekoRandom.cs index 505b76605..2f928c486 100644 --- a/src/NadekoBot/Common/NadekoRandom.cs +++ b/src/NadekoBot/Common/NadekoRandom.cs @@ -36,7 +36,7 @@ public class NadekoRandom : Random var bytes = new byte[sizeof(int)]; _rng.GetBytes(bytes); var sign = Math.Sign(BitConverter.ToInt32(bytes, 0)); - return (sign * BitConverter.ToInt32(bytes, 0)) % (maxValue - minValue) + minValue; + return sign * BitConverter.ToInt32(bytes, 0) % (maxValue - minValue) + minValue; } public long NextLong(long minValue, long maxValue) @@ -48,7 +48,7 @@ public class NadekoRandom : Random var bytes = new byte[sizeof(long)]; _rng.GetBytes(bytes); var sign = Math.Sign(BitConverter.ToInt64(bytes, 0)); - return (sign * BitConverter.ToInt64(bytes, 0)) % (maxValue - minValue) + minValue; + return sign * BitConverter.ToInt64(bytes, 0) % (maxValue - minValue) + minValue; } public override void NextBytes(byte[] buffer) diff --git a/src/NadekoBot/Common/PlatformHelper.cs b/src/NadekoBot/Common/PlatformHelper.cs index 51dadda29..a8f9d9549 100644 --- a/src/NadekoBot/Common/PlatformHelper.cs +++ b/src/NadekoBot/Common/PlatformHelper.cs @@ -10,7 +10,7 @@ public static class PlatformHelper public static int ProcessorCount { get { var now = Environment.TickCount; - if (_processorCount == 0 || (now - _lastProcessorCountRefreshTicks) >= ProcessorCountRefreshIntervalMs) + if (_processorCount == 0 || now - _lastProcessorCountRefreshTicks >= ProcessorCountRefreshIntervalMs) { _processorCount = Environment.ProcessorCount; _lastProcessorCountRefreshTicks = now; diff --git a/src/NadekoBot/Common/SmartText/SmartEmbedText.cs b/src/NadekoBot/Common/SmartText/SmartEmbedText.cs index ca62655f8..564b7a8e0 100644 --- a/src/NadekoBot/Common/SmartText/SmartEmbedText.cs +++ b/src/NadekoBot/Common/SmartText/SmartEmbedText.cs @@ -24,7 +24,7 @@ public sealed record SmartEmbedText : SmartText !string.IsNullOrWhiteSpace(Url) || !string.IsNullOrWhiteSpace(Thumbnail) || !string.IsNullOrWhiteSpace(Image) || - (Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl))) || + Footer != null && (!string.IsNullOrWhiteSpace(Footer.Text) || !string.IsNullOrWhiteSpace(Footer.IconUrl)) || Fields is { Length: > 0 }; public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null) diff --git a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs index 07c710e55..a5103c091 100644 --- a/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/ShmartNumberTypeReader.cs @@ -37,7 +37,7 @@ public sealed class ShmartNumberTypeReader : NadekoTypeReader { var expr = new NCalc.Expression(i, NCalc.EvaluateOptions.IgnoreCase); expr.EvaluateParameter += (str, ev) => EvaluateParam(str, ev, context); - var lon = (long)(decimal.Parse(expr.Evaluate().ToString())); + var lon = (long)decimal.Parse(expr.Evaluate().ToString()); return TypeReaderResult.FromSuccess(new ShmartNumber(lon, input)); } catch (Exception) diff --git a/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs b/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs index 65a29a1e6..22e6e593e 100644 --- a/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs +++ b/src/NadekoBot/Db/Extensions/DiscordUserExtensions.cs @@ -48,11 +48,11 @@ public static class DiscordUserExtensions public static int GetUserGlobalRank(this DbSet users, ulong id) { return users.AsQueryable() - .Where(x => x.TotalXp > (users + .Where(x => x.TotalXp > users .AsQueryable() .Where(y => y.UserId == id) .Select(y => y.TotalXp) - .FirstOrDefault())) + .FirstOrDefault()) .Count() + 1; } diff --git a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs index 36eec3ff0..d0c3658c0 100644 --- a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs @@ -69,10 +69,11 @@ public static class GuildConfigExtensions /// /// Gets and creates if it doesn't exist a config for a guild. /// - /// For which guild - /// Use to manipulate the set however you want + /// Context + /// Id of the guide + /// Use to manipulate the set however you want. Pass null to include everything /// Config for the guild - public static GuildConfig GuildConfigsForId(this NadekoContext ctx, ulong guildId, Func, IQueryable> includes = null) + public static GuildConfig GuildConfigsForId(this NadekoContext ctx, ulong guildId, Func, IQueryable> includes) { GuildConfig config; @@ -91,13 +92,13 @@ public static class GuildConfigExtensions if (config is null) { - ctx.GuildConfigs.Add((config = new() + ctx.GuildConfigs.Add(config = new() { GuildId = guildId, Permissions = Permissionv2.GetDefaultPermlist, WarningsInitialized = true, WarnPunishments = DefaultWarnPunishments, - })); + }); ctx.SaveChanges(); } @@ -150,11 +151,11 @@ public static class GuildConfigExtensions if (config is null) // if there is no guildconfig, create new one { - ctx.GuildConfigs.Add((config = new() + ctx.GuildConfigs.Add(config = new() { GuildId = guildId, Permissions = Permissionv2.GetDefaultPermlist - })); + }); ctx.SaveChanges(); } else if (config.Permissions is null || !config.Permissions.Any()) // if no perms, add default ones diff --git a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs index 0a7eb2736..c04d44c16 100644 --- a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs +++ b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs @@ -60,12 +60,11 @@ public static class UserXpExtensions return xps .AsQueryable() .AsNoTracking() - .Where(x => x.GuildId == guildId && ((x.Xp + x.AwardedXp) > - (xps.AsQueryable() - .Where(y => y.UserId == userId && y.GuildId == guildId) - .Select(y => y.Xp + y.AwardedXp) - .FirstOrDefault()) - )) + .Where(x => x.GuildId == guildId && x.Xp + x.AwardedXp > + xps.AsQueryable() + .Where(y => y.UserId == userId && y.GuildId == guildId) + .Select(y => y.Xp + y.AwardedXp) + .FirstOrDefault()) .Count() + 1; } diff --git a/src/NadekoBot/Modules/Administration/Common/UserSpamStats.cs b/src/NadekoBot/Modules/Administration/Common/UserSpamStats.cs index d6893d70f..c28158750 100644 --- a/src/NadekoBot/Modules/Administration/Common/UserSpamStats.cs +++ b/src/NadekoBot/Modules/Administration/Common/UserSpamStats.cs @@ -25,7 +25,7 @@ public sealed class UserSpamStats : IDisposable lock (applyLock) { var upperMsg = message.Content.ToUpperInvariant(); - if (upperMsg != LastMessage || (string.IsNullOrWhiteSpace(upperMsg) && message.Attachments.Any())) + if (upperMsg != LastMessage || string.IsNullOrWhiteSpace(upperMsg) && message.Attachments.Any()) { LastMessage = upperMsg; while (timers.TryDequeue(out var old)) diff --git a/src/NadekoBot/Modules/Administration/RoleCommands.cs b/src/NadekoBot/Modules/Administration/RoleCommands.cs index f642a8acd..8e824d811 100644 --- a/src/NadekoBot/Modules/Administration/RoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/RoleCommands.cs @@ -154,7 +154,7 @@ public partial class Administration } else { - var g = ((SocketGuild)ctx.Guild); + var g = (SocketGuild)ctx.Guild; foreach (var rr in rrs) { var ch = g.GetTextChannel(rr.ChannelId); @@ -164,7 +164,7 @@ public partial class Administration msg = await ch.GetMessageAsync(rr.MessageId).ConfigureAwait(false) as IUserMessage; } var content = msg?.Content.TrimTo(30) ?? "DELETED!"; - embed.AddField($"**{rr.Index + 1}.** {(ch?.Name ?? "DELETED!")}", + embed.AddField($"**{rr.Index + 1}.** {ch?.Name ?? "DELETED!"}", GetText(strs.reaction_roles_message(rr.ReactionRoles?.Count ?? 0, content))); } } @@ -197,7 +197,7 @@ public partial class Administration { var runnerUser = (IGuildUser)ctx.User; var runnerMaxRolePosition = runnerUser.GetRoles().Max(x => x.Position); - if ((ctx.User.Id != ctx.Guild.OwnerId) && runnerMaxRolePosition <= roleToAdd.Position) + if (ctx.User.Id != ctx.Guild.OwnerId && runnerMaxRolePosition <= roleToAdd.Position) return; try { @@ -271,7 +271,7 @@ public partial class Administration .Where(x => !x.IsManaged && x != x.Guild.EveryoneRole) .ToList(); - if (user.Id == ctx.Guild.OwnerId || (ctx.User.Id != ctx.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position))) + if (user.Id == ctx.Guild.OwnerId || ctx.User.Id != ctx.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= userRoles.Max(x => x.Position)) return; try { diff --git a/src/NadekoBot/Modules/Administration/Services/ImageOnlyChannelService.cs b/src/NadekoBot/Modules/Administration/Services/ImageOnlyChannelService.cs index 0845d997a..6ca998c06 100644 --- a/src/NadekoBot/Modules/Administration/Services/ImageOnlyChannelService.cs +++ b/src/NadekoBot/Modules/Administration/Services/ImageOnlyChannelService.cs @@ -81,8 +81,8 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior var newState = false; using var uow = _db.GetDbContext(); if (forceDisable - || (_enabledOn.TryGetValue(guildId, out var channels) - && channels.TryRemove(channelId))) + || _enabledOn.TryGetValue(guildId, out var channels) + && channels.TryRemove(channelId)) { uow.ImageOnlyChannels.Delete(x => x.ChannelId == channelId); } diff --git a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs index 58374222a..5613a6ace 100644 --- a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs @@ -225,7 +225,7 @@ public sealed class LogCommandService : ILogCommandService logSetting.LogVoicePresenceId = logSetting.UserMutedId = logSetting.LogVoicePresenceTTSId = - (value ? channelId : (ulong?) null); + value ? channelId : (ulong?) null; ; await uow.SaveChangesAsync(); GuildLogSettings.AddOrUpdate(guildId, id => logSetting, (id, old) => logSetting); @@ -244,7 +244,7 @@ public sealed class LogCommandService : ILogCommandService var g = after.Guild; if (!GuildLogSettings.TryGetValue(g.Id, out var logSetting) - || (logSetting.UserUpdatedId is null)) + || logSetting.UserUpdatedId is null) return; ITextChannel logChannel; @@ -303,54 +303,54 @@ public sealed class LogCommandService : ILogCommandService switch (type) { case LogType.Other: - channelId = logSetting.LogOtherId = (logSetting.LogOtherId is null ? cid : default); + channelId = logSetting.LogOtherId = logSetting.LogOtherId is null ? cid : default; break; case LogType.MessageUpdated: - channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId is null ? cid : default); + channelId = logSetting.MessageUpdatedId = logSetting.MessageUpdatedId is null ? cid : default; break; case LogType.MessageDeleted: - channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId is null ? cid : default); + channelId = logSetting.MessageDeletedId = logSetting.MessageDeletedId is null ? cid : default; //logSetting.DontLogBotMessageDeleted = (options == "nobot"); break; case LogType.UserJoined: - channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId is null ? cid : default); + channelId = logSetting.UserJoinedId = logSetting.UserJoinedId is null ? cid : default; break; case LogType.UserLeft: - channelId = logSetting.UserLeftId = (logSetting.UserLeftId is null ? cid : default); + channelId = logSetting.UserLeftId = logSetting.UserLeftId is null ? cid : default; break; case LogType.UserBanned: - channelId = logSetting.UserBannedId = (logSetting.UserBannedId is null ? cid : default); + channelId = logSetting.UserBannedId = logSetting.UserBannedId is null ? cid : default; break; case LogType.UserUnbanned: - channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId is null ? cid : default); + channelId = logSetting.UserUnbannedId = logSetting.UserUnbannedId is null ? cid : default; break; case LogType.UserUpdated: - channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId is null ? cid : default); + channelId = logSetting.UserUpdatedId = logSetting.UserUpdatedId is null ? cid : default; break; case LogType.UserMuted: - channelId = logSetting.UserMutedId = (logSetting.UserMutedId is null ? cid : default); + channelId = logSetting.UserMutedId = logSetting.UserMutedId is null ? cid : default; break; case LogType.ChannelCreated: - channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId is null ? cid : default); + channelId = logSetting.ChannelCreatedId = logSetting.ChannelCreatedId is null ? cid : default; break; case LogType.ChannelDestroyed: channelId = logSetting.ChannelDestroyedId = - (logSetting.ChannelDestroyedId is null ? cid : default); + logSetting.ChannelDestroyedId is null ? cid : default; break; case LogType.ChannelUpdated: - channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId is null ? cid : default); + channelId = logSetting.ChannelUpdatedId = logSetting.ChannelUpdatedId is null ? cid : default; break; case LogType.UserPresence: channelId = logSetting.LogUserPresenceId = - (logSetting.LogUserPresenceId is null ? cid : default); + logSetting.LogUserPresenceId is null ? cid : default; break; case LogType.VoicePresence: channelId = logSetting.LogVoicePresenceId = - (logSetting.LogVoicePresenceId is null ? cid : default); + logSetting.LogVoicePresenceId is null ? cid : default; break; case LogType.VoicePresenceTTS: channelId = logSetting.LogVoicePresenceTTSId = - (logSetting.LogVoicePresenceTTSId is null ? cid : default); + logSetting.LogVoicePresenceTTSId is null ? cid : default; break; } @@ -376,7 +376,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.LogVoicePresenceTTSId is null)) + || logSetting.LogVoicePresenceTTSId is null) return; ITextChannel logChannel; @@ -416,7 +416,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.UserMutedId is null)) + || logSetting.UserMutedId is null) return; ITextChannel logChannel; @@ -460,7 +460,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.UserMutedId is null)) + || logSetting.UserMutedId is null) return; ITextChannel logChannel; @@ -512,7 +512,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out var logSetting) - || (logSetting.LogOtherId is null)) + || logSetting.LogOtherId is null) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other) @@ -681,7 +681,7 @@ public sealed class LogCommandService : ILogCommandService var after = (IGuildChannel) cafter; if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting) - || (logSetting.ChannelUpdatedId is null) + || logSetting.ChannelUpdatedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -732,7 +732,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) - || (logSetting.ChannelDestroyedId is null) + || logSetting.ChannelDestroyedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == ch.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -817,7 +817,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.LogVoicePresenceId is null) + || logSetting.LogVoicePresenceId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == iusr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -870,7 +870,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.UserLeftId is null) + || logSetting.UserLeftId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -905,7 +905,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) - || (logSetting.UserJoinedId is null)) + || logSetting.UserJoinedId is null) return; ITextChannel logChannel; @@ -946,7 +946,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting) - || (logSetting.UserUnbannedId is null) + || logSetting.UserUnbannedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -981,7 +981,7 @@ public sealed class LogCommandService : ILogCommandService try { if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting) - || (logSetting.UserBannedId is null) + || logSetting.UserBannedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -1029,7 +1029,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting) - || (logSetting.MessageDeletedId is null) + || logSetting.MessageDeletedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -1087,7 +1087,7 @@ public sealed class LogCommandService : ILogCommandService return; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting) - || (logSetting.MessageUpdatedId is null) + || logSetting.MessageUpdatedId is null || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel)) return; diff --git a/src/NadekoBot/Modules/Administration/Services/MuteService.cs b/src/NadekoBot/Modules/Administration/Services/MuteService.cs index 16b3abf5c..9b5c04244 100644 --- a/src/NadekoBot/Modules/Administration/Services/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Services/MuteService.cs @@ -299,7 +299,7 @@ public class MuteService : INService } } - foreach (var toOverwrite in (await guild.GetTextChannelsAsync().ConfigureAwait(false))) + foreach (var toOverwrite in await guild.GetTextChannelsAsync().ConfigureAwait(false)) { try { diff --git a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs index bca1c123f..fd6f2faa0 100644 --- a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs @@ -190,7 +190,7 @@ public class RoleCommandsService : INService { var toAdd = user.Guild.GetRole(dbRero.RoleId); - return (toAdd != null && !user.Roles.Contains(toAdd)) + return toAdd != null && !user.Roles.Contains(toAdd) ? user.AddRoleAsync(toAdd) : Task.CompletedTask; } diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index 0841178b7..844842183 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -320,7 +320,7 @@ WHERE GuildId={guildId} // these 3 don't make sense with time if ((punish == PunishmentAction.Softban || punish == PunishmentAction.Kick || punish == PunishmentAction.RemoveRoles) && time != null) return false; - if (number <= 0 || (time != null && time.Time > TimeSpan.FromDays(49))) + if (number <= 0 || time != null && time.Time > TimeSpan.FromDays(49)) return false; using (var uow = _db.GetDbContext()) @@ -334,7 +334,7 @@ WHERE GuildId={guildId} { Count = number, Punishment = punish, - Time = (int?)(time?.Time.TotalMinutes) ?? 0, + Time = (int?)time?.Time.TotalMinutes ?? 0, RoleId = punish == PunishmentAction.AddRole ? role.Id : default(ulong?), }); uow.SaveChanges(); diff --git a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs index fd81aafeb..2c67ff407 100644 --- a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs @@ -37,7 +37,7 @@ public partial class Administration // bot can't punish a user who is higher in the hierarchy. Discord will return 403 // moderator can be owner, in which case role hierarchy doesn't matter // otherwise, moderator has to have a higher role - if ((botMaxRole <= targetMaxRole || (ctx.User.Id != ownerId && targetMaxRole >= modMaxRole)) || target.Id == ownerId) + if (botMaxRole <= targetMaxRole || ctx.User.Id != ownerId && targetMaxRole >= modMaxRole || target.Id == ownerId) { await ReplyErrorLocalizedAsync(strs.hierarchy); return false; diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index e3cd6d0f9..0412dadac 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -20,8 +20,8 @@ public class CustomReactions : NadekoModule _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) @@ -53,7 +53,7 @@ public class CustomReactions : NadekoModule 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; diff --git a/src/NadekoBot/Modules/CustomReactions/Extensions/CustomReactionExtensions.cs b/src/NadekoBot/Modules/CustomReactions/Extensions/CustomReactionExtensions.cs index f73a55fd1..042f01851 100644 --- a/src/NadekoBot/Modules/CustomReactions/Extensions/CustomReactionExtensions.cs +++ b/src/NadekoBot/Modules/CustomReactions/Extensions/CustomReactionExtensions.cs @@ -60,7 +60,7 @@ public static class CustomReactionExtensions if (word.Length < str.Length && str.isValidWordDivider(word.Length)) return WordPosition.Start; } - else if ((wordIndex + word.Length) == str.Length) + else if (wordIndex + word.Length == str.Length) { if (str.isValidWordDivider(wordIndex - 1)) return WordPosition.End; diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index 8b26f6db8..601e39b83 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -264,7 +264,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(); diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs index ac3c61131..72e63350d 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs @@ -78,7 +78,7 @@ public partial class Gambling GetText(strs.animal_race_won_money( Format.Bold(winner.Username), winner.Animal.Icon, - (race.FinishedUsers[0].Bet * (race.Users.Count - 1)) + CurrencySign))); + race.FinishedUsers[0].Bet * (race.Users.Count - 1) + CurrencySign))); } else { @@ -111,7 +111,7 @@ public partial class Gambling {String.Join("\n", race.Users.Select(p => { var index = race.FinishedUsers.IndexOf(p); - var extra = (index == -1 ? "" : $"#{index + 1} {(index == 0 ? "🏆" : "")}"); + var extra = index == -1 ? "" : $"#{index + 1} {(index == 0 ? "🏆" : "")}"; return $"{(int)(p.Progress / 60f * 100),-2}%|{new string('‣', p.Progress) + p.Animal.Icon + extra}"; }))} |🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🏁🔚|"; diff --git a/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs b/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs index 6ca6b7dd2..26455875f 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs @@ -179,7 +179,7 @@ public class Blackjack { var hw = Dealer.GetHandValue(); while (hw < 17 - || (hw == 17 && Dealer.Cards.Count(x => x.Number == 1) > (Dealer.GetRawHandValue() - 17) / 10))// hit on soft 17 + || hw == 17 && Dealer.Cards.Count(x => x.Number == 1) > (Dealer.GetRawHandValue() - 17) / 10)// hit on soft 17 { /* Dealer has A 6 diff --git a/src/NadekoBot/Modules/Gambling/Common/Deck.cs b/src/NadekoBot/Modules/Gambling/Common/Deck.cs index 7d1f89e64..d8dd7a476 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Deck.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Deck.cs @@ -252,13 +252,13 @@ public class Deck { if (cards.GroupBy(card => card.Number).Count() != cards.Count()) return false; - var toReturn = (cards.Max(card => (int)card.Number) - - cards.Min(card => (int)card.Number) == 4); + var toReturn = cards.Max(card => (int)card.Number) + - cards.Min(card => (int)card.Number) == 4; if (toReturn || cards.All(c => c.Number != 1)) return toReturn; var newCards = cards.Select(c => c.Number == 1 ? new(c.Suit, 14) : c); - return (newCards.Max(card => (int)card.Number) - - newCards.Min(card => (int)card.Number) == 4); + return newCards.Max(card => (int)card.Number) + - newCards.Min(card => (int)card.Number) == 4; } bool hasThreeOfKind(List cards) => cards.GroupBy(card => card.Number) diff --git a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs index fa77ce788..f219dedda 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs @@ -167,8 +167,8 @@ public class ReactionEvent : ICurrencyEvent || msg.Id != _msg.Id // same message || gu.IsBot // no bots || (DateTime.UtcNow - gu.CreatedAt).TotalDays <= 5 // no recently created accounts - || (_noRecentlyJoinedServer && // if specified, no users who joined the server in the last 24h - (gu.JoinedAt is null || (DateTime.UtcNow - gu.JoinedAt.Value).TotalDays < 1))) // and no users for who we don't know when they joined + || _noRecentlyJoinedServer && // if specified, no users who joined the server in the last 24h + (gu.JoinedAt is null || (DateTime.UtcNow - gu.JoinedAt.Value).TotalDays < 1)) // and no users for who we don't know when they joined { return; } diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs index 7bcd00a0d..82430ff0b 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs @@ -158,8 +158,8 @@ public sealed class Connect4Game : IDisposable if (CurrentPhase == Phase.Ended || CurrentPhase == Phase.Joining) return false; - if (!((_players[0].Value.UserId == userId && CurrentPhase == Phase.P1Move) - || (_players[1].Value.UserId == userId && CurrentPhase == Phase.P2Move))) + if (!(_players[0].Value.UserId == userId && CurrentPhase == Phase.P1Move + || _players[1].Value.UserId == userId && CurrentPhase == Phase.P2Move)) return false; if (inputCol < 0 || inputCol > NumberOfColumns) //invalid input diff --git a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs index 2737ebf89..9d50a4dce 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs @@ -185,7 +185,7 @@ public partial class Gambling { for (var j = 0; j < Connect4Game.NumberOfColumns; j++) { - var cur = game.GameState[i + (j * Connect4Game.NumberOfRows) - 1]; + var cur = game.GameState[i + j * Connect4Game.NumberOfRows - 1]; if (cur == Connect4Game.Field.Empty) sb.Append("⚫"); //black circle diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 6d06eb99d..cf5547cfe 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -65,8 +65,8 @@ public partial class Gambling : GamblingModule .WithTitle(GetText(strs.economy_state)) .AddField(GetText(strs.currency_owned), ((BigInteger)(ec.Cash - ec.Bot)).ToString("N", _enUsCulture) + CurrencySign) .AddField(GetText(strs.currency_one_percent), (onePercent * 100).ToString("F2") + "%") - .AddField(GetText(strs.currency_planted), ((BigInteger)ec.Planted) + CurrencySign) - .AddField(GetText(strs.owned_waifus_total), ((BigInteger)ec.Waifus) + CurrencySign) + .AddField(GetText(strs.currency_planted), (BigInteger)ec.Planted + CurrencySign) + .AddField(GetText(strs.owned_waifus_total), (BigInteger)ec.Waifus + CurrencySign) .AddField(GetText(strs.bot_currency), ec.Bot.ToString("N", _enUsCulture) + CurrencySign) .AddField(GetText(strs.total), ((BigInteger)(ec.Cash + ec.Planted + ec.Waifus)).ToString("N", _enUsCulture) + CurrencySign) .WithOkColor(); @@ -146,7 +146,7 @@ public partial class Gambling : GamblingModule { role = role ?? ctx.Guild.EveryoneRole; - var members = (await role.GetMembersAsync().ConfigureAwait(false)); + var members = await role.GetMembersAsync().ConfigureAwait(false); var membersArray = members as IUser[] ?? members.ToArray(); if (membersArray.Length == 0) { @@ -271,9 +271,9 @@ public partial class Gambling : GamblingModule } await _cs.AddAsync(usr, - $"Awarded by bot owner. ({ctx.User.Username}/{ctx.User.Id}) {(msg ?? "")}", + $"Awarded by bot owner. ({ctx.User.Username}/{ctx.User.Id}) {msg ?? ""}", amount, - gamble: (ctx.Client.CurrentUser.Id != usrId)).ConfigureAwait(false); + gamble: ctx.Client.CurrentUser.Id != usrId).ConfigureAwait(false); await ReplyConfirmLocalizedAsync(strs.awarded(n(amount) + CurrencySign, $"<@{usrId}>")); } @@ -329,7 +329,7 @@ public partial class Gambling : GamblingModule return; if (await _cs.RemoveAsync(user, $"Taken by bot owner.({ctx.User.Username}/{ctx.User.Id})", amount, - gamble: (ctx.Client.CurrentUser.Id != user.Id)).ConfigureAwait(false)) + gamble: ctx.Client.CurrentUser.Id != user.Id).ConfigureAwait(false)) await ReplyConfirmLocalizedAsync(strs.take(n(amount) + CurrencySign, Format.Bold(user.ToString()))).ConfigureAwait(false); else await ReplyErrorLocalizedAsync(strs.take_fail(n(amount) + CurrencySign, Format.Bold(user.ToString()), CurrencySign)); @@ -344,7 +344,7 @@ public partial class Gambling : GamblingModule return; if (await _cs.RemoveAsync(usrId, $"Taken by bot owner.({ctx.User.Username}/{ctx.User.Id})", amount, - gamble: (ctx.Client.CurrentUser.Id != usrId)).ConfigureAwait(false)) + gamble: ctx.Client.CurrentUser.Id != usrId).ConfigureAwait(false)) await ReplyConfirmLocalizedAsync(strs.take(amount + CurrencySign, $"<@{usrId}>")); else await ReplyErrorLocalizedAsync(strs.take_fail(amount + CurrencySign, Format.Code(usrId.ToString()), CurrencySign)); @@ -440,7 +440,7 @@ public partial class Gambling : GamblingModule var winner = rdGame.Winner == rdGame.P1 ? ctx.User : u; - description += $"\n**{winner}** Won {n(((long)(rdGame.Amount * 2 * 0.98))) + CurrencySign}"; + description += $"\n**{winner}** Won {n((long)(rdGame.Amount * 2 * 0.98)) + CurrencySign}"; embed = embed.WithDescription(description); @@ -609,7 +609,7 @@ public partial class Gambling : GamblingModule public async Task Rps(RpsPick pick, ShmartNumber amount = default) { long oldAmount = amount; - if (!await CheckBetOptional(amount).ConfigureAwait(false) || (amount == 1)) + if (!await CheckBetOptional(amount).ConfigureAwait(false) || amount == 1) return; string getRpsPick(RpsPick p) @@ -646,9 +646,9 @@ public partial class Gambling : GamblingModule embed.WithOkColor(); msg = GetText(strs.rps_draw(getRpsPick(pick))); } - else if ((pick == RpsPick.Paper && nadekoPick == RpsPick.Rock) || - (pick == RpsPick.Rock && nadekoPick == RpsPick.Scissors) || - (pick == RpsPick.Scissors && nadekoPick == RpsPick.Paper)) + else if (pick == RpsPick.Paper && nadekoPick == RpsPick.Rock || + pick == RpsPick.Rock && nadekoPick == RpsPick.Scissors || + pick == RpsPick.Scissors && nadekoPick == RpsPick.Paper) { amount = (long)(amount * base._config.BetFlip.Multiplier); await _cs.AddAsync(ctx.User.Id, diff --git a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs index 4b9ceaa44..1185e986d 100644 --- a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs @@ -110,7 +110,7 @@ public class WaifuService : INService .Count(); return (int) Math.Ceiling(waifu.Price * 1.25f) + - ((divorces + affs + 2) * settings.Waifu.Multipliers.WaifuReset); + (divorces + affs + 2) * settings.Waifu.Multipliers.WaifuReset; } } @@ -164,7 +164,7 @@ public class WaifuService : INService await using (var uow = _db.GetDbContext()) { w = uow.WaifuInfo.ByWaifuUserId(target.Id); - isAffinity = (w?.Affinity?.UserId == user.Id); + isAffinity = w?.Affinity?.UserId == user.Id; if (w is null) { var claimer = uow.GetOrCreateUser(user); @@ -202,7 +202,7 @@ public class WaifuService : INService { var oldClaimer = w.Claimer; w.Claimer = uow.GetOrCreateUser(user); - w.Price = amount + (amount / 4); + w.Price = amount + amount / 4; result = WaifuClaimResult.Success; uow.WaifuUpdates.Add(new() diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index 17c335a2a..b23092ca8 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -212,7 +212,7 @@ public partial class Gambling } private static long GetProfitAmount(int price) => - (int)(Math.Ceiling(0.90 * price)); + (int)Math.Ceiling(0.90 * price); [NadekoCommand, Aliases] [RequireContext(ContextType.Guild)] @@ -300,7 +300,7 @@ public partial class Gambling set => set.Include(x => x.ShopEntries) .ThenInclude(x => x.Items)).ShopEntries); entry = entries.ElementAtOrDefault(index); - if (entry != null && (rightType = (entry.Type == ShopEntryType.List))) + if (entry != null && (rightType = entry.Type == ShopEntryType.List)) { if (added = entry.Items.Add(item)) { diff --git a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs index 9d2dd89c2..d1a13b58e 100644 --- a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs @@ -227,7 +227,7 @@ public partial class Gambling foreach (var w in waifus) { var j = i++; - embed.AddField("#" + ((page * 9) + j + 1) + " - " + w.Price + CurrencySign, w.ToString(), false); + embed.AddField("#" + (page * 9 + j + 1) + " - " + w.Price + CurrencySign, w.ToString(), false); } await ctx.Channel.EmbedAsync(embed); diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index e69cc41fd..a2f118c36 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -198,7 +198,7 @@ public class Help : NadekoModule { succ = new((await Task.WhenAll(cmds.Select(async x => { - var pre = (await x.CheckPreconditionsAsync(Context, _services).ConfigureAwait(false)); + var pre = await x.CheckPreconditionsAsync(Context, _services).ConfigureAwait(false); return (Cmd: x, Succ: pre.IsSuccess); })).ConfigureAwait(false)) .Where(x => x.Succ) diff --git a/src/NadekoBot/Modules/Music/Common/Resolvers/YtdlYoutubeResolver.cs b/src/NadekoBot/Modules/Music/Common/Resolvers/YtdlYoutubeResolver.cs index 31fdbe3ce..9762f4cd7 100644 --- a/src/NadekoBot/Modules/Music/Common/Resolvers/YtdlYoutubeResolver.cs +++ b/src/NadekoBot/Modules/Music/Common/Resolvers/YtdlYoutubeResolver.cs @@ -145,7 +145,7 @@ public sealed class YtdlYoutubeResolver : IYoutubeResolver var match = expiryRegex.Match(streamUrl); if (match.Success && double.TryParse(match.Groups["timestamp"].ToString(), out var timestamp)) { - var realExpiry = (timestamp.ToUnixTimestamp() - DateTime.UtcNow); + var realExpiry = timestamp.ToUnixTimestamp() - DateTime.UtcNow; if (realExpiry > TimeSpan.FromMinutes(60)) return realExpiry.Subtract(TimeSpan.FromMinutes(30)); diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index fbe21efe5..78bd058f2 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -326,7 +326,7 @@ public sealed partial class Music : NadekoModule desc = add + "\n" + desc; var embed = _eb.Create() - .WithAuthor(GetText(strs.player_queue(curPage + 1, (tracks.Count / LQ_ITEMS_PER_PAGE) + 1)), + .WithAuthor(GetText(strs.player_queue(curPage + 1, tracks.Count / LQ_ITEMS_PER_PAGE + 1)), MusicIconUrl) .WithDescription(desc) .WithFooter($" {mp.PrettyVolume()} | 🎶 {tracks.Count} | ⌛ {mp.PrettyTotalTime()} ") @@ -428,7 +428,7 @@ public sealed partial class Music : NadekoModule } var embed = _eb.Create() - .WithAuthor(GetText(strs.removed_song) + " #" + (index), MusicIconUrl) + .WithAuthor(GetText(strs.removed_song) + " #" + index, MusicIconUrl) .WithDescription(song.PrettyName()) .WithFooter(song.PrettyInfo()) .WithErrorColor(); diff --git a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs index 7d88b5888..c7e516ae2 100644 --- a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs @@ -33,10 +33,10 @@ public static class PermissionExtensions //false = applicable, not allowed public static bool? CheckPermission(this Permissionv2 perm, IUserMessage message, string commandName, string moduleName) { - if (!((perm.SecondaryTarget == SecondaryPermissionType.Command && - perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant()) || - (perm.SecondaryTarget == SecondaryPermissionType.Module && - perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant()) || + if (!(perm.SecondaryTarget == SecondaryPermissionType.Command && + perm.SecondaryTargetName.ToLowerInvariant() == commandName.ToLowerInvariant() || + perm.SecondaryTarget == SecondaryPermissionType.Module && + perm.SecondaryTargetName.ToLowerInvariant() == moduleName.ToLowerInvariant() || perm.SecondaryTarget == SecondaryPermissionType.AllModules)) return null; diff --git a/src/NadekoBot/Modules/Searches/FeedCommands.cs b/src/NadekoBot/Modules/Searches/FeedCommands.cs index c66ed8f65..706748c4a 100644 --- a/src/NadekoBot/Modules/Searches/FeedCommands.cs +++ b/src/NadekoBot/Modules/Searches/FeedCommands.cs @@ -102,7 +102,7 @@ public partial class Searches var i = 0; var fs = string.Join("\n", feeds.Skip(cur * 10) .Take(10) - .Select(x => $"`{(cur * 10) + (++i)}.` <#{x.ChannelId}> {x.Url}")); + .Select(x => $"`{cur * 10 + ++i}.` <#{x.ChannelId}> {x.Url}")); return embed.WithDescription(fs); diff --git a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs index 6661b73e2..fed4de1bb 100644 --- a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs +++ b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs @@ -89,7 +89,7 @@ public partial class Searches { var character = tempList[i]; - sb.AppendLine($"#{i + 1 + (curPage * 9),-4}{character.Name,-23}{ShortLeagueName(character.League),-10}{character.Class,-13}{character.Level,-3}"); + sb.AppendLine($"#{i + 1 + curPage * 9,-4}{character.Name,-23}{ShortLeagueName(character.League),-10}{character.Class,-13}{character.Level,-3}"); } sb.AppendLine("```"); diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 0745d7f11..f6254d752 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -241,7 +241,7 @@ public partial class Searches : NadekoModule if (!elems.Any()) return; - var img = (elems.ElementAtOrDefault(new NadekoRandom().Next(0, elems.Count))?.Children?.FirstOrDefault() as IHtmlImageElement); + var img = elems.ElementAtOrDefault(new NadekoRandom().Next(0, elems.Count))?.Children?.FirstOrDefault() as IHtmlImageElement; if (img?.Source is null) return; diff --git a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs index 09056ce3e..bd8e093eb 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs @@ -125,7 +125,7 @@ public partial class Searches { var elem = elements[index]; eb.AddField( - $"**#{(index + 1) + (12 * cur)}** {elem.Username.ToLower()}", + $"**#{index + 1 + 12 * cur}** {elem.Username.ToLower()}", $"【{elem.Type}】\n<#{elem.ChannelId}>\n{elem.Message?.TrimTo(50)}", true); } diff --git a/src/NadekoBot/Modules/Utility/InviteCommands.cs b/src/NadekoBot/Modules/Utility/InviteCommands.cs index bc45e9463..07bead4c6 100644 --- a/src/NadekoBot/Modules/Utility/InviteCommands.cs +++ b/src/NadekoBot/Modules/Utility/InviteCommands.cs @@ -60,7 +60,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 || inv.MaxAge == 0 || inv.CreatedAt is null ? "∞" : (inv.CreatedAt.Value.AddSeconds(inv.MaxAge.Value).UtcDateTime - DateTime.UtcNow) .ToString(@"d\.hh\:mm\:ss"); diff --git a/src/NadekoBot/Modules/Utility/PatreonCommands.cs b/src/NadekoBot/Modules/Utility/PatreonCommands.cs index 9e52f6b3a..d6e0b7b5a 100644 --- a/src/NadekoBot/Modules/Utility/PatreonCommands.cs +++ b/src/NadekoBot/Modules/Utility/PatreonCommands.cs @@ -36,7 +36,7 @@ public partial class Utility return; } - var rem = (_service.Interval - (DateTime.UtcNow - _service.LastUpdate)); + var rem = _service.Interval - (DateTime.UtcNow - _service.LastUpdate); var helpcmd = Format.Code(Prefix + "donate"); await ctx.Channel.EmbedAsync(_eb.Create().WithOkColor() .WithDescription(GetText(strs.clpa_obsolete)) diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 6129b7a28..74c5fd3db 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -213,7 +213,7 @@ public partial class Utility { var q = uow.Quotes.GetById(id); - if ((q?.GuildId != ctx.Guild.Id) || (!hasManageMessages && q.AuthorId != ctx.Message.Author.Id)) + if (q?.GuildId != ctx.Guild.Id || !hasManageMessages && q.AuthorId != ctx.Message.Author.Id) { response = GetText(strs.quotes_remove_none); } diff --git a/src/NadekoBot/Modules/Utility/RemindCommands.cs b/src/NadekoBot/Modules/Utility/RemindCommands.cs index f8dc9352b..5e72511ad 100644 --- a/src/NadekoBot/Modules/Utility/RemindCommands.cs +++ b/src/NadekoBot/Modules/Utility/RemindCommands.cs @@ -131,7 +131,7 @@ public partial class Utility var when = rem.When; var diff = when - DateTime.UtcNow; embed.AddField( - $"#{++i + (page * 10)} {rem.When:HH:mm yyyy-MM-dd} UTC (in {(int) diff.TotalHours}h {(int) diff.Minutes}m)", + $"#{++i + page * 10} {rem.When:HH:mm yyyy-MM-dd} UTC (in {(int) diff.TotalHours}h {(int) diff.Minutes}m)", $@"`Target:` {(rem.IsPrivate ? "DM" : "Channel")} `TargetId:` {rem.ChannelId} `Message:` {rem.Message?.TrimTo(50)}", false); diff --git a/src/NadekoBot/Modules/Utility/RepeatCommands.cs b/src/NadekoBot/Modules/Utility/RepeatCommands.cs index be32f7f61..91ba23c0d 100644 --- a/src/NadekoBot/Modules/Utility/RepeatCommands.cs +++ b/src/NadekoBot/Modules/Utility/RepeatCommands.cs @@ -116,8 +116,8 @@ public partial class Utility : TimeSpan.FromDays(1)); if (string.IsNullOrWhiteSpace(message) - || (interval != null && - (interval.Time > TimeSpan.FromMinutes(25000) || interval.Time < TimeSpan.FromMinutes(1)))) + || interval != null && + (interval.Time > TimeSpan.FromMinutes(25000) || interval.Time < TimeSpan.FromMinutes(1))) { return; } diff --git a/src/NadekoBot/Modules/Utility/Services/RunningRepeater.cs b/src/NadekoBot/Modules/Utility/Services/RunningRepeater.cs index 7ee62f1bd..e03057afb 100644 --- a/src/NadekoBot/Modules/Utility/Services/RunningRepeater.cs +++ b/src/NadekoBot/Modules/Utility/Services/RunningRepeater.cs @@ -89,7 +89,7 @@ public sealed class RunningRepeater // interval (2.4h) * 0.834 is 2.0016 and that is the initial interval var initialIntervalMultiplier = 1 - (triggerCount - Math.Truncate(triggerCount)); - return DateTime.UtcNow + (Repeater.Interval * initialIntervalMultiplier); + return DateTime.UtcNow + Repeater.Interval * initialIntervalMultiplier; } public override bool Equals(object obj) diff --git a/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs b/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs index 0859e6c1e..81ea4722a 100644 --- a/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs +++ b/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs @@ -79,10 +79,10 @@ public partial class Utility { if (originUnit.UnitType == "currency") { - res = (value * targetUnit.Modifier) / originUnit.Modifier; + res = value * targetUnit.Modifier / originUnit.Modifier; } else - res = (value * originUnit.Modifier) / targetUnit.Modifier; + res = value * originUnit.Modifier / targetUnit.Modifier; } res = Math.Round(res, 4); diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 1d683b3d6..02b8893fc 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -87,7 +87,7 @@ public partial class Utility : NadekoModule await ReplyErrorLocalizedAsync(strs.nobody_playing_game).ConfigureAwait(false); else { - await SendConfirmAsync("```css\n" + string.Join("\n", arr.GroupBy(item => (i++) / 2) + await SendConfirmAsync("```css\n" + string.Join("\n", arr.GroupBy(item => i++ / 2) .Select(ig => string.Concat(ig.Select(el => $"• {el,-27}")))) + "\n```") .ConfigureAwait(false); } @@ -348,7 +348,7 @@ public partial class Utility : NadekoModule if (page < 0) return; - var guilds = await Task.Run(() => _client.Guilds.OrderBy(g => g.Name).Skip((page) * 15).Take(15)).ConfigureAwait(false); + var guilds = await Task.Run(() => _client.Guilds.OrderBy(g => g.Name).Skip(page * 15).Take(15)).ConfigureAwait(false); if (!guilds.Any()) { diff --git a/src/NadekoBot/Modules/Xp/Club.cs b/src/NadekoBot/Modules/Xp/Club.cs index b13c49ea7..0e088d943 100644 --- a/src/NadekoBot/Modules/Xp/Club.cs +++ b/src/NadekoBot/Modules/Xp/Club.cs @@ -74,7 +74,7 @@ public partial class Xp [NadekoCommand, Aliases] public async Task ClubIcon([Leftover] string url = null) { - if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url != null) + if (!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url != null || !await _service.SetClubIcon(ctx.User.Id, url is null ? null : new Uri(url))) { await ReplyErrorLocalizedAsync(strs.club_icon_error).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Xp/Services/ClubService.cs b/src/NadekoBot/Modules/Xp/Services/ClubService.cs index 8d0b54c3e..ed7781f29 100644 --- a/src/NadekoBot/Modules/Xp/Services/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Services/ClubService.cs @@ -294,7 +294,7 @@ public class ClubService : INService if (usr is null) return false; - if (club.OwnerId == usr.Id || (usr.IsClubAdmin && club.Owner.UserId != bannerId)) // can't ban the owner kek, whew + if (club.OwnerId == usr.Id || usr.IsClubAdmin && club.Owner.UserId != bannerId) // can't ban the owner kek, whew return false; club.Bans.Add(new() @@ -345,7 +345,7 @@ public class ClubService : INService if (usr is null) return false; - if (club.OwnerId == usr.Id || (usr.IsClubAdmin && club.Owner.UserId != kickerId)) + if (club.OwnerId == usr.Id || usr.IsClubAdmin && club.Owner.UserId != kickerId) return false; club.Users.Remove(usr); diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index 2d4109a9e..ed7af492c 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -940,9 +940,9 @@ public class XpService : INService //xp bar if (_template.User.Xp.Bar.Show) { - var xpPercent = (global.LevelXp / (float) global.RequiredXp); + var xpPercent = global.LevelXp / (float) global.RequiredXp; DrawXpBar(xpPercent, _template.User.Xp.Bar.Global, img); - xpPercent = (guild.LevelXp / (float) guild.RequiredXp); + xpPercent = guild.LevelXp / (float) guild.RequiredXp; DrawXpBar(xpPercent, _template.User.Xp.Bar.Guild, img); } @@ -970,7 +970,7 @@ public class XpService : INService ? "+ " : ""; var awX = _template.User.Xp.Awarded.Pos.X - - (Math.Max(0, (stats.FullGuildStats.AwardedXp.ToString().Length - 2)) * 5); + Math.Max(0, stats.FullGuildStats.AwardedXp.ToString().Length - 2) * 5; var awY = _template.User.Xp.Awarded.Pos.Y; img.Mutate(x => x.DrawText($"({sign}{stats.FullGuildStats.AwardedXp})", _fonts.NotoSans.CreateFont(_template.User.Xp.Awarded.FontSize, FontStyle.Bold), diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 36d0de8c0..cd6fd0017 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -338,7 +338,7 @@ public partial class Xp : NadekoModule await ctx.Channel.TriggerTypingAsync(); - var socketGuild = ((SocketGuild)ctx.Guild); + var socketGuild = (SocketGuild)ctx.Guild; var allUsers = new List(); if (opts.Clean) { @@ -384,7 +384,7 @@ public partial class Xp : NadekoModule awardStr = $"({userXpData.AwardedXp})"; embed.AddField( - $"#{(i + 1 + curPage * 9)} {(user?.ToString() ?? users[i].UserId.ToString())}", + $"#{i + 1 + curPage * 9} {user?.ToString() ?? users[i].UserId.ToString()}", $"{GetText(strs.level_x(levelStats.Level))} - {levelStats.TotalXp}xp {awardStr}"); } return embed; @@ -412,7 +412,7 @@ public partial class Xp : NadekoModule { var user = users[i]; embed.AddField( - $"#{i + 1 + page * 9} {(user.ToString())}", + $"#{i + 1 + page * 9} {user.ToString()}", $"{GetText(strs.level_x(new LevelStats(users[i].TotalXp).Level))} - {users[i].TotalXp}xp"); } } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 535016a13..6206be014 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -146,8 +146,8 @@ public class CommandHandler : INService "Channel: {2}\n\t" + "Message: {3}", usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} - (channel is null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} - (channel is null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]"), // {2} + channel is null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]", // {1} + channel is null ? "PRIVATE" : channel.Name + " [" + channel.Id + "]", // {2} usrMsg.Content // {3} ); } diff --git a/src/NadekoBot/Services/GreetSettingsService.cs b/src/NadekoBot/Services/GreetSettingsService.cs index e515ad294..7769576f2 100644 --- a/src/NadekoBot/Services/GreetSettingsService.cs +++ b/src/NadekoBot/Services/GreetSettingsService.cs @@ -50,10 +50,10 @@ public class GreetSettingsService : INService { // if user is a new booster // or boosted again the same server - if ((oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null }) - || (oldUser?.PremiumSince is { } oldDate - && newUser?.PremiumSince is { } newDate - && newDate > oldDate)) + if (oldUser is { PremiumSince: null } && newUser is { PremiumSince: not null } + || oldUser?.PremiumSince is { } oldDate + && newUser?.PremiumSince is { } newDate + && newDate > oldDate) { var conf = GetOrAddSettingsForGuild(newUser.Guild.Id); if (!conf.SendBoostMessage) return Task.CompletedTask; diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 529b8aa4c..24e26601c 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -375,7 +375,7 @@ public class GoogleApiService : IGoogleApiService, INService text = await http.GetStringAsync(url).ConfigureAwait(false); } - return (string.Concat(JArray.Parse(text)[0].Select(x => x[0]))); + return string.Concat(JArray.Parse(text)[0].Select(x => x[0])); } private string ConvertToLanguageCode(string language) diff --git a/src/NadekoBot/_Extensions/IEnumerableExtensions.cs b/src/NadekoBot/_Extensions/IEnumerableExtensions.cs index dd6234d68..06bde1272 100644 --- a/src/NadekoBot/_Extensions/IEnumerableExtensions.cs +++ b/src/NadekoBot/_Extensions/IEnumerableExtensions.cs @@ -39,15 +39,15 @@ public static class IEnumerableExtensions var n = list.Count; while (n > 1) { - var box = new byte[(n / Byte.MaxValue) + 1]; + var box = new byte[n / Byte.MaxValue + 1]; int boxSum; do { provider.GetBytes(box); boxSum = box.Sum(b => b); - } while (!(boxSum < n * ((Byte.MaxValue * box.Length) / n))); + } while (!(boxSum < n * (Byte.MaxValue * box.Length / n))); - var k = (boxSum % n); + var k = boxSum % n; n--; var value = list[k]; list[k] = list[n]; diff --git a/src/NadekoBot/_Extensions/StringExtensions.cs b/src/NadekoBot/_Extensions/StringExtensions.cs index 8414bf85d..063e000a9 100644 --- a/src/NadekoBot/_Extensions/StringExtensions.cs +++ b/src/NadekoBot/_Extensions/StringExtensions.cs @@ -115,7 +115,7 @@ public static class StringExtensions for (var j = 1; j <= m; j++) { // Step 5 - var cost = (t[j - 1] == s[i - 1]) ? 0 : 1; + var cost = t[j - 1] == s[i - 1] ? 0 : 1; // Step 6 d[i, j] = Math.Min(