From d8c7cdc7f4730b5da20e291333d3a03d670fece6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Sat, 19 Jun 2021 08:24:09 +0200 Subject: [PATCH] Changed all == null to is null and all !(* == null) to * is not null --- src/NadekoBot/Common/Attributes/Ratelimit.cs | 2 +- .../Common/Collections/ConcurrentHashSet.cs | 14 +-- .../Common/Replacements/ReplacementBuilder.cs | 8 +- .../TypeReaders/BotCommandTypeReader.cs | 2 +- .../TypeReaders/GuildDateTimeTypeReader.cs | 2 +- .../TypeReaders/Models/PermissionAction.cs | 2 +- .../Common/TypeReaders/ModuleTypeReader.cs | 4 +- .../Db/Extensions/GuildConfigExtensions.cs | 16 +-- .../SelfAssignableRolesExtensions.cs | 2 +- .../Db/Extensions/UserXpExtensions.cs | 2 +- .../Db/Extensions/WaifuExtensions.cs | 2 +- .../Db/Extensions/WarningExtensions.cs | 2 +- src/NadekoBot/Db/Models/CommandAlias.cs | 2 +- src/NadekoBot/Db/Models/ShopEntry.cs | 2 +- .../Db/Models/SlowmodeIgnoredRole.cs | 2 +- .../Db/Models/SlowmodeIgnoredUser.cs | 2 +- src/NadekoBot/Db/Models/Waifu.cs | 4 +- .../Modules/Administration/Administration.cs | 6 +- .../Administration/AutoAssignRoleCommands.cs | 2 +- .../Administration/GameChannelCommands.cs | 4 +- .../Modules/Administration/LogCommands.cs | 2 +- .../Administration/PlayingRotateCommands.cs | 2 +- .../Administration/ProtectionCommands.cs | 8 +- .../Modules/Administration/RoleCommands.cs | 4 +- .../SelfAssignedRolesCommands.cs | 2 +- .../Modules/Administration/SelfCommands.cs | 10 +- .../Services/AdministrationService.cs | 2 +- .../Services/AutoAssignRoleService.cs | 2 +- .../Services/DangerousCommandsService.cs | 2 +- .../Services/DiscordPermOverrideService.cs | 2 +- .../Services/GameVoiceChannelService.cs | 6 +- .../Services/GuildTimezoneService.cs | 4 +- .../Services/LogCommandService.cs | 108 +++++++++--------- .../Administration/Services/MuteService.cs | 10 +- .../Services/ProtectionService.cs | 2 +- .../Services/RoleCommandsService.cs | 6 +- .../Services/SelfAssignedRolesService.cs | 8 +- .../Administration/Services/SelfService.cs | 4 +- .../Services/UserPunishService.cs | 8 +- .../Administration/Services/VcRoleService.cs | 8 +- .../Administration/TimeZoneCommands.cs | 2 +- .../Administration/UserPunishCommands.cs | 10 +- .../Modules/Administration/VcRoleCommands.cs | 4 +- .../CustomReactions/CustomReactions.cs | 8 +- .../CustomReactions/Extensions/Extensions.cs | 2 +- .../Services/CustomReactionsService.cs | 12 +- .../Modules/Gambling/AnimalRacingCommands.cs | 2 +- .../Gambling/Common/Blackjack/Blackjack.cs | 2 +- src/NadekoBot/Modules/Gambling/Common/Deck.cs | 2 +- .../Gambling/Common/Events/ReactionEvent.cs | 4 +- .../Modules/Gambling/Connect4/Connect4.cs | 2 +- .../Modules/Gambling/Connect4Commands.cs | 2 +- .../Modules/Gambling/DrawCommands.cs | 2 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 2 +- .../Services/CurrencyEventsService.cs | 2 +- .../Gambling/Services/PlantPickService.cs | 4 +- .../Modules/Gambling/Services/WaifuService.cs | 14 +-- .../Modules/Gambling/ShopCommands.cs | 8 +- .../Modules/Gambling/WaifuClaimCommands.cs | 6 +- .../Modules/Games/Common/PollRunner.cs | 4 +- .../Modules/Games/Common/TicTacToe.cs | 8 +- .../Modules/Games/Common/Trivia/TriviaGame.cs | 2 +- .../Modules/Games/Common/TypingGame.cs | 4 +- src/NadekoBot/Modules/Games/Games.cs | 2 +- .../Modules/Games/HangmanCommands.cs | 2 +- src/NadekoBot/Modules/Games/NunchiCommands.cs | 2 +- src/NadekoBot/Modules/Games/PollCommands.cs | 4 +- .../Games/Services/ChatterbotService.cs | 4 +- .../Modules/Games/Services/PollService.cs | 2 +- src/NadekoBot/Modules/Help/Help.cs | 2 +- .../Modules/Help/Services/HelpService.cs | 4 +- .../Common/Resolvers/LocalTrackResolver.cs | 2 +- .../Common/Resolvers/SoundcloudResolver.cs | 2 +- .../Modules/Music/Common/_OldMusicPlayer.cs | 6 +- .../Modules/Music/Common/_OldMusicQueue.cs | 2 +- src/NadekoBot/Modules/Music/Music.cs | 6 +- .../Modules/Music/PlaylistCommands.cs | 2 +- .../Modules/Music/Services/MusicService.cs | 4 +- .../Music/Services/_OldMusicService.cs | 10 +- src/NadekoBot/Modules/Music/_OldMusic.cs | 26 ++--- src/NadekoBot/Modules/Nsfw/Nsfw.cs | 10 +- .../Common/PermissionExtensions.cs | 6 +- .../Modules/Permissions/FilterCommands.cs | 16 +-- .../Modules/Permissions/Permissions.cs | 6 +- .../Permissions/Services/BlacklistService.cs | 2 +- .../Permissions/Services/FilterService.cs | 2 +- .../Services/PermissionsService.cs | 6 +- .../Modules/Searches/AnimeSearchCommands.cs | 8 +- .../Modules/Searches/CryptoCommands.cs | 2 +- src/NadekoBot/Modules/Searches/Searches.cs | 28 ++--- .../Searches/Services/AnimeSearchService.cs | 2 +- .../Searches/Services/CryptoService.cs | 2 +- .../Modules/Searches/Services/FeedsService.cs | 2 +- .../Searches/Services/SearchesService.cs | 16 +-- .../Searches/Services/YtTrackService.cs | 2 +- src/NadekoBot/Modules/Utility/InfoCommands.cs | 6 +- .../Modules/Utility/QuoteCommands.cs | 4 +- .../Modules/Utility/RemindCommands.cs | 6 +- .../Utility/Services/CommandMapService.cs | 2 +- .../Utility/Services/PatreonRewardsService.cs | 4 +- .../Modules/Utility/Services/RemindService.cs | 4 +- .../Utility/Services/RepeaterService.cs | 2 +- .../Utility/Services/StreamRoleService.cs | 8 +- .../Utility/Services/VerboseErrorsService.cs | 2 +- .../Modules/Utility/UnitConversionCommands.cs | 2 +- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- src/NadekoBot/Modules/Xp/Club.cs | 8 +- .../Modules/Xp/Services/ClubService.cs | 34 +++--- .../Modules/Xp/Services/XpService.cs | 4 +- src/NadekoBot/Modules/Xp/Xp.cs | 2 +- src/NadekoBot/Services/CommandHandler.cs | 10 +- src/NadekoBot/Services/Common/ImageLoader.cs | 2 +- .../Services/GreetSettingsService.cs | 2 +- src/NadekoBot/Services/Impl/Localization.cs | 4 +- src/NadekoBot/Services/Impl/RedisCache.cs | 8 +- src/NadekoBot/Services/ShardsCoordinator.cs | 8 +- src/NadekoBot/_Extensions/Extensions.cs | 8 +- .../_Extensions/IEnumerableExtensions.cs | 2 +- .../_Extensions/IMessageChannelExtensions.cs | 2 +- src/NadekoBot/_Extensions/IUserExtensions.cs | 4 +- .../_Extensions/LinkedListExtensions.cs | 2 +- .../_Extensions/ProcessExtensions.cs | 2 +- src/NadekoBot/_Extensions/StringExtensions.cs | 4 +- .../Ayu.Discord.Voice.csproj | 1 + src/ayu/Ayu.Discord.Voice/SocketClient.cs | 2 +- 125 files changed, 367 insertions(+), 366 deletions(-) diff --git a/src/NadekoBot/Common/Attributes/Ratelimit.cs b/src/NadekoBot/Common/Attributes/Ratelimit.cs index 851d7c992..88761c696 100644 --- a/src/NadekoBot/Common/Attributes/Ratelimit.cs +++ b/src/NadekoBot/Common/Attributes/Ratelimit.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Core.Common.Attributes var cache = services.GetService(); var rem = cache.TryAddRatelimit(context.User.Id, command.Name, Seconds); - if(rem == null) + if(rem is null) return Task.FromResult(PreconditionResult.FromSuccess()); var msgContent = $"You can use this command again in {rem.Value.TotalSeconds:F1}s."; diff --git a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs b/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs index f4b5be2d5..99759f21b 100644 --- a/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs +++ b/src/NadekoBot/Common/Collections/ConcurrentHashSet.cs @@ -176,7 +176,7 @@ namespace NadekoBot.Common.Collections public ConcurrentHashSet(IEnumerable collection, IEqualityComparer comparer) : this(comparer) { - if (collection == null) throw new ArgumentNullException(nameof(collection)); + if (collection is null) throw new ArgumentNullException(nameof(collection)); InitializeFromCollection(collection); } @@ -205,8 +205,8 @@ namespace NadekoBot.Common.Collections public ConcurrentHashSet(int concurrencyLevel, IEnumerable collection, IEqualityComparer comparer) : this(concurrencyLevel, DefaultCapacity, false, comparer) { - if (collection == null) throw new ArgumentNullException(nameof(collection)); - if (comparer == null) throw new ArgumentNullException(nameof(comparer)); + if (collection is null) throw new ArgumentNullException(nameof(collection)); + if (comparer is null) throw new ArgumentNullException(nameof(comparer)); InitializeFromCollection(collection); } @@ -348,11 +348,11 @@ namespace NadekoBot.Common.Collections Node previous = null; for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next) { - Debug.Assert((previous == null && current == tables.Buckets[bucketNo]) || previous.Next == current); + Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current); if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item)) { - if (previous == null) + if (previous is null) { Volatile.Write(ref tables.Buckets[bucketNo], current.Next); } @@ -406,7 +406,7 @@ namespace NadekoBot.Common.Collections void ICollection.CopyTo(T[] array, int arrayIndex) { - if (array == null) throw new ArgumentNullException(nameof(array)); + if (array is null) throw new ArgumentNullException(nameof(array)); if (arrayIndex < 0) throw new ArgumentOutOfRangeException(nameof(arrayIndex)); var locksAcquired = 0; @@ -474,7 +474,7 @@ namespace NadekoBot.Common.Collections Node previous = null; for (var current = tables.Buckets[bucketNo]; current != null; current = current.Next) { - Debug.Assert((previous == null && current == tables.Buckets[bucketNo]) || previous.Next == current); + Debug.Assert((previous is null && current == tables.Buckets[bucketNo]) || previous.Next == current); if (hashcode == current.Hashcode && _comparer.Equals(current.Item, item)) { return false; diff --git a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs index c78f885d2..eb3f30e71 100644 --- a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs +++ b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs @@ -69,8 +69,8 @@ namespace NadekoBot.Common.Replacements public ReplacementBuilder WithServer(DiscordSocketClient client, SocketGuild g) { /*OBSOLETE*/ - _reps.TryAdd("%sid%", () => g == null ? "DM" : g.Id.ToString()); - _reps.TryAdd("%server%", () => g == null ? "DM" : g.Name); + _reps.TryAdd("%sid%", () => g is null ? "DM" : g.Id.ToString()); + _reps.TryAdd("%server%", () => g is null ? "DM" : g.Name); _reps.TryAdd("%members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?"); _reps.TryAdd("%server_time%", () => { @@ -86,8 +86,8 @@ namespace NadekoBot.Common.Replacements to).ToString("HH:mm ") + to.StandardName.GetInitials(); }); /*NEW*/ - _reps.TryAdd("%server.id%", () => g == null ? "DM" : g.Id.ToString()); - _reps.TryAdd("%server.name%", () => g == null ? "DM" : g.Name); + _reps.TryAdd("%server.id%", () => g is null ? "DM" : g.Id.ToString()); + _reps.TryAdd("%server.name%", () => g is null ? "DM" : g.Name); _reps.TryAdd("%server.members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?"); _reps.TryAdd("%server.time%", () => { diff --git a/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs b/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs index 353bfc145..f2ec41130 100644 --- a/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/BotCommandTypeReader.cs @@ -29,7 +29,7 @@ namespace NadekoBot.Common.TypeReaders var cmd = _cmds.Commands.FirstOrDefault(c => c.Aliases.Select(a => a.ToUpperInvariant()).Contains(input)); - if (cmd == null) + if (cmd is null) return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such command found.")); return Task.FromResult(TypeReaderResult.FromSuccess(cmd)); diff --git a/src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs b/src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs index eabfb3cbb..1660e98a4 100644 --- a/src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/GuildDateTimeTypeReader.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Common.TypeReaders public override Task ReadAsync(ICommandContext context, string input, IServiceProvider services) { var gdt = Parse(services, context.Guild.Id, input); - if(gdt == null) + if(gdt is null) return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input string is in an incorrect format.")); return Task.FromResult(TypeReaderResult.FromSuccess(gdt)); diff --git a/src/NadekoBot/Common/TypeReaders/Models/PermissionAction.cs b/src/NadekoBot/Common/TypeReaders/Models/PermissionAction.cs index f9a800580..12dbb1dfe 100644 --- a/src/NadekoBot/Common/TypeReaders/Models/PermissionAction.cs +++ b/src/NadekoBot/Common/TypeReaders/Models/PermissionAction.cs @@ -14,7 +14,7 @@ public override bool Equals(object obj) { - if (obj == null || GetType() != obj.GetType()) + if (obj is null || GetType() != obj.GetType()) { return false; } diff --git a/src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs b/src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs index 79cceaa35..a6f7dfc7c 100644 --- a/src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs +++ b/src/NadekoBot/Common/TypeReaders/ModuleTypeReader.cs @@ -21,7 +21,7 @@ namespace NadekoBot.Common.TypeReaders { input = input.ToUpperInvariant(); var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input)?.Key; - if (module == null) + if (module is null) return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such module found.")); return Task.FromResult(TypeReaderResult.FromSuccess(module)); @@ -41,7 +41,7 @@ namespace NadekoBot.Common.TypeReaders { input = input.ToUpperInvariant(); var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input)?.Key; - if (module == null && input != "ACTUALCUSTOMREACTIONS") + if (module is null && input != "ACTUALCUSTOMREACTIONS") return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "No such module found.")); return Task.FromResult(TypeReaderResult.FromSuccess(new ModuleOrCrInfo diff --git a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs index 121323acb..d972428e1 100644 --- a/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs +++ b/src/NadekoBot/Db/Extensions/GuildConfigExtensions.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Db .Include(y => y.StreamRole.Whitelist) .Include(y => y.StreamRole.Blacklist)); - if (conf.StreamRole == null) + if (conf.StreamRole is null) conf.StreamRole = new StreamRoleSettings(); return conf.StreamRole; @@ -79,7 +79,7 @@ namespace NadekoBot.Db { GuildConfig config; - if (includes == null) + if (includes is null) { config = ctx .GuildConfigs @@ -92,7 +92,7 @@ namespace NadekoBot.Db config = set.FirstOrDefault(c => c.GuildId == guildId); } - if (config == null) + if (config is null) { ctx.GuildConfigs.Add((config = new GuildConfig { @@ -122,7 +122,7 @@ namespace NadekoBot.Db .ThenInclude(gc => gc.IgnoredChannels) .FirstOrDefault(x => x.GuildId == guildId); - if (config == null) + if (config is null) { ctx.GuildConfigs.Add((config = new GuildConfig { @@ -160,7 +160,7 @@ namespace NadekoBot.Db .Include(gc => gc.Permissions) .FirstOrDefault(); - if (config == null) // if there is no guildconfig, create new one + if (config is null) // if there is no guildconfig, create new one { ctx.GuildConfigs.Add((config = new GuildConfig { @@ -169,7 +169,7 @@ namespace NadekoBot.Db })); ctx.SaveChanges(); } - else if (config.Permissions == null || !config.Permissions.Any()) // if no perms, add default ones + else if (config.Permissions is null || !config.Permissions.Any()) // if no perms, add default ones { config.Permissions = Permissionv2.GetDefaultPermlist; ctx.SaveChanges(); @@ -200,7 +200,7 @@ namespace NadekoBot.Db { var conf = configs.FirstOrDefault(gc => gc.GuildId == id); - if (conf == null) + if (conf is null) return; conf.CleverbotEnabled = cleverbotEnabled; @@ -216,7 +216,7 @@ namespace NadekoBot.Db .Include(x => x.XpSettings) .ThenInclude(x => x.ExclusionList)); - if (gc.XpSettings == null) + if (gc.XpSettings is null) gc.XpSettings = new XpSettings(); return gc.XpSettings; diff --git a/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs b/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs index 2daa67c6e..87eb97127 100644 --- a/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs +++ b/src/NadekoBot/Db/Extensions/SelfAssignableRolesExtensions.cs @@ -11,7 +11,7 @@ namespace NadekoBot.Db { var role = roles.FirstOrDefault(s => s.GuildId == guildId && s.RoleId == roleId); - if (role == null) + if (role is null) return false; roles.Remove(role); diff --git a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs index 4b3f92839..cdef2ec48 100644 --- a/src/NadekoBot/Db/Extensions/UserXpExtensions.cs +++ b/src/NadekoBot/Db/Extensions/UserXpExtensions.cs @@ -13,7 +13,7 @@ namespace NadekoBot.Db { var usr = ctx.UserXpStats.FirstOrDefault(x => x.UserId == userId && x.GuildId == guildId); - if (usr == null) + if (usr is null) { ctx.Add(usr = new UserXpStats() { diff --git a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs index 6728f77a1..303cdacd9 100644 --- a/src/NadekoBot/Db/Extensions/WaifuExtensions.cs +++ b/src/NadekoBot/Db/Extensions/WaifuExtensions.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Db { public static WaifuInfo ByWaifuUserId(this DbSet waifus, ulong userId, Func, IQueryable> includes = null) { - if (includes == null) + if (includes is null) { return waifus.Include(wi => wi.Waifu) .Include(wi => wi.Affinity) diff --git a/src/NadekoBot/Db/Extensions/WarningExtensions.cs b/src/NadekoBot/Db/Extensions/WarningExtensions.cs index f63efd856..b823633dc 100644 --- a/src/NadekoBot/Db/Extensions/WarningExtensions.cs +++ b/src/NadekoBot/Db/Extensions/WarningExtensions.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Db .Skip(index) .FirstOrDefault(); - if (warn == null || warn.Forgiven) + if (warn is null || warn.Forgiven) return false; warn.Forgiven = true; diff --git a/src/NadekoBot/Db/Models/CommandAlias.cs b/src/NadekoBot/Db/Models/CommandAlias.cs index 75540bf78..d4d6c8c39 100644 --- a/src/NadekoBot/Db/Models/CommandAlias.cs +++ b/src/NadekoBot/Db/Models/CommandAlias.cs @@ -8,7 +8,7 @@ //// override object.Equals //public override bool Equals(object obj) //{ - // if (obj == null || GetType() != obj.GetType()) + // if (obj is null || GetType() != obj.GetType()) // { // return false; // } diff --git a/src/NadekoBot/Db/Models/ShopEntry.cs b/src/NadekoBot/Db/Models/ShopEntry.cs index 570a5fd43..3d05ab44f 100644 --- a/src/NadekoBot/Db/Models/ShopEntry.cs +++ b/src/NadekoBot/Db/Models/ShopEntry.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Core.Services.Database.Models public override bool Equals(object obj) { - if (obj == null || GetType() != obj.GetType()) + if (obj is null || GetType() != obj.GetType()) { return false; } diff --git a/src/NadekoBot/Db/Models/SlowmodeIgnoredRole.cs b/src/NadekoBot/Db/Models/SlowmodeIgnoredRole.cs index 462b3b755..fb2f56592 100644 --- a/src/NadekoBot/Db/Models/SlowmodeIgnoredRole.cs +++ b/src/NadekoBot/Db/Models/SlowmodeIgnoredRole.cs @@ -7,7 +7,7 @@ // override object.Equals public override bool Equals(object obj) { - if (obj == null || GetType() != obj.GetType()) + if (obj is null || GetType() != obj.GetType()) { return false; } diff --git a/src/NadekoBot/Db/Models/SlowmodeIgnoredUser.cs b/src/NadekoBot/Db/Models/SlowmodeIgnoredUser.cs index 63090b973..492865c03 100644 --- a/src/NadekoBot/Db/Models/SlowmodeIgnoredUser.cs +++ b/src/NadekoBot/Db/Models/SlowmodeIgnoredUser.cs @@ -7,7 +7,7 @@ // override object.Equals public override bool Equals(object obj) { - if (obj == null || GetType() != obj.GetType()) + if (obj is null || GetType() != obj.GetType()) { return false; } diff --git a/src/NadekoBot/Db/Models/Waifu.cs b/src/NadekoBot/Db/Models/Waifu.cs index 9d15d01f8..a89fbcfd2 100644 --- a/src/NadekoBot/Db/Models/Waifu.cs +++ b/src/NadekoBot/Db/Models/Waifu.cs @@ -31,7 +31,7 @@ namespace NadekoBot.Core.Services.Database.Models { claimer = $"{ claimerUsername }#{Claimer.Discriminator}"; } - if (AffinityId == null) + if (AffinityId is null) { status = $"... but {waifuUsername}'s heart is empty"; } @@ -72,7 +72,7 @@ namespace NadekoBot.Core.Services.Database.Models { claimer = $"{ claimerUsername }#{ClaimerDiscrim}"; } - if (Affinity == null) + if (Affinity is null) { status = $"... but {waifuUsername}'s heart is empty"; } diff --git a/src/NadekoBot/Modules/Administration/Administration.cs b/src/NadekoBot/Modules/Administration/Administration.cs index 4660bc5a8..dc190cc79 100644 --- a/src/NadekoBot/Modules/Administration/Administration.cs +++ b/src/NadekoBot/Modules/Administration/Administration.cs @@ -28,7 +28,7 @@ namespace NadekoBot.Modules.Administration public async Task Slowmode(StoopidTime time = null) { var seconds = (int?)time?.Time.TotalSeconds ?? 0; - if (!(time is null) && (time.Time < TimeSpan.FromSeconds(0) || time.Time > TimeSpan.FromHours(6))) + if (time is not null && (time.Time < TimeSpan.FromSeconds(0) || time.Time > TimeSpan.FromHours(6))) return; @@ -305,13 +305,13 @@ namespace NadekoBot.Modules.Administration var msg = await channel.GetMessageAsync(messageId).ConfigureAwait(false); - if (msg == null) + if (msg is null) { await ReplyErrorLocalizedAsync("msg_not_found").ConfigureAwait(false); return; } - if (time == null) + if (time is null) { await msg.DeleteAsync().ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/AutoAssignRoleCommands.cs b/src/NadekoBot/Modules/Administration/AutoAssignRoleCommands.cs index c29b2a449..f44ac69d9 100644 --- a/src/NadekoBot/Modules/Administration/AutoAssignRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/AutoAssignRoleCommands.cs @@ -55,7 +55,7 @@ namespace NadekoBot.Modules.Administration return; } - var existing = roles.Select(rid => ctx.Guild.GetRole(rid)).Where(r => !(r is null)) + var existing = roles.Select(rid => ctx.Guild.GetRole(rid)).Where(r => r is not null) .ToList(); if (existing.Count != roles.Count) diff --git a/src/NadekoBot/Modules/Administration/GameChannelCommands.cs b/src/NadekoBot/Modules/Administration/GameChannelCommands.cs index 9cd236c80..5d3bacfc2 100644 --- a/src/NadekoBot/Modules/Administration/GameChannelCommands.cs +++ b/src/NadekoBot/Modules/Administration/GameChannelCommands.cs @@ -19,14 +19,14 @@ namespace NadekoBot.Modules.Administration { var vch = ((IGuildUser)ctx.User).VoiceChannel; - if (vch == null) + if (vch is null) { await ReplyErrorLocalizedAsync("not_in_voice").ConfigureAwait(false); return; } var id = _service.ToggleGameVoiceChannel(ctx.Guild.Id, vch.Id); - if (id == null) + if (id is null) { await ReplyConfirmLocalizedAsync("gvc_disabled").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/LogCommands.cs b/src/NadekoBot/Modules/Administration/LogCommands.cs index 4cb96b00e..ab412b52a 100644 --- a/src/NadekoBot/Modules/Administration/LogCommands.cs +++ b/src/NadekoBot/Modules/Administration/LogCommands.cs @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Administration var str = string.Join("\n", Enum.GetNames(typeof(LogType)) .Select(x => { - var val = l == null ? null : GetLogProperty(l, Enum.Parse(x)); + var val = l is null ? null : GetLogProperty(l, Enum.Parse(x)); if (val != null) return $"{Format.Bold(x)} <#{val}>"; return Format.Bold(x); diff --git a/src/NadekoBot/Modules/Administration/PlayingRotateCommands.cs b/src/NadekoBot/Modules/Administration/PlayingRotateCommands.cs index 5173f0c25..e2aa7199e 100644 --- a/src/NadekoBot/Modules/Administration/PlayingRotateCommands.cs +++ b/src/NadekoBot/Modules/Administration/PlayingRotateCommands.cs @@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Administration var msg = await _service.RemovePlayingAsync(index).ConfigureAwait(false); - if (msg == null) + if (msg is null) return; await ReplyConfirmLocalizedAsync("reprm", msg).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Administration/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/ProtectionCommands.cs index 9be1c6672..f6c635570 100644 --- a/src/NadekoBot/Modules/Administration/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/ProtectionCommands.cs @@ -113,7 +113,7 @@ namespace NadekoBot.Modules.Administration return; } - if (!(punishTime is null)) + if (punishTime is not null) { if (!_service.IsDurationAllowed(action)) { @@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Administration var stats = await _service.StartAntiRaidAsync(ctx.Guild.Id, userThreshold, seconds, action, time).ConfigureAwait(false); - if (stats == null) + if (stats is null) { return; } @@ -185,7 +185,7 @@ namespace NadekoBot.Modules.Administration if (messageCount < 2 || messageCount > 10) return; - if (!(timeData is null)) + if (timeData is not null) { if (!_service.IsDurationAllowed(action)) { @@ -244,7 +244,7 @@ namespace NadekoBot.Modules.Administration .WithValue(GetAntiRaidString(raid).TrimTo(1024)) .WithIsInline(true)); - if (!(alt is null)) + if (alt is not null) embed.AddField("Anti-Alt", GetAntiAltString(alt), true); await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Administration/RoleCommands.cs b/src/NadekoBot/Modules/Administration/RoleCommands.cs index b05cff1cb..a3eb2374f 100644 --- a/src/NadekoBot/Modules/Administration/RoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/RoleCommands.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Administration var msgs = await ((SocketTextChannel)ctx.Channel).GetMessagesAsync().FlattenAsync().ConfigureAwait(false); var prev = (IUserMessage)msgs.FirstOrDefault(x => x is IUserMessage && x.Id != ctx.Message.Id); - if (prev == null) + if (prev is null) return; if (input.Length % 2 != 0) @@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Administration { var ch = g.GetTextChannel(rr.ChannelId); IUserMessage msg = null; - if (!(ch is null)) + if (ch is not null) { msg = await ch.GetMessageAsync(rr.MessageId).ConfigureAwait(false) as IUserMessage; } diff --git a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs index 7a38281cb..c6e64b523 100644 --- a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs @@ -138,7 +138,7 @@ namespace NadekoBot.Modules.Administration rolesStr.AppendLine("\t\t\t\t ⟪" + groupNameText + "⟫"); foreach (var (Model, Role) in kvp.AsEnumerable()) { - if (Role == null) + if (Role is null) { continue; } diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index 7a88a4e28..d3cce1717 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -58,7 +58,7 @@ namespace NadekoBot.Modules.Administration await ctx.Channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("scadd")) .AddField(efb => efb.WithName(GetText("server")) - .WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true)) + .WithValue(cmd.GuildId is null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("channel")) .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true)) .AddField(efb => efb.WithName(GetText("command_text")) @@ -419,7 +419,7 @@ namespace NadekoBot.Modules.Administration .WithDefault(Context) .Build(); - await _bot.SetGameAsync(game == null ? game : rep.Replace(game), type).ConfigureAwait(false); + await _bot.SetGameAsync(game is null ? game : rep.Replace(game), type).ConfigureAwait(false); await ReplyConfirmLocalizedAsync("set_game").ConfigureAwait(false); } @@ -448,7 +448,7 @@ namespace NadekoBot.Modules.Administration var sid = ulong.Parse(ids[0]); var server = _client.Guilds.FirstOrDefault(s => s.Id == sid); - if (server == null) + if (server is null) return; var rep = new ReplacementBuilder() @@ -459,7 +459,7 @@ namespace NadekoBot.Modules.Administration { var cid = ulong.Parse(ids[1].Substring(2)); var ch = server.TextChannels.FirstOrDefault(c => c.Id == cid); - if (ch == null) + if (ch is null) { return; } @@ -477,7 +477,7 @@ namespace NadekoBot.Modules.Administration { var uid = ulong.Parse(ids[1].Substring(2)); var user = server.Users.FirstOrDefault(u => u.Id == uid); - if (user == null) + if (user is null) { return; } diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index 1cdf85d72..c721cde39 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Administration.Services var old = conf.DelMsgOnCmdChannels.FirstOrDefault(x => x.ChannelId == chId); if (newState == Administration.State.Inherit) { - if (!(old is null)) + if (old is not null) { conf.DelMsgOnCmdChannels.Remove(old); uow.Remove(old); diff --git a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs index 0582b9bb2..b40b291f5 100644 --- a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration.Services { var roleIds = savedRoleIds .Select(roleId => user.Guild.GetRole(roleId)) - .Where(x => !(x is null)) + .Where(x => x is not null) .ToList(); if (roleIds.Any()) diff --git a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs index 228e3b92a..829cce630 100644 --- a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs @@ -101,7 +101,7 @@ DELETE FROM Clubs;"; .FirstOrDefaultAsyncEF(x => x.Waifu.UserId == userId); // if it exists, delete waifu related things - if (!(wi is null)) + if (wi is not null) { // remove updates which have new or old as this waifu await uow diff --git a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs index 1c3f3682f..04202ee3b 100644 --- a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs @@ -145,7 +145,7 @@ namespace NadekoBot.Modules.Administration.Services public async Task TryBlockLate(DiscordSocketClient client, ICommandContext context, string moduleName, CommandInfo command) { - if (TryGetOverrides(context.Guild?.Id ?? 0, command.Name, out var perm) && !(perm is null)) + if (TryGetOverrides(context.Guild?.Id ?? 0, command.Name, out var perm) && perm is not null) { var result = await new RequireUserPermissionAttribute((GuildPermission) perm) .CheckPermissionsAsync(context, command, _services); diff --git a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs index 0aebabaa1..1af4ec1eb 100644 --- a/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs +++ b/src/NadekoBot/Modules/Administration/Services/GameVoiceChannelService.cs @@ -38,7 +38,7 @@ namespace NadekoBot.Modules.Administration.Services { //if the user is in the voice channel and that voice channel is gvc var vc = after.VoiceChannel; - if (vc == null || !GameVoiceChannels.Contains(vc.Id)) + if (vc is null || !GameVoiceChannels.Contains(vc.Id)) return; //if the activity has changed, and is a playing activity @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Administration.Services var game = gUser.Activity?.Name; if (oldState.VoiceChannel == newState.VoiceChannel || - newState.VoiceChannel == null) + newState.VoiceChannel is null) return; if (!GameVoiceChannels.Contains(newState.VoiceChannel.Id) || @@ -123,7 +123,7 @@ namespace NadekoBot.Modules.Administration.Services var vch = gUser.Guild.VoiceChannels .FirstOrDefault(x => x.Name.ToLowerInvariant() == game); - if (vch == null) + if (vch is null) return; await Task.Delay(1000).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs b/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs index 0bd2018f8..5d8aa88f1 100644 --- a/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs +++ b/src/NadekoBot/Modules/Administration/Services/GuildTimezoneService.cs @@ -45,7 +45,7 @@ namespace NadekoBot.Modules.Administration.Services TimeZoneInfo tz; try { - if (x.TimeZoneId == null) + if (x.TimeZoneId is null) tz = null; else tz = TimeZoneInfo.FindSystemTimeZoneById(x.TimeZoneId); @@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Administration.Services gc.TimeZoneId = tz?.Id; uow.SaveChanges(); - if (tz == null) + if (tz is null) _timezones.TryRemove(guildId, out tz); else _timezones.AddOrUpdate(guildId, tz, (key, old) => tz); diff --git a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs index d7d02313a..7d9d09767 100644 --- a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs @@ -203,12 +203,12 @@ namespace NadekoBot.Modules.Administration.Services var g = after.Guild; if (!GuildLogSettings.TryGetValue(g.Id, out LogSetting logSetting) - || (logSetting.UserUpdatedId == null)) + || (logSetting.UserUpdatedId is null)) return; ITextChannel logChannel; if ((logChannel = - await TryGetLogChannel(g, logSetting, LogType.UserUpdated).ConfigureAwait(false)) == null) + await TryGetLogChannel(g, logSetting, LogType.UserUpdated).ConfigureAwait(false)) is null) return; var embed = new EmbedBuilder(); @@ -262,54 +262,54 @@ namespace NadekoBot.Modules.Administration.Services switch (type) { case LogType.Other: - channelId = logSetting.LogOtherId = (logSetting.LogOtherId == null ? cid : default); + channelId = logSetting.LogOtherId = (logSetting.LogOtherId is null ? cid : default); break; case LogType.MessageUpdated: - channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId == null ? cid : default); + channelId = logSetting.MessageUpdatedId = (logSetting.MessageUpdatedId is null ? cid : default); break; case LogType.MessageDeleted: - channelId = logSetting.MessageDeletedId = (logSetting.MessageDeletedId == 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 == null ? cid : default); + channelId = logSetting.UserJoinedId = (logSetting.UserJoinedId is null ? cid : default); break; case LogType.UserLeft: - channelId = logSetting.UserLeftId = (logSetting.UserLeftId == null ? cid : default); + channelId = logSetting.UserLeftId = (logSetting.UserLeftId is null ? cid : default); break; case LogType.UserBanned: - channelId = logSetting.UserBannedId = (logSetting.UserBannedId == null ? cid : default); + channelId = logSetting.UserBannedId = (logSetting.UserBannedId is null ? cid : default); break; case LogType.UserUnbanned: - channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId == null ? cid : default); + channelId = logSetting.UserUnbannedId = (logSetting.UserUnbannedId is null ? cid : default); break; case LogType.UserUpdated: - channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId == null ? cid : default); + channelId = logSetting.UserUpdatedId = (logSetting.UserUpdatedId is null ? cid : default); break; case LogType.UserMuted: - channelId = logSetting.UserMutedId = (logSetting.UserMutedId == null ? cid : default); + channelId = logSetting.UserMutedId = (logSetting.UserMutedId is null ? cid : default); break; case LogType.ChannelCreated: - channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId == null ? cid : default); + channelId = logSetting.ChannelCreatedId = (logSetting.ChannelCreatedId is null ? cid : default); break; case LogType.ChannelDestroyed: channelId = logSetting.ChannelDestroyedId = - (logSetting.ChannelDestroyedId == null ? cid : default); + (logSetting.ChannelDestroyedId is null ? cid : default); break; case LogType.ChannelUpdated: - channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId == null ? cid : default); + channelId = logSetting.ChannelUpdatedId = (logSetting.ChannelUpdatedId is null ? cid : default); break; case LogType.UserPresence: channelId = logSetting.LogUserPresenceId = - (logSetting.LogUserPresenceId == null ? cid : default); + (logSetting.LogUserPresenceId is null ? cid : default); break; case LogType.VoicePresence: channelId = logSetting.LogVoicePresenceId = - (logSetting.LogVoicePresenceId == null ? cid : default); + (logSetting.LogVoicePresenceId is null ? cid : default); break; case LogType.VoicePresenceTTS: channelId = logSetting.LogVoicePresenceTTSId = - (logSetting.LogVoicePresenceTTSId == null ? cid : default); + (logSetting.LogVoicePresenceTTSId is null ? cid : default); break; } @@ -335,12 +335,12 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.LogVoicePresenceTTSId == null)) + || (logSetting.LogVoicePresenceTTSId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresenceTTS) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var str = ""; @@ -348,11 +348,11 @@ namespace NadekoBot.Modules.Administration.Services { str = GetText(logChannel.Guild, "log_vc_moved", usr.Username, beforeVch?.Name, afterVch?.Name); } - else if (beforeVch == null) + else if (beforeVch is null) { str = GetText(logChannel.Guild, "log_vc_joined", usr.Username, afterVch.Name); } - else if (afterVch == null) + else if (afterVch is null) { str = GetText(logChannel.Guild, "log_vc_left", usr.Username, beforeVch.Name); } @@ -375,12 +375,12 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.UserMutedId == null)) + || (logSetting.UserMutedId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var mutes = ""; var mutedLocalized = GetText(logChannel.Guild, "muted_sn"); @@ -419,12 +419,12 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.UserMutedId == null)) + || (logSetting.UserMutedId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var mutes = ""; @@ -471,11 +471,11 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting) - || (logSetting.LogOtherId == null)) + || (logSetting.LogOtherId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(users.First().Guild, logSetting, LogType.Other) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var punishment = ""; @@ -642,13 +642,13 @@ namespace NadekoBot.Modules.Administration.Services var after = (IGuildChannel) cafter; if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting) - || (logSetting.ChannelUpdatedId == null) + || (logSetting.ChannelUpdatedId is null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == after.Id)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(before.Guild, logSetting, LogType.ChannelUpdated) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var embed = new EmbedBuilder().WithOkColor() @@ -698,13 +698,13 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting) - || (logSetting.ChannelDestroyedId == null) + || (logSetting.ChannelDestroyedId is null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == ch.Id)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelDestroyed) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; string title; if (ch is IVoiceChannel) @@ -738,12 +738,12 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting) - || (logSetting.ChannelCreatedId == null)) + || (logSetting.ChannelCreatedId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(ch.Guild, logSetting, LogType.ChannelCreated) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; string title; if (ch is IVoiceChannel) @@ -783,12 +783,12 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.LogVoicePresenceId == null)) + || (logSetting.LogVoicePresenceId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.VoicePresence) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; string str = null; @@ -799,14 +799,14 @@ namespace NadekoBot.Modules.Administration.Services "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), Format.Bold(beforeVch?.Name ?? ""), Format.Bold(afterVch?.Name ?? "")); } - else if (beforeVch == null) + else if (beforeVch is null) { str = "🎙" + Format.Code(PrettyCurrentTime(usr.Guild)) + GetText(logChannel.Guild, "user_vjoined", "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), Format.Bold(afterVch.Name ?? "")); } - else if (afterVch == null) + else if (afterVch is null) { str = "🎙" + Format.Code(PrettyCurrentTime(usr.Guild)) + GetText(logChannel.Guild, "user_vleft", "👤" + Format.Bold(usr.Username + "#" + usr.Discriminator), @@ -836,16 +836,16 @@ namespace NadekoBot.Modules.Administration.Services // { // var guild = optGuild.GetValueOrDefault() ?? (usr as SocketGuildUser)?.Guild; - // if (guild == null) + // if (guild is null) // return; // if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting) - // || (logSetting.LogUserPresenceId == null) + // || (logSetting.LogUserPresenceId is null) // || before.Status == after.Status) // return; // ITextChannel logChannel; - // if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) == null) + // if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserPresence)) is null) // return; // string str = ""; // if (before.Status != after.Status) @@ -878,12 +878,12 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.UserLeftId == null)) + || (logSetting.UserLeftId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var embed = new EmbedBuilder() .WithOkColor() @@ -912,12 +912,12 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) - || (logSetting.UserJoinedId == null)) + || (logSetting.UserJoinedId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserJoined) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var embed = new EmbedBuilder() @@ -953,12 +953,12 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting) - || (logSetting.UserUnbannedId == null)) + || (logSetting.UserUnbannedId is null)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserUnbanned) - .ConfigureAwait(false)) == null) + .ConfigureAwait(false)) is null) return; var embed = new EmbedBuilder() .WithOkColor() @@ -987,7 +987,7 @@ namespace NadekoBot.Modules.Administration.Services try { if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting) - || (logSetting.UserBannedId == null)) + || (logSetting.UserBannedId is null)) return; ITextChannel logChannel; @@ -1024,7 +1024,7 @@ namespace NadekoBot.Modules.Administration.Services try { var msg = (optMsg.HasValue ? optMsg.Value : null) as IUserMessage; - if (msg == null || msg.IsAuthor(_client)) + if (msg is null || msg.IsAuthor(_client)) return; if (_ignoreMessageIds.Contains(msg.Id)) @@ -1034,13 +1034,13 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) - || (logSetting.MessageDeletedId == null) + || (logSetting.MessageDeletedId is null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageDeleted) - .ConfigureAwait(false)) == null || logChannel.Id == msg.Id) + .ConfigureAwait(false)) is null || logChannel.Id == msg.Id) return; var resolvedMessage = msg.Resolve(userHandling: TagHandling.FullName); @@ -1080,7 +1080,7 @@ namespace NadekoBot.Modules.Administration.Services return; var before = (optmsg.HasValue ? optmsg.Value : null) as IUserMessage; - if (before == null) + if (before is null) return; if (!(ch is ITextChannel channel)) @@ -1093,13 +1093,13 @@ namespace NadekoBot.Modules.Administration.Services return; if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) - || (logSetting.MessageUpdatedId == null) + || (logSetting.MessageUpdatedId is null) || logSetting.IgnoredChannels.Any(ilc => ilc.ChannelId == channel.Id)) return; ITextChannel logChannel; if ((logChannel = await TryGetLogChannel(channel.Guild, logSetting, LogType.MessageUpdated) - .ConfigureAwait(false)) == null || logChannel.Id == after.Channel.Id) + .ConfigureAwait(false)) is null || logChannel.Id == after.Channel.Id) return; var embed = new EmbedBuilder() @@ -1208,7 +1208,7 @@ namespace NadekoBot.Modules.Administration.Services var channel = await guild.GetTextChannelAsync(id.Value).ConfigureAwait(false); - if (channel == null) + if (channel is null) { UnsetLogSetting(guild.Id, logChannelType); return null; diff --git a/src/NadekoBot/Modules/Administration/Services/MuteService.cs b/src/NadekoBot/Modules/Administration/Services/MuteService.cs index b0b63fbf9..168f21cdc 100644 --- a/src/NadekoBot/Modules/Administration/Services/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Services/MuteService.cs @@ -159,7 +159,7 @@ namespace NadekoBot.Modules.Administration.Services { MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet muted); - if (muted == null || !muted.Contains(usr.Id)) + if (muted is null || !muted.Contains(usr.Id)) return Task.CompletedTask; var _ = Task.Run(() => MuteUser(usr, _client.CurrentUser, reason: "Sticky mute").ConfigureAwait(false)); } @@ -259,7 +259,7 @@ namespace NadekoBot.Modules.Administration.Services } else if (type == MuteType.Voice) { - if (usr == null) + if (usr is null) return; try { @@ -270,7 +270,7 @@ namespace NadekoBot.Modules.Administration.Services } else if (type == MuteType.Chat) { - if (usr == null) + if (usr is null) return; await usr.RemoveRoleAsync(await GetMuteRole(usr.Guild).ConfigureAwait(false)).ConfigureAwait(false); UserUnmuted(usr, mod, MuteType.Chat, reason); @@ -279,7 +279,7 @@ namespace NadekoBot.Modules.Administration.Services public async Task GetMuteRole(IGuild guild) { - if (guild == null) + if (guild is null) throw new ArgumentNullException(nameof(guild)); const string defaultMuteRoleName = "nadeko-mute"; @@ -287,7 +287,7 @@ namespace NadekoBot.Modules.Administration.Services var muteRoleName = GuildMuteRoles.GetOrAdd(guild.Id, defaultMuteRoleName); var muteRole = guild.Roles.FirstOrDefault(r => r.Name == muteRoleName); - if (muteRole == null) + if (muteRole is null) { //if it doesn't exist, create it diff --git a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs index 3bd0efaae..6278f7231 100644 --- a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs +++ b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs @@ -141,7 +141,7 @@ namespace NadekoBot.Modules.Administration.Services _antiSpamGuilds[gc.GuildId] = new AntiSpamStats() { AntiSpamSettings = spam }; var alt = gc.AntiAltSetting; - if (!(alt is null)) + if (alt is not null) _antiAltGuilds[gc.GuildId] = new AntiAltStats(alt); } diff --git a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs index 3084f5051..f64071c60 100644 --- a/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/RoleCommandsService.cs @@ -53,7 +53,7 @@ namespace NadekoBot.Modules.Administration.Services var conf = confs.FirstOrDefault(x => x.MessageId == msg.Id); - if (conf == null) + if (conf is null) return; // compare emote names for backwards compatibility :facepalm: @@ -129,7 +129,7 @@ namespace NadekoBot.Modules.Administration.Services var conf = confs.FirstOrDefault(x => x.MessageId == msg.Id); - if (conf == null) + if (conf is null) return; var reactionRole = conf.ReactionRoles.FirstOrDefault(x => x.EmoteName == reaction.Emote.Name || x.EmoteName == reaction.Emote.ToString()); @@ -137,7 +137,7 @@ namespace NadekoBot.Modules.Administration.Services if (reactionRole != null) { var role = gusr.Guild.GetRole(reactionRole.RoleId); - if (role == null) + if (role is null) return; await gusr.RemoveRoleAsync(role).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs index a819ae3dc..14afce9a4 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs @@ -82,7 +82,7 @@ namespace NadekoBot.Modules.Administration.Services var (autoDelete, exclusive, roles) = GetAdAndRoles(guildUser.Guild.Id); var theRoleYouWant = roles.FirstOrDefault(r => r.RoleId == role.Id); - if (theRoleYouWant == null) + if (theRoleYouWant is null) { return (AssignResult.Err_Not_Assignable, autoDelete, null); } @@ -145,7 +145,7 @@ namespace NadekoBot.Modules.Administration.Services if (toUpdate != null) gc.SelfAssignableRoleGroupNames.Remove(toUpdate); } - else if (toUpdate == null) + else if (toUpdate is null) { gc.SelfAssignableRoleGroupNames.Add(new GroupName { @@ -170,7 +170,7 @@ namespace NadekoBot.Modules.Administration.Services { var (autoDelete, _, roles) = GetAdAndRoles(guildUser.Guild.Id); - if (roles.FirstOrDefault(r => r.RoleId == role.Id) == null) + if (roles.FirstOrDefault(r => r.RoleId == role.Id) is null) { return (RemoveResult.Err_Not_Assignable, autoDelete); } @@ -261,7 +261,7 @@ namespace NadekoBot.Modules.Administration.Services var roleModels = uow.SelfAssignableRoles.GetFromGuild(guild.Id); roles = roleModels .Select(x => (Model: x, Role: guild.GetRole(x.RoleId))); - uow.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role == null).Select(x => x.Model).ToArray()); + uow.SelfAssignableRoles.RemoveRange(roles.Where(x => x.Role is null).Select(x => x.Model).ToArray()); uow.SaveChanges(); } diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index f9cc3fbe5..f733488a3 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -74,7 +74,7 @@ namespace NadekoBot.Modules.Administration.Services var server = _client.Guilds.FirstOrDefault(g => g.Id.ToString() == guildStr) ?? _client.Guilds.FirstOrDefault(g => g.Name.Trim().ToUpperInvariant() == guildStr); - if (server == null) + if (server is null) { return; } @@ -205,7 +205,7 @@ namespace NadekoBot.Modules.Administration.Services var channels = await Task.WhenAll(_creds.OwnerIds.Select(id => { var user = _client.GetUser(id); - if (user == null) + if (user is null) return Task.FromResult(null); return user.GetOrCreateDMChannelAsync(); diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index 6c9265a92..898843129 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Administration.Services if (p != null) { var user = await guild.GetUserAsync(userId).ConfigureAwait(false); - if (user == null) + if (user is null) return null; await ApplyPunishment(guild, user, mod, p.Punishment, p.Time, p.RoleId, "Warned too many times."); @@ -146,7 +146,7 @@ namespace NadekoBot.Modules.Administration.Services if (roleId is null) return; var role = guild.GetRole(roleId.Value); - if (!(role is null)) + if (role is not null) { if (minutes == 0) await user.AddRoleAsync(role).ConfigureAwait(false); @@ -389,14 +389,14 @@ WHERE GuildId={guildId} .AsQueryable() .FirstOrDefault(x => x.GuildId == guildId); - if (text == null) + if (text is null) { if (template is null) return; uow.Remove(template); } - else if (template == null) + else if (template is null) { uow.BanTemplates.Add(new BanTemplate() { diff --git a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs index 3f2739c75..0cf1e4aee 100644 --- a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs @@ -106,7 +106,7 @@ namespace NadekoBot.Modules.Administration.Services { await Task.Yield(); var g = _client.GetGuild(gconf.GuildId); - if (g == null) + if (g is null) return; var infos = new ConcurrentDictionary(); @@ -115,7 +115,7 @@ namespace NadekoBot.Modules.Administration.Services foreach (var ri in gconf.VcRoleInfos) { var role = g.GetRole(ri.RoleId); - if (role == null) + if (role is null) { missingRoles.Add(ri); continue; @@ -137,7 +137,7 @@ namespace NadekoBot.Modules.Administration.Services public void AddVcRole(ulong guildId, IRole role, ulong vcId) { - if (role == null) + if (role is null) throw new ArgumentNullException(nameof(role)); var guildVcRoles = VcRoles.GetOrAdd(guildId, new ConcurrentDictionary()); @@ -184,7 +184,7 @@ namespace NadekoBot.Modules.Administration.Services { var gusr = usr as SocketGuildUser; - if (gusr == null) + if (gusr is null) return Task.CompletedTask; var oldVc = oldState.VoiceChannel; diff --git a/src/NadekoBot/Modules/Administration/TimeZoneCommands.cs b/src/NadekoBot/Modules/Administration/TimeZoneCommands.cs index 846320a8f..be72b56d1 100644 --- a/src/NadekoBot/Modules/Administration/TimeZoneCommands.cs +++ b/src/NadekoBot/Modules/Administration/TimeZoneCommands.cs @@ -76,7 +76,7 @@ namespace NadekoBot.Modules.Administration try { tz = TimeZoneInfo.FindSystemTimeZoneById(id); } catch { tz = null; } - if (tz == null) + if (tz is null) { await ReplyErrorLocalizedAsync("timezone_not_found").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs index c0a12f36f..73f1e0572 100644 --- a/src/NadekoBot/Modules/Administration/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/UserPunishCommands.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Administration var embed = new EmbedBuilder() .WithOkColor(); - if (punishment == null) + if (punishment is null) { embed.WithDescription(GetText("user_warned", Format.Bold(user.ToString()))); @@ -430,7 +430,7 @@ namespace NadekoBot.Modules.Administration { var defaultMessage = GetText("bandm", Format.Bold(ctx.Guild.Name), msg); var embed = _service.GetBanUserDmEmbed(Context, guildUser, defaultMessage, msg, time.Time); - if (!(embed is null)) + if (embed is not null) { var userChannel = await guildUser.GetOrCreateDMChannelAsync(); await userChannel.EmbedAsync(embed); @@ -497,7 +497,7 @@ namespace NadekoBot.Modules.Administration { var defaultMessage = GetText("bandm", Format.Bold(ctx.Guild.Name), msg); var embed = _service.GetBanUserDmEmbed(Context, user, defaultMessage, msg, null); - if (!(embed is null)) + if (embed is not null) { var userChannel = await user.GetOrCreateDMChannelAsync(); await userChannel.EmbedAsync(embed); @@ -613,7 +613,7 @@ namespace NadekoBot.Modules.Administration var bun = bans.FirstOrDefault(x => x.User.ToString().ToLowerInvariant() == user.ToLowerInvariant()); - if (bun == null) + if (bun is null) { await ReplyErrorLocalizedAsync("user_not_found").ConfigureAwait(false); return; @@ -632,7 +632,7 @@ namespace NadekoBot.Modules.Administration var bun = bans.FirstOrDefault(x => x.User.Id == userId); - if (bun == null) + if (bun is null) { await ReplyErrorLocalizedAsync("user_not_found").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Administration/VcRoleCommands.cs b/src/NadekoBot/Modules/Administration/VcRoleCommands.cs index 098dbe194..84ef3323e 100644 --- a/src/NadekoBot/Modules/Administration/VcRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/VcRoleCommands.cs @@ -41,13 +41,13 @@ namespace NadekoBot.Modules.Administration var vc = user.VoiceChannel; - if (vc == null || vc.GuildId != user.GuildId) + if (vc is null || vc.GuildId != user.GuildId) { await ReplyErrorLocalizedAsync("must_be_in_voice").ConfigureAwait(false); return; } - if (role == null) + if (role is null) { if (_service.RemoveVcRole(ctx.Guild.Id, vc.Id)) { diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index d29e9d442..99bfa00ff 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -23,7 +23,7 @@ namespace NadekoBot.Modules.CustomReactions _clientFactory = clientFactory; } - private bool AdminInGuildOrOwnerInDm() => (ctx.Guild == null && _creds.IsOwner(ctx.User)) + private bool AdminInGuildOrOwnerInDm() => (ctx.Guild is null && _creds.IsOwner(ctx.User)) || (ctx.Guild != null && ((IGuildUser)ctx.User).GuildPermissions.Administrator); [NadekoCommand, Usage, Description, Aliases] @@ -56,7 +56,7 @@ namespace NadekoBot.Modules.CustomReactions if (string.IsNullOrWhiteSpace(message) || id < 0) return; - if ((channel == 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("insuff_perms").ConfigureAwait(false); return; @@ -87,7 +87,7 @@ namespace NadekoBot.Modules.CustomReactions var customReactions = _service.GetCustomReactionsFor(ctx.Guild?.Id); - if (customReactions == null || !customReactions.Any()) + if (customReactions is null || !customReactions.Any()) { await ReplyErrorLocalizedAsync("no_found").ConfigureAwait(false); return; @@ -139,7 +139,7 @@ namespace NadekoBot.Modules.CustomReactions { var found = _service.GetCustomReaction(ctx.Guild?.Id, (int)id); - if (found == null) + if (found is null) { await ReplyErrorLocalizedAsync("no_found_id").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs index d6fe1c4ec..95a8c35e6 100644 --- a/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs +++ b/src/NadekoBot/Modules/CustomReactions/Extensions/Extensions.cs @@ -37,7 +37,7 @@ namespace NadekoBot.Modules.CustomReactions.Extensions var img = (elems.ElementAtOrDefault(new NadekoRandom().Next(0, elems.Length))?.Children?.FirstOrDefault() as IHtmlImageElement); - if (img?.Source == null) + if (img?.Source is null) return ""; return " " + img.Source.Replace("b.", ".", StringComparison.InvariantCulture) + " "; diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index adc6b345b..1c30e6fbd 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -237,7 +237,7 @@ namespace NadekoBot.Modules.CustomReactions.Services using var uow = _db.GetDbContext(); var cr = uow.CustomReactions.GetById(id); - if (cr == null || cr.GuildId != guildId) + if (cr is null || cr.GuildId != guildId) return null; // disable allowtarget if message had target, but it was removed from it @@ -268,7 +268,7 @@ namespace NadekoBot.Modules.CustomReactions.Services if (toDelete is null) return null; - if ((toDelete.IsGlobal() && guildId == null) || (guildId == toDelete.GuildId)) + if ((toDelete.IsGlobal() && guildId is null) || (guildId == toDelete.GuildId)) { uow.CustomReactions.Remove(toDelete); await uow.SaveChangesAsync(); @@ -309,7 +309,7 @@ namespace NadekoBot.Modules.CustomReactions.Services if (_newGuildReactions.TryGetValue(channel.Guild.Id, out var reactions) && reactions.Length > 0) { var cr = MatchCustomReactions(content, reactions); - if (!(cr is null)) + if (cr is not null) return cr; } @@ -375,7 +375,7 @@ namespace NadekoBot.Modules.CustomReactions.Services return null; var cancelled = result.FirstOrDefault(x => x.Response == "-"); - if (!(cancelled is null)) + if (cancelled is not null) return cancelled; return result[_rng.Next(0, result.Count)]; @@ -551,7 +551,7 @@ namespace NadekoBot.Modules.CustomReactions.Services lock (_gcrWriteLock) { var cr = Array.Find(_globalReactions, item => item.Id == id); - if (!(cr is null)) + if (cr is not null) { return _pubSub.Pub(_gcrDeletedkey, cr.Id); } @@ -629,7 +629,7 @@ namespace NadekoBot.Modules.CustomReactions.Services { using var uow = _db.GetDbContext(); var cr = uow.CustomReactions.GetById(id); - if (cr == null || cr.GuildId != guildId) + if (cr is null || cr.GuildId != guildId) return null; return cr; diff --git a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs index 794241d38..29931c952 100644 --- a/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs +++ b/src/NadekoBot/Modules/Gambling/AnimalRacingCommands.cs @@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Gambling var msg = raceMessage; - if (msg == null) + if (msg is null) raceMessage = await ctx.Channel.SendConfirmAsync(text) .ConfigureAwait(false); else diff --git a/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs b/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs index ddb151204..b2f21da9f 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Blackjack/Blackjack.cs @@ -345,7 +345,7 @@ namespace NadekoBot.Modules.Gambling.Common.Blackjack public Task PrintState() { - if (StateUpdated == null) + if (StateUpdated is null) return Task.CompletedTask; return StateUpdated.Invoke(this); } diff --git a/src/NadekoBot/Modules/Gambling/Common/Deck.cs b/src/NadekoBot/Modules/Gambling/Common/Deck.cs index f5b4df6c8..7e87a6cfa 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Deck.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Deck.cs @@ -300,7 +300,7 @@ namespace NadekoBot.Modules.Gambling.Common public static string GetHandValue(List cards) { - if (handValues == null) + if (handValues is null) InitHandValues(); foreach (var kvp in handValues.Where(x => x.Value(cards))) { diff --git a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs index 5000909e6..b1cbeb5d2 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs @@ -169,12 +169,12 @@ namespace NadekoBot.Modules.Gambling.Common.Events if (_emote.Name != r.Emote.Name) return; var gu = (r.User.IsSpecified ? r.User.Value : null) as IGuildUser; - if (gu == null // no unknown users, as they could be bots, or alts + if (gu is null // no unknown users, as they could be bots, or alts || 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 == null || (DateTime.UtcNow - gu.JoinedAt.Value).TotalDays < 1))) // and no users for who we don't know when they joined + (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 9a781fd11..40fcc0fbf 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs @@ -98,7 +98,7 @@ namespace NadekoBot.Modules.Gambling.Common.Connect4 await _locker.WaitAsync().ConfigureAwait(false); try { - if (_players[1] == null) + if (_players[1] is null) { var __ = OnGameFailedToStart?.Invoke(this); CurrentPhase = Phase.Ended; diff --git a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs index c3c6231da..58bbe5fd0 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs @@ -168,7 +168,7 @@ namespace NadekoBot.Modules.Gambling .WithOkColor(); - if (msg == null) + if (msg is null) msg = await ctx.Channel.EmbedAsync(embed).ConfigureAwait(false); else await msg.ModifyAsync(x => x.Embed = embed.Build()).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/DrawCommands.cs b/src/NadekoBot/Modules/Gambling/DrawCommands.cs index d5024bc73..b63a69e25 100644 --- a/src/NadekoBot/Modules/Gambling/DrawCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DrawCommands.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Gambling if (num < 1 || num > 10) throw new ArgumentOutOfRangeException(nameof(num)); - Deck cards = guildId == null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck()); + Deck cards = guildId is null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck()); var images = new List>(); var cardObjects = new List(); for (var i = 0; i < num; i++) diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index ee1d01344..a0aac6723 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -413,7 +413,7 @@ namespace NadekoBot.Modules.Gambling -- "; - if (rdMsg == null) + if (rdMsg is null) { rdMsg = await ctx.Channel.EmbedAsync(embed) .ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs b/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs index 6c0b23325..751bff6df 100644 --- a/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs @@ -92,7 +92,7 @@ namespace NadekoBot.Modules.Gambling.Services { SocketGuild g = _client.GetGuild(guildId); SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel; - if (ch == null) + if (ch is null) return false; ICurrencyEvent ce; diff --git a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs index 635474369..1cadf5025 100644 --- a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs @@ -182,7 +182,7 @@ namespace NadekoBot.Modules.Gambling.Services private Task PotentialFlowerGeneration(IUserMessage imsg) { var msg = imsg as SocketUserMessage; - if (msg == null || msg.Author.IsBot) + if (msg is null || msg.Author.IsBot) return Task.CompletedTask; if (!(imsg.Channel is ITextChannel channel)) @@ -351,7 +351,7 @@ namespace NadekoBot.Modules.Gambling.Services { // try to send the message with the currency image var msgId = await SendPlantMessageAsync(gid, ch, user, amount, pass).ConfigureAwait(false); - if (msgId == null) + if (msgId is null) { // if it fails it will return null, if it returns null, refund await _cs.AddAsync(uid, "Planted currency refund", amount, gamble: false); diff --git a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs index f49e739ce..93bbfaf7b 100644 --- a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs @@ -49,7 +49,7 @@ namespace NadekoBot.Modules.Gambling.Services var ownerUser = uow.GetOrCreateUser(owner); // owner has to be the owner of the waifu - if (waifu == null || waifu.ClaimerId != ownerUser.Id) + if (waifu is null || waifu.ClaimerId != ownerUser.Id) return false; // if waifu likes the person, gotta pay the penalty @@ -97,7 +97,7 @@ namespace NadekoBot.Modules.Gambling.Services { var waifu = uow.WaifuInfo.ByWaifuUserId(user.Id); - if (waifu == null) + if (waifu is null) return settings.Waifu.MinPrice; var divorces = uow.WaifuUpdates.Count(x => x.Old != null && @@ -168,7 +168,7 @@ namespace NadekoBot.Modules.Gambling.Services { w = uow.WaifuInfo.ByWaifuUserId(target.Id); isAffinity = (w?.Affinity?.UserId == user.Id); - if (w == null) + if (w is null) { var claimer = uow.GetOrCreateUser(user); var waifu = uow.GetOrCreateUser(target); @@ -257,14 +257,14 @@ namespace NadekoBot.Modules.Gambling.Services using (var uow = _db.GetDbContext()) { var w = uow.WaifuInfo.ByWaifuUserId(user.Id); - var newAff = target == null ? null : uow.GetOrCreateUser(target); + var newAff = target is null ? null : uow.GetOrCreateUser(target); if (w?.Affinity?.UserId == target?.Id) { } else if (!_cache.TryAddAffinityCooldown(user.Id, out remaining)) { } - else if (w == null) + else if (w is null) { var thisUser = uow.GetOrCreateUser(user); uow.WaifuInfo.Add(new WaifuInfo() @@ -330,7 +330,7 @@ namespace NadekoBot.Modules.Gambling.Services { w = uow.WaifuInfo.ByWaifuUserId(targetId); var now = DateTime.UtcNow; - if (w?.Claimer == null || w.Claimer.UserId != user.Id) + if (w?.Claimer is null || w.Claimer.UserId != user.Id) result = DivorceResult.NotYourWife; else if (!_cache.TryAddDivorceCooldown(user.Id, out remaining)) { @@ -383,7 +383,7 @@ namespace NadekoBot.Modules.Gambling.Services var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id, set => set.Include(x => x.Items) .Include(x => x.Claimer)); - if (w == null) + if (w is null) { uow.WaifuInfo.Add(w = new WaifuInfo() { diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index e490ac219..23f8be744 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -104,7 +104,7 @@ namespace NadekoBot.Modules.Gambling uow.SaveChanges(); } - if (entry == null) + if (entry is null) { await ReplyErrorLocalizedAsync("shop_item_not_found").ConfigureAwait(false); return; @@ -115,7 +115,7 @@ namespace NadekoBot.Modules.Gambling var guser = (IGuildUser)ctx.User; var role = ctx.Guild.GetRole(entry.RoleId); - if (role == null) + if (role is null) { await ReplyErrorLocalizedAsync("shop_role_not_found").ConfigureAwait(false); return; @@ -306,7 +306,7 @@ namespace NadekoBot.Modules.Gambling } } } - if (entry == null) + if (entry is null) await ReplyErrorLocalizedAsync("shop_item_not_found").ConfigureAwait(false); else if (!rightType) await ReplyErrorLocalizedAsync("shop_item_wrong_type").ConfigureAwait(false); @@ -341,7 +341,7 @@ namespace NadekoBot.Modules.Gambling } } - if (removed == null) + if (removed is null) await ReplyErrorLocalizedAsync("shop_item_not_found").ConfigureAwait(false); else await ctx.Channel.EmbedAsync(EntryToEmbed(removed) diff --git a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs index ec2191efd..f3343485e 100644 --- a/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs +++ b/src/NadekoBot/Modules/Gambling/WaifuClaimCommands.cs @@ -187,11 +187,11 @@ namespace NadekoBot.Modules.Gambling } return; } - if (u == null) + if (u is null) { await ReplyConfirmLocalizedAsync("waifu_affinity_reset"); } - else if (oldAff == null) + else if (oldAff is null) { await ReplyConfirmLocalizedAsync("waifu_affinity_set", Format.Bold(u.ToString())); } @@ -240,7 +240,7 @@ namespace NadekoBot.Modules.Gambling [Priority(1)] public Task WaifuInfo([Leftover]IUser target = null) { - if (target == null) + if (target is null) target = ctx.User; return InternalWaifuInfo(target.Id, target.ToString()); diff --git a/src/NadekoBot/Modules/Games/Common/PollRunner.cs b/src/NadekoBot/Modules/Games/Common/PollRunner.cs index 3e203266c..7becede5b 100644 --- a/src/NadekoBot/Modules/Games/Common/PollRunner.cs +++ b/src/NadekoBot/Modules/Games/Common/PollRunner.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Games.Common { // has to be a user message // channel must be the same the poll started in - if (msg == null || msg.Author.IsBot || msg.Channel.Id != Poll.ChannelId) + if (msg is null || msg.Author.IsBot || msg.Channel.Id != Poll.ChannelId) return false; // has to be an integer @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Games.Common return false; var usr = msg.Author as IGuildUser; - if (usr == null) + if (usr is null) return false; voteObj = new PollVote() diff --git a/src/NadekoBot/Modules/Games/Common/TicTacToe.cs b/src/NadekoBot/Modules/Games/Common/TicTacToe.cs index e7295564f..022ad4dcb 100644 --- a/src/NadekoBot/Modules/Games/Common/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/Common/TicTacToe.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Games.Common { for (var j = 0; j < _state.GetLength(1); j++) { - sb.Append(_state[i, j] == null ? _numbers[i * 3 + j] : GetIcon(_state[i, j])); + sb.Append(_state[i, j] is null ? _numbers[i * 3 + j] : GetIcon(_state[i, j])); if (j < _state.GetLength(1) - 1) sb.Append("┃"); } @@ -102,7 +102,7 @@ namespace NadekoBot.Modules.Games.Common if (!string.IsNullOrWhiteSpace(title)) embed.WithTitle(title); - if (_winner == null) + if (_winner is null) { if (_phase == Phase.Ended) embed.WithFooter(efb => efb.WithText(GetText("ttt_no_moves"))); @@ -192,7 +192,7 @@ namespace NadekoBot.Modules.Games.Common { for (var j = 0; j < 3; j++) { - if (_state[i, j] == null) + if (_state[i, j] is null) return false; } } @@ -213,7 +213,7 @@ namespace NadekoBot.Modules.Games.Common if (int.TryParse(msg.Content, out var index) && --index >= 0 && index <= 9 && - _state[index / 3, index % 3] == null) + _state[index / 3, index % 3] is null) { _state[index / 3, index % 3] = _curUserIndex; diff --git a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs index ef5977f59..fafa44ba4 100644 --- a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaGame.cs @@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Games.Common.Trivia var umsg = imsg as SocketUserMessage; var textChannel = umsg?.Channel as ITextChannel; - if (textChannel == null || textChannel.Guild != Guild) + if (textChannel is null || textChannel.Guild != Guild) return; var guildUser = (IGuildUser)umsg.Author; diff --git a/src/NadekoBot/Modules/Games/Common/TypingGame.cs b/src/NadekoBot/Modules/Games/Common/TypingGame.cs index 3cc7e81b5..86f554b10 100644 --- a/src/NadekoBot/Modules/Games/Common/TypingGame.cs +++ b/src/NadekoBot/Modules/Games/Common/TypingGame.cs @@ -143,10 +143,10 @@ namespace NadekoBot.Modules.Games.Common if (imsg.Author.IsBot) return; var msg = imsg as SocketUserMessage; - if (msg == null) + if (msg is null) return; - if (this.Channel == null || this.Channel.Id != msg.Channel.Id) return; + if (this.Channel is null || this.Channel.Id != msg.Channel.Id) return; var guess = msg.Content; diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index b2eb412cf..cb95a73c9 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -61,7 +61,7 @@ namespace NadekoBot.Modules.Games var gr = _service.GirlRatings.GetOrAdd(usr.Id, GetGirl); var originalStream = await gr.Stream; - if (originalStream == null) + if (originalStream is null) { await ReplyErrorLocalizedAsync("something_went_wrong").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Games/HangmanCommands.cs b/src/NadekoBot/Modules/Games/HangmanCommands.cs index c891a49eb..e2e362660 100644 --- a/src/NadekoBot/Modules/Games/HangmanCommands.cs +++ b/src/NadekoBot/Modules/Games/HangmanCommands.cs @@ -85,7 +85,7 @@ namespace NadekoBot.Modules.Games Task Hm_OnGameEnded(Hangman game, string winner) { - if (winner == null) + if (winner is null) { var loseEmbed = new EmbedBuilder().WithTitle($"Hangman Game ({game.TermType}) - Ended") .WithDescription(Format.Bold("You lose.")) diff --git a/src/NadekoBot/Modules/Games/NunchiCommands.cs b/src/NadekoBot/Modules/Games/NunchiCommands.cs index a3877ed0f..162f29d5b 100644 --- a/src/NadekoBot/Modules/Games/NunchiCommands.cs +++ b/src/NadekoBot/Modules/Games/NunchiCommands.cs @@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Games game.Dispose(); } - if (arg2 == null) + if (arg2 is null) return ConfirmLocalizedAsync("nunchi_ended_no_winner", Format.Bold(arg2)); else return ConfirmLocalizedAsync("nunchi_ended", Format.Bold(arg2)); diff --git a/src/NadekoBot/Modules/Games/PollCommands.cs b/src/NadekoBot/Modules/Games/PollCommands.cs index a5b380165..ef3bf7a01 100644 --- a/src/NadekoBot/Modules/Games/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/PollCommands.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Games var poll = _service.CreatePoll(ctx.Guild.Id, ctx.Channel.Id, arg); - if(poll == null) + if(poll is null) { await ReplyErrorLocalizedAsync("poll_invalid_input").ConfigureAwait(false); return; @@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Games var channel = (ITextChannel)ctx.Channel; Poll p; - if ((p = _service.StopPoll(ctx.Guild.Id)) == null) + if ((p = _service.StopPoll(ctx.Guild.Id)) is null) return; var embed = GetStats(p, GetText("poll_closed")); diff --git a/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs b/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs index f78dc7bdd..7682d855c 100644 --- a/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs +++ b/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs @@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Games.Services var channel = msg.Channel as ITextChannel; cleverbot = null; - if (channel == null) + if (channel is null) return null; if (!ChatterBotGuilds.TryGetValue(channel.Guild.Id, out Lazy lazyCleverbot)) @@ -110,7 +110,7 @@ namespace NadekoBot.Modules.Games.Services try { var message = PrepareMessage(usrMsg, out IChatterBotSession cbs); - if (message == null || cbs == null) + if (message is null || cbs is null) return false; var pc = _perms.GetCacheFor(guild.Id); diff --git a/src/NadekoBot/Modules/Games/Services/PollService.cs b/src/NadekoBot/Modules/Games/Services/PollService.cs index 2d9ccc102..91b236b22 100644 --- a/src/NadekoBot/Modules/Games/Services/PollService.cs +++ b/src/NadekoBot/Modules/Games/Services/PollService.cs @@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Games.Services public async Task RunBehavior(DiscordSocketClient client, IGuild guild, IUserMessage msg) { - if (guild == null) + if (guild is null) return false; if (!ActivePolls.TryGetValue(guild.Id, out var poll)) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 874ece0e6..3b6a3647b 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -268,7 +268,7 @@ namespace NadekoBot.Modules.Help { var channel = ctx.Channel; - if (com == null) + if (com is null) { IMessageChannel ch = channel is ITextChannel ? await ((IGuildUser)ctx.User).GetOrCreateDMChannelAsync().ConfigureAwait(false) diff --git a/src/NadekoBot/Modules/Help/Services/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs index 753528e9c..ce355402d 100644 --- a/src/NadekoBot/Modules/Help/Services/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -43,7 +43,7 @@ namespace NadekoBot.Modules.Help.Services public Task LateExecute(DiscordSocketClient client, IGuild guild, IUserMessage msg) { var settings = _bss.Data; - if (guild == null) + if (guild is null) { if (string.IsNullOrWhiteSpace(settings.DmHelpText) || settings.DmHelpText == "-") return Task.CompletedTask; @@ -136,7 +136,7 @@ namespace NadekoBot.Modules.Help.Services .FirstOrDefault(ca => ca is UserPermAttribute); string userPermString = string.Empty; - if (!(userPerm is null)) + if (userPerm is not null) { if (userPerm.UserPermissionAttribute.ChannelPermission is ChannelPermission cPerm) userPermString = GetPreconditionString((ChannelPerm) cPerm); diff --git a/src/NadekoBot/Modules/Music/Common/Resolvers/LocalTrackResolver.cs b/src/NadekoBot/Modules/Music/Common/Resolvers/LocalTrackResolver.cs index 915a51851..c02988189 100644 --- a/src/NadekoBot/Modules/Music/Common/Resolvers/LocalTrackResolver.cs +++ b/src/NadekoBot/Modules/Music/Common/Resolvers/LocalTrackResolver.cs @@ -64,7 +64,7 @@ namespace NadekoBot.Modules.Music.Resolvers yield break; var firstData = await ResolveByQueryAsync(firstFile); - if (!(firstData is null)) + if (firstData is not null) yield return firstData; var fileChunks = files.Skip(1).Chunk(10); diff --git a/src/NadekoBot/Modules/Music/Common/Resolvers/SoundcloudResolver.cs b/src/NadekoBot/Modules/Music/Common/Resolvers/SoundcloudResolver.cs index d96ce5af9..ac920323d 100644 --- a/src/NadekoBot/Modules/Music/Common/Resolvers/SoundcloudResolver.cs +++ b/src/NadekoBot/Modules/Music/Common/Resolvers/SoundcloudResolver.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Modules.Music.Resolvers public async Task ResolveByQueryAsync(string query) { var cached = await _trackCacher.GetCachedDataByQueryAsync(query, MusicPlatform.SoundCloud); - if (!(cached is null)) + if (cached is not null) return CachableDataToTrackInfo(cached); var svideo = !IsSoundCloudLink(query) diff --git a/src/NadekoBot/Modules/Music/Common/_OldMusicPlayer.cs b/src/NadekoBot/Modules/Music/Common/_OldMusicPlayer.cs index 3541b2fc6..711342da3 100644 --- a/src/NadekoBot/Modules/Music/Common/_OldMusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/Common/_OldMusicPlayer.cs @@ -199,7 +199,7 @@ // //Log.Information("Buffered. Getting audio client..."); // var ac = await GetAudioClient().ConfigureAwait(false); // Log.Information("Got Audio client"); -// if (ac == null) +// if (ac is null) // { // Log.Information("Can't join"); // await Task.Delay(900, cancelToken).ConfigureAwait(false); @@ -371,7 +371,7 @@ // // private async Task GetAudioClient(bool reconnect = false) // { -// if (_audioClient == null || +// if (_audioClient is null || // _audioClient.ConnectionState != ConnectionState.Connected || // reconnect || // newVoiceChannel) @@ -529,7 +529,7 @@ // { // lock (locker) // { -// if (PauseTaskSource == null) +// if (PauseTaskSource is null) // PauseTaskSource = new TaskCompletionSource(); // else // { diff --git a/src/NadekoBot/Modules/Music/Common/_OldMusicQueue.cs b/src/NadekoBot/Modules/Music/Common/_OldMusicQueue.cs index 6af5f99ce..f489f803b 100644 --- a/src/NadekoBot/Modules/Music/Common/_OldMusicQueue.cs +++ b/src/NadekoBot/Modules/Music/Common/_OldMusicQueue.cs @@ -86,7 +86,7 @@ // if (MaxQueueSize != 0 && Songs.Count >= MaxQueueSize) // throw new QueueFullException(); // var curSong = Current.Song; -// if (curSong == null) +// if (curSong is null) // { // Songs.AddLast(song); // return Songs.Count; diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 62e8701cc..1775c4507 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -285,7 +285,7 @@ namespace NadekoBot.Modules.Music { string desc = string.Empty; var current = mp.GetCurrentTrack(out var currentIndex); - if (!(current is null)) + if (current is not null) { desc = $"`🔊` {current.PrettyFullName()}\n\n" + desc; } @@ -371,7 +371,7 @@ namespace NadekoBot.Modules.Music try { var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id).ConfigureAwait(false); - if (input == null + if (input is null || !int.TryParse(input, out var index) || (index -= 1) < 0 || index >= videos.Count) @@ -699,7 +699,7 @@ namespace NadekoBot.Modules.Music } var currentTrack = mp.GetCurrentTrack(out _); - if (currentTrack == null) + if (currentTrack is null) return; var embed = new EmbedBuilder().WithOkColor() diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index a12571e6a..9b8423eb9 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -213,7 +213,7 @@ namespace NadekoBot.Modules.Music mpl = uow.MusicPlaylists.GetWithSongs(id); } - if (mpl == null) + if (mpl is null) { await ReplyErrorLocalizedAsync("playlist_id_not_found").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index 146b209e8..79bf879c1 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -313,7 +313,7 @@ namespace NadekoBot.Modules.Music.Services { var randomPlayingTrack = _players .Select(x => x.Value.GetCurrentTrack(out _)) - .Where(x => !(x is null)) + .Where(x => x is not null) .Shuffle() .FirstOrDefault(); @@ -328,7 +328,7 @@ namespace NadekoBot.Modules.Music.Services { var count = _players .Select(x => x.Value.GetCurrentTrack(out _)) - .Count(x => !(x is null)); + .Count(x => x is not null); return count.ToString(); }); diff --git a/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs b/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs index 37b62f3ff..82114b1ea 100644 --- a/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/_OldMusicService.cs @@ -100,7 +100,7 @@ // string GetText(string text, params object[] replacements) => // _strings.GetText(text, textCh.Guild.Id, replacements); // -// if (voiceCh == null || voiceCh.Guild != textCh.Guild) +// if (voiceCh is null || voiceCh.Guild != textCh.Guild) // { // if (textCh != null) // { @@ -139,7 +139,7 @@ // } // // var (Index, Current) = mp.Current; -// if (Current == null +// if (Current is null // && !mp.RepeatCurrentSong // && !mp.RepeatPlaylist // && !mp.FairPlay @@ -161,7 +161,7 @@ // // // ignored // //} // var sender = player; -// if (sender == null) +// if (sender is null) // return; // try // { @@ -215,7 +215,7 @@ // return; // // var si = await ResolveSong(related[new NadekoRandom().Next(related.Length)], _client.CurrentUser.ToString(), MusicType.YouTube).ConfigureAwait(false); -// if (si == null) +// if (si is null) // throw new SongNotFoundException(); // var mp = await GetOrCreatePlayer(txtCh.GuildId, vch, txtCh).ConfigureAwait(false); // mp.Enqueue(si); @@ -229,7 +229,7 @@ // var strategy = await resolverFactory.GetResolveStrategy(query, musicType).ConfigureAwait(false); // var sinfo = await strategy.ResolveSong(query).ConfigureAwait(false); // -// if (sinfo == null) +// if (sinfo is null) // return null; // // sinfo.QueuerName = queuerName; diff --git a/src/NadekoBot/Modules/Music/_OldMusic.cs b/src/NadekoBot/Modules/Music/_OldMusic.cs index 83bb2706b..1a7137be7 100644 --- a/src/NadekoBot/Modules/Music/_OldMusic.cs +++ b/src/NadekoBot/Modules/Music/_OldMusic.cs @@ -51,13 +51,13 @@ // // var t = Task.Run(() => // // { // // var usr = iusr as SocketGuildUser; -// // if (usr == null || +// // if (usr is null || // // oldState.VoiceChannel == newState.VoiceChannel) // // return; // // // var player = _music.GetPlayerOrDefault(usr.Guild.Id); // -// // if (player == null) +// // if (player is null) // // return; // // // try @@ -97,7 +97,7 @@ // // private async Task InternalQueue(MusicPlayer mp, SongInfo songInfo, bool silent, bool queueFirst = false, bool forcePlay = false) // { -// if (songInfo == null) +// if (songInfo is null) // { // if (!silent) // await ReplyErrorLocalizedAsync("song_not_found").ConfigureAwait(false); @@ -216,7 +216,7 @@ // try // { // var input = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id).ConfigureAwait(false); -// if (input == null +// if (input is null // || !int.TryParse(input, out var index) // || (index -= 1) < 0 // || index >= videos.Length) @@ -436,7 +436,7 @@ // public async Task SongRemove(All _) // { // var mp = _service.GetPlayerOrDefault(ctx.Guild.Id); -// if (mp == null) +// if (mp is null) // return; // mp.Stop(true); // await ReplyConfirmLocalizedAsync("queue_cleared").ConfigureAwait(false); @@ -576,7 +576,7 @@ // mpl = uow.MusicPlaylists.GetWithSongs(id); // } // -// if (mpl == null) +// if (mpl is null) // { // await ReplyErrorLocalizedAsync("playlist_id_not_found").ConfigureAwait(false); // return; @@ -700,7 +700,7 @@ // { // var mp = await _service.GetOrCreatePlayer(Context).ConfigureAwait(false); // var (_, currentSong) = mp.Current; -// if (currentSong == null) +// if (currentSong is null) // return; // try { await mp.UpdateSongDurationsAsync().ConfigureAwait(false); } catch { } // @@ -744,7 +744,7 @@ // Log.Warning(ex.Message); // } // -// if (plId == null) +// if (plId is null) // { // await ReplyErrorLocalizedAsync("no_search_results").ConfigureAwait(false); // return; @@ -834,12 +834,12 @@ // { // var vch = ((IGuildUser)ctx.User).VoiceChannel; // -// if (vch == null) +// if (vch is null) // return; // // var mp = _service.GetPlayerOrDefault(ctx.Guild.Id); // -// if (mp == null) +// if (mp is null) // return; // // await mp.SetVoiceChannel(vch).ConfigureAwait(false); @@ -853,7 +853,7 @@ // return; // // MusicPlayer mp = _service.GetPlayerOrDefault(ctx.Guild.Id); -// if (mp == null) +// if (mp is null) // return; // // fromto = fromto?.Trim(); @@ -862,7 +862,7 @@ // SongInfo s; // if (fromtoArr.Length != 2 || !int.TryParse(fromtoArr[0], out var n1) || // !int.TryParse(fromtoArr[1], out var n2) || n1 < 1 || n2 < 1 || n1 == n2 -// || (s = mp.MoveSong(--n1, --n2)) == null) +// || (s = mp.MoveSong(--n1, --n2)) is null) // { // await ReplyConfirmLocalizedAsync("invalid_input").ConfigureAwait(false); // return; @@ -916,7 +916,7 @@ // { // var mp = await _service.GetOrCreatePlayer(Context).ConfigureAwait(false); // var (_, currentSong) = mp.Current; -// if (currentSong == null) +// if (currentSong is null) // return; // var currentValue = mp.ToggleRepeatSong(); // diff --git a/src/NadekoBot/Modules/Nsfw/Nsfw.cs b/src/NadekoBot/Modules/Nsfw/Nsfw.cs index 49328a3ae..55c90e570 100644 --- a/src/NadekoBot/Modules/Nsfw/Nsfw.cs +++ b/src/NadekoBot/Modules/Nsfw/Nsfw.cs @@ -55,13 +55,13 @@ namespace NadekoBot.Modules.NSFW img = await _service.DapiSearch(tag, type, ctx.Guild?.Id, true).ConfigureAwait(false); // if i can't find the image, ran out of providers, or tag is blacklisted // return the error - if (img == null && !listOfProviders.Any()) + if (img is null && !listOfProviders.Any()) { await ReplyErrorLocalizedAsync("no_results").ConfigureAwait(false); return; } - } while (img == null); + } while (img is null); await channel.EmbedAsync(new EmbedBuilder().WithOkColor() .WithImageUrl(img.FileUrl) @@ -129,7 +129,7 @@ namespace NadekoBot.Modules.NSFW { try { - if (tagsArr == null || tagsArr.Length == 0) + if (tagsArr is null || tagsArr.Length == 0) await InternalHentai(ctx.Channel, null).ConfigureAwait(false); else await InternalHentai(ctx.Channel, tagsArr[new NadekoRandom().Next(0, tagsArr.Length)]).ConfigureAwait(false); @@ -252,7 +252,7 @@ namespace NadekoBot.Modules.NSFW _service.DapiSearch(tag, DapiSearchType.Yandere, ctx.Guild?.Id, true)).ConfigureAwait(false); var linksEnum = images?.Where(l => l != null).ToArray(); - if (images == null || !linksEnum.Any()) + if (images is null || !linksEnum.Any()) { await ReplyErrorLocalizedAsync("no_results").ConfigureAwait(false); return; @@ -439,7 +439,7 @@ namespace NadekoBot.Modules.NSFW imgObj = await _service.DapiSearch(tag, type, ctx.Guild?.Id, forceExplicit).ConfigureAwait(false); - if (imgObj == null) + if (imgObj is null) await ReplyErrorLocalizedAsync("no_results").ConfigureAwait(false); else { diff --git a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs index c312e79da..77f3e6d70 100644 --- a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs @@ -19,7 +19,7 @@ namespace NadekoBot.Modules.Permissions.Common var result = perm.CheckPermission(message, commandName, moduleName); - if (result == null) + if (result is null) { continue; } @@ -55,13 +55,13 @@ namespace NadekoBot.Modules.Permissions.Common return perm.State; break; case PrimaryPermissionType.Role: - if (guildUser == null) + if (guildUser is null) break; if (guildUser.RoleIds.Contains(perm.PrimaryTargetId)) return perm.State; break; case PrimaryPermissionType.Server: - if (guildUser == null) + if (guildUser is null) break; return perm.State; } diff --git a/src/NadekoBot/Modules/Permissions/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/FilterCommands.cs index eb5ad526f..29167431a 100644 --- a/src/NadekoBot/Modules/Permissions/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/FilterCommands.cs @@ -77,7 +77,7 @@ namespace NadekoBot.Modules.Permissions }; removed = config.FilterInvitesChannelIds.FirstOrDefault(fc => fc.Equals(match)); - if (removed == null) + if (removed is null) { config.FilterInvitesChannelIds.Add(match); } @@ -88,7 +88,7 @@ namespace NadekoBot.Modules.Permissions await uow.SaveChangesAsync(); } - if (removed == null) + if (removed is null) { _service.InviteFilteringChannels.Add(channel.Id); await ReplyConfirmLocalizedAsync("invite_filter_channel_on").ConfigureAwait(false); @@ -142,7 +142,7 @@ namespace NadekoBot.Modules.Permissions }; removed = config.FilterLinksChannelIds.FirstOrDefault(fc => fc.Equals(match)); - if (removed == null) + if (removed is null) { config.FilterLinksChannelIds.Add(match); } @@ -153,7 +153,7 @@ namespace NadekoBot.Modules.Permissions await uow.SaveChangesAsync(); } - if (removed == null) + if (removed is null) { _service.LinkFilteringChannels.Add(channel.Id); await ReplyConfirmLocalizedAsync("link_filter_channel_on").ConfigureAwait(false); @@ -207,7 +207,7 @@ namespace NadekoBot.Modules.Permissions ChannelId = channel.Id }; removed = config.FilterWordsChannelIds.FirstOrDefault(fc => fc.Equals(match)); - if (removed == null) + if (removed is null) { config.FilterWordsChannelIds.Add(match); } @@ -218,7 +218,7 @@ namespace NadekoBot.Modules.Permissions await uow.SaveChangesAsync(); } - if (removed == null) + if (removed is null) { _service.WordFilteringChannels.Add(channel.Id); await ReplyConfirmLocalizedAsync("word_filter_channel_on").ConfigureAwait(false); @@ -248,7 +248,7 @@ namespace NadekoBot.Modules.Permissions removed = config.FilteredWords.FirstOrDefault(fw => fw.Word.Trim().ToLowerInvariant() == word); - if (removed == null) + if (removed is null) config.FilteredWords.Add(new FilteredWord() { Word = word }); else { @@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Permissions var filteredWords = _service.ServerFilteredWords.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); - if (removed == null) + if (removed is null) { filteredWords.Add(word); await ReplyConfirmLocalizedAsync("filter_word_add", Format.Code(word)).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index 47dbc0d87..d7ae2b30c 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -33,7 +33,7 @@ namespace NadekoBot.Modules.Permissions using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); - if (action == null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle. + if (action is null) action = new PermissionAction(!config.VerbosePermissions); // New behaviour, can toggle. config.VerbosePermissions = action.Value; await uow.SaveChangesAsync(); _service.UpdateCache(config); @@ -57,11 +57,11 @@ namespace NadekoBot.Modules.Permissions if (role != null && role == role.Guild.EveryoneRole) return; - if (role == null) + if (role is null) { var cache = _service.GetCacheFor(ctx.Guild.Id); if (!ulong.TryParse(cache.PermRole, out var roleId) || - (role = ((SocketGuild)ctx.Guild).GetRole(roleId)) == null) + (role = ((SocketGuild)ctx.Guild).GetRole(roleId)) is null) { await ReplyConfirmLocalizedAsync("permrole_not_set", Format.Bold(cache.PermRole)).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs index 2996cb628..a58be94cb 100644 --- a/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/BlacklistService.cs @@ -89,7 +89,7 @@ namespace NadekoBot.Modules.Permissions.Services var toRemove = uow.Blacklist .FirstOrDefault(bi => bi.ItemId == id && bi.Type == type); - if (!(toRemove is null)) + if (toRemove is not null) uow.Blacklist.Remove(toRemove); uow.SaveChanges(); diff --git a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs index 33384b2c9..54542e967 100644 --- a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs @@ -114,7 +114,7 @@ namespace NadekoBot.Modules.Permissions.Services var guild = (channel as ITextChannel)?.Guild; var usrMsg = newMsg as IUserMessage; - if (guild == null || usrMsg == null) + if (guild is null || usrMsg is null) return Task.CompletedTask; return RunBehavior(null, guild, usrMsg); diff --git a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs index 1eb6f1685..a7ea34596 100644 --- a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs @@ -59,7 +59,7 @@ namespace NadekoBot.Modules.Permissions.Services UpdateCache(config); } Cache.TryGetValue(guildId, out pc); - if (pc == null) + if (pc is null) throw new Exception("Cache is null."); } return pc; @@ -108,7 +108,7 @@ namespace NadekoBot.Modules.Permissions.Services var commandName = command.Name.ToLowerInvariant(); await Task.Yield(); - if (guild == null) + if (guild is null) { return false; } @@ -149,7 +149,7 @@ namespace NadekoBot.Modules.Permissions.Services rid = 0; string returnMsg; IRole role; - if (string.IsNullOrWhiteSpace(permRole) || (role = guild.GetRole(rid)) == null) + if (string.IsNullOrWhiteSpace(permRole) || (role = guild.GetRole(rid)) is null) { returnMsg = $"You need Admin permissions in order to use permission commands."; if (pc.Verbose) diff --git a/src/NadekoBot/Modules/Searches/AnimeSearchCommands.cs b/src/NadekoBot/Modules/Searches/AnimeSearchCommands.cs index b82760726..ab0057359 100644 --- a/src/NadekoBot/Modules/Searches/AnimeSearchCommands.cs +++ b/src/NadekoBot/Modules/Searches/AnimeSearchCommands.cs @@ -24,7 +24,7 @@ namespace NadekoBot.Modules.Searches var novelData = await _service.GetNovelData(query).ConfigureAwait(false); - if (novelData == null) + if (novelData is null) { await ReplyErrorLocalizedAsync("failed_finding_novel").ConfigureAwait(false); return; @@ -63,7 +63,7 @@ namespace NadekoBot.Modules.Searches var favorites = document.QuerySelectorAll("div.user-favorites > div.di-tc"); var favAnime = GetText("anime_no_fav"); - if (favorites.Length > 0 && favorites[0].QuerySelector("p") == null) + if (favorites.Length > 0 && favorites[0].QuerySelector("p") is null) favAnime = string.Join("\n", favorites[0].QuerySelectorAll("ul > li > div.di-tc.va-t > a") .Shuffle() .Take(3) @@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Searches var animeData = await _service.GetAnimeData(query).ConfigureAwait(false); - if (animeData == null) + if (animeData is null) { await ReplyErrorLocalizedAsync("failed_finding_anime").ConfigureAwait(false); return; @@ -172,7 +172,7 @@ namespace NadekoBot.Modules.Searches var mangaData = await _service.GetMangaData(query).ConfigureAwait(false); - if (mangaData == null) + if (mangaData is null) { await ReplyErrorLocalizedAsync("failed_finding_manga").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Searches/CryptoCommands.cs b/src/NadekoBot/Modules/Searches/CryptoCommands.cs index fc412d595..a548e5e7f 100644 --- a/src/NadekoBot/Modules/Searches/CryptoCommands.cs +++ b/src/NadekoBot/Modules/Searches/CryptoCommands.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Searches } } - if (crypto == null) + if (crypto is null) { await ReplyErrorLocalizedAsync("crypto_not_found").ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 4d7adf6aa..69f817546 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -51,7 +51,7 @@ namespace NadekoBot.Modules.Searches public async Task Rip([Leftover] IGuildUser usr) { var av = usr.RealAvatarUrl(128); - if (av == null) + if (av is null) return; using (var picStream = await _service.GetRipPictureAsync(usr.Nickname ?? usr.Username, av).ConfigureAwait(false)) { @@ -73,7 +73,7 @@ namespace NadekoBot.Modules.Searches var embed = new EmbedBuilder(); var data = await _service.GetWeatherDataAsync(query).ConfigureAwait(false); - if (data == null) + if (data is null) { embed.WithDescription(GetText("city_not_found")) .WithErrorColor(); @@ -115,7 +115,7 @@ namespace NadekoBot.Modules.Searches await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); var (data, err) = await _service.GetTimeDataAsync(query).ConfigureAwait(false); - if (!(err is null)) + if (err is not null) { string errorKey; switch (err) @@ -177,7 +177,7 @@ namespace NadekoBot.Modules.Searches await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); var movie = await _service.GetMovieDataAsync(query).ConfigureAwait(false); - if (movie == null) + if (movie is null) { await ReplyErrorLocalizedAsync("imdb_fail").ConfigureAwait(false); return; @@ -247,7 +247,7 @@ namespace NadekoBot.Modules.Searches var img = (elems.ElementAtOrDefault(new NadekoRandom().Next(0, elems.Count))?.Children?.FirstOrDefault() as IHtmlImageElement); - if (img?.Source == null) + if (img?.Source is null) return; var source = img.Source.Replace("b.", ".", StringComparison.InvariantCulture); @@ -406,7 +406,7 @@ namespace NadekoBot.Modules.Searches await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); var card = await _service.GetMtgCardAsync(search).ConfigureAwait(false); - if (card == null) + if (card is null) { await ReplyErrorLocalizedAsync("card_not_found").ConfigureAwait(false); return; @@ -439,7 +439,7 @@ namespace NadekoBot.Modules.Searches await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); var card = await _service.GetHearthstoneCardDataAsync(name).ConfigureAwait(false); - if (card == null) + if (card is null) { await ReplyErrorLocalizedAsync("card_not_found").ConfigureAwait(false); return; @@ -560,7 +560,7 @@ namespace NadekoBot.Modules.Searches using (var http = _httpFactory.CreateClient()) { var response = await http.GetStringAsync("https://catfact.ninja/fact").ConfigureAwait(false); - if (response == null) + if (response is null) return; var fact = JObject.Parse(response)["fact"].ToString(); @@ -573,11 +573,11 @@ namespace NadekoBot.Modules.Searches [RequireContext(ContextType.Guild)] public async Task Revav([Leftover] IGuildUser usr = null) { - if (usr == null) + if (usr is null) usr = (IGuildUser)ctx.User; var av = usr.RealAvatarUrl(); - if (av == null) + if (av is null) return; await ctx.Channel.SendConfirmAsync($"https://images.google.com/searchbyimage?image_url={av}").ConfigureAwait(false); @@ -649,12 +649,12 @@ namespace NadekoBot.Modules.Searches [RequireContext(ContextType.Guild)] public async Task Avatar([Leftover] IGuildUser usr = null) { - if (usr == null) + if (usr is null) usr = (IGuildUser)ctx.User; var avatarUrl = usr.RealAvatarUrl(2048); - if (avatarUrl == null) + if (avatarUrl is null) { await ReplyErrorLocalizedAsync("avatar_none", usr.ToString()).ConfigureAwait(false); return; @@ -725,7 +725,7 @@ namespace NadekoBot.Modules.Searches catch { } - if (obj.Error != null || obj.Verses == null || obj.Verses.Length == 0) + if (obj.Error != null || obj.Verses is null || obj.Verses.Length == 0) await ctx.Channel.SendErrorAsync(obj.Error ?? "No verse found.").ConfigureAwait(false); else { @@ -773,7 +773,7 @@ namespace NadekoBot.Modules.Searches var imgObj = await _service.DapiSearch(tag, type, ctx.Guild?.Id).ConfigureAwait(false); - if (imgObj == null) + if (imgObj is null) await channel.SendErrorAsync(umsg.Author.Mention + " " + GetText("no_results")).ConfigureAwait(false); else await channel.EmbedAsync(new EmbedBuilder().WithOkColor() diff --git a/src/NadekoBot/Modules/Searches/Services/AnimeSearchService.cs b/src/NadekoBot/Modules/Searches/Services/AnimeSearchService.cs index 4c71e2924..f215e83ea 100644 --- a/src/NadekoBot/Modules/Searches/Services/AnimeSearchService.cs +++ b/src/NadekoBot/Modules/Searches/Services/AnimeSearchService.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Modules.Searches.Services using (var document = await BrowsingContext.New(config).OpenAsync(link).ConfigureAwait(false)) { var imageElem = document.QuerySelector("div.seriesimg > img"); - if (imageElem == null) + if (imageElem is null) return null; var imageUrl = ((IHtmlImageElement)imageElem).Source; diff --git a/src/NadekoBot/Modules/Searches/Services/CryptoService.cs b/src/NadekoBot/Modules/Searches/Services/CryptoService.cs index 66ff26b95..6452651df 100644 --- a/src/NadekoBot/Modules/Searches/Services/CryptoService.cs +++ b/src/NadekoBot/Modules/Searches/Services/CryptoService.cs @@ -40,7 +40,7 @@ namespace NadekoBot.Modules.Searches.Services || x.Symbol.ToUpperInvariant() == name); (CryptoResponseData Elem, int Distance)? nearest = null; - if (crypto == null) + if (crypto is null) { nearest = cryptos.Select(x => (x, Distance: x.Name.ToUpperInvariant().LevenshteinDistance(name))) .OrderBy(x => x.Distance) diff --git a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs index 8af6f0828..aff87297b 100644 --- a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs @@ -118,7 +118,7 @@ namespace NadekoBot.Modules.Searches.Services var previewElement = afi.Element.Elements() .FirstOrDefault(x => x.Name.LocalName == "preview"); - if (previewElement == null) + if (previewElement is null) { previewElement = afi.Element.Elements() .FirstOrDefault(x => x.Name.LocalName == "thumbnail"); diff --git a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs index 3fe6c1410..428c962a0 100644 --- a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs @@ -226,7 +226,7 @@ namespace NadekoBot.Modules.Searches.Services $"appid=42cd627dd60debf25a5739e50a217d74&" + $"units=metric").ConfigureAwait(false); - if (data == null) + if (data is null) return null; return JsonConvert.DeserializeObject(data); @@ -504,7 +504,7 @@ namespace NadekoBot.Modules.Searches.Services search, TimeSpan.FromDays(1)).ConfigureAwait(false); - if (data == null || data.Length == 0) + if (data is null || data.Length == 0) return null; return data[_rng.Next(0, data.Length)]; @@ -543,7 +543,7 @@ namespace NadekoBot.Modules.Searches.Services .ConfigureAwait(false); var responseObject = JsonConvert.DeserializeObject(response); - if (responseObject == null) + if (responseObject is null) return new MtgData[0]; var cards = responseObject.Cards.Take(5).ToArray(); @@ -582,12 +582,12 @@ namespace NadekoBot.Modules.Searches.Services var response = await http.GetStringAsync($"https://omgvamp-hearthstone-v1.p.rapidapi.com/" + $"cards/search/{Uri.EscapeUriString(name)}").ConfigureAwait(false); var objs = JsonConvert.DeserializeObject(response); - if (objs == null || objs.Length == 0) + if (objs is null || objs.Length == 0) return null; var data = objs.FirstOrDefault(x => x.Collectible) ?? objs.FirstOrDefault(x => !string.IsNullOrEmpty(x.PlayerClass)) ?? objs.FirstOrDefault(); - if (data == null) + if (data is null) return null; if (!string.IsNullOrWhiteSpace(data.Img)) { @@ -624,7 +624,7 @@ namespace NadekoBot.Modules.Searches.Services var res = await http.GetStringAsync(string.Format("https://omdbapi.nadeko.bot/?t={0}&y=&plot=full&r=json", name.Trim().Replace(' ', '+'))).ConfigureAwait(false); var movie = JsonConvert.DeserializeObject(res); - if (movie?.Title == null) + if (movie?.Title is null) return null; movie.Poster = await _google.ShortenUrl(movie.Poster).ConfigureAwait(false); return movie; @@ -671,7 +671,7 @@ namespace NadekoBot.Modules.Searches.Services } }, default(string), TimeSpan.FromHours(24)); - if (gamesMap == null) + if (gamesMap is null) return -1; @@ -780,7 +780,7 @@ namespace NadekoBot.Modules.Searches.Services var href = (children[0].QuerySelector("a") as IHtmlAnchorElement)?.Href; var name = children[0].QuerySelector("h3")?.TextContent; - if (href == null || name == null) + if (href is null || name is null) return null; var txt = children[1].TextContent; diff --git a/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs b/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs index 4440696ca..a6a42c45d 100644 --- a/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs +++ b/src/NadekoBot/Modules/Searches/Services/YtTrackService.cs @@ -94,7 +94,7 @@ namespace NadekoBot.Modules.Searches.Services // var oldObj = gc.YtFollowedChannels // .FirstOrDefault(x => x.ChannelId == channelId && x.YtChannelId == ytChannelId); // - // if(!(oldObj is null)) + // if(oldObj is not null) // { // return false; // } diff --git a/src/NadekoBot/Modules/Utility/InfoCommands.cs b/src/NadekoBot/Modules/Utility/InfoCommands.cs index fdc44f03a..f23ad59ae 100644 --- a/src/NadekoBot/Modules/Utility/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/InfoCommands.cs @@ -36,7 +36,7 @@ namespace NadekoBot.Modules.Utility guild = (SocketGuild)channel.Guild; else guild = _client.Guilds.FirstOrDefault(g => g.Name.ToUpperInvariant() == guildName.ToUpperInvariant()); - if (guild == null) + if (guild is null) return; var ownername = guild.GetUser(guild.OwnerId); var textchn = guild.TextChannels.Count(); @@ -79,7 +79,7 @@ namespace NadekoBot.Modules.Utility public async Task ChannelInfo(ITextChannel channel = null) { var ch = channel ?? (ITextChannel)ctx.Channel; - if (ch == null) + if (ch is null) return; var createdAt = new DateTime(2015, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(ch.Id >> 22); var usercount = (await ch.GetUsersAsync().FlattenAsync().ConfigureAwait(false)).Count(); @@ -99,7 +99,7 @@ namespace NadekoBot.Modules.Utility { var user = usr ?? ctx.User as IGuildUser; - if (user == null) + if (user is null) return; var embed = new EmbedBuilder() diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 91491025a..8c90f664a 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -75,7 +75,7 @@ namespace NadekoBot.Modules.Utility //} } - if (quote == null) + if (quote is null) return; var rep = new ReplacementBuilder() @@ -141,7 +141,7 @@ namespace NadekoBot.Modules.Utility keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); } - if (keywordquote == null) + if (keywordquote is null) return; await ctx.Channel.SendMessageAsync($"`#{keywordquote.Id}` 💬 " + keyword.ToLowerInvariant() + ": " + diff --git a/src/NadekoBot/Modules/Utility/RemindCommands.cs b/src/NadekoBot/Modules/Utility/RemindCommands.cs index 19ac8108f..fb9e8c8de 100644 --- a/src/NadekoBot/Modules/Utility/RemindCommands.cs +++ b/src/NadekoBot/Modules/Utility/RemindCommands.cs @@ -48,7 +48,7 @@ namespace NadekoBot.Modules.Utility ulong target; target = meorhere == MeOrHere.Me ? ctx.User.Id : ctx.Channel.Id; - if (!await RemindInternal(target, meorhere == MeOrHere.Me || ctx.Guild == null, remindData.Time, remindData.What) + if (!await RemindInternal(target, meorhere == MeOrHere.Me || ctx.Guild is null, remindData.Time, remindData.What) .ConfigureAwait(false)) { await ReplyErrorLocalizedAsync("remind_too_long").ConfigureAwait(false); @@ -144,7 +144,7 @@ namespace NadekoBot.Modules.Utility } } - if (rem == null) + if (rem is null) { await ReplyErrorLocalizedAsync("reminder_not_exist").ConfigureAwait(false); } @@ -186,7 +186,7 @@ namespace NadekoBot.Modules.Utility await uow.SaveChangesAsync(); } - var gTime = ctx.Guild == null + var gTime = ctx.Guild is null ? time : TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(ctx.Guild.Id)); try diff --git a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs index 7df7fb7e8..218a707a3 100644 --- a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs +++ b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Utility.Services { await Task.Yield(); - if (guild == null || string.IsNullOrWhiteSpace(input)) + if (guild is null || string.IsNullOrWhiteSpace(input)) return input; if (guild != null) diff --git a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs index 4453060e0..e8f6f0af8 100644 --- a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs @@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Utility.Services data = JsonConvert.DeserializeObject(res); var pledgers = data.Data.Where(x => x["type"].ToString() == "pledge"); rewards.AddRange(pledgers.Select(x => JsonConvert.DeserializeObject(x.ToString())) - .Where(x => x.attributes.declined_since == null)); + .Where(x => x.attributes.declined_since is null)); if (data.Included != null) { users.AddRange(data.Included @@ -141,7 +141,7 @@ namespace NadekoBot.Modules.Utility.Services var users = uow.Set(); var usr = users.FirstOrDefault(x => x.PatreonUserId == data.User.id); - if (usr == null) + if (usr is null) { users.Add(new RewardedUser() { diff --git a/src/NadekoBot/Modules/Utility/Services/RemindService.cs b/src/NadekoBot/Modules/Utility/Services/RemindService.cs index 31a912a35..f8aa4c50f 100644 --- a/src/NadekoBot/Modules/Utility/Services/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RemindService.cs @@ -156,7 +156,7 @@ namespace NadekoBot.Modules.Utility.Services if (r.IsPrivate) { var user = _client.GetUser(r.ChannelId); - if (user == null) + if (user is null) return; ch = await user.GetOrCreateDMChannelAsync().ConfigureAwait(false); } @@ -164,7 +164,7 @@ namespace NadekoBot.Modules.Utility.Services { ch = _client.GetGuild(r.ServerId)?.GetTextChannel(r.ChannelId); } - if (ch == null) + if (ch is null) return; await ch.EmbedAsync(new EmbedBuilder() diff --git a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs index 3cd802c38..ff17977b4 100644 --- a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs @@ -165,7 +165,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") return; } - while (!(current is null) && current.Value.NextTime < rep.NextTime) + while (current is not null && current.Value.NextTime < rep.NextTime) current = current.Next; if (current is null) diff --git a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs index 515dfaba0..4bf35d0b0 100644 --- a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs +++ b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs @@ -239,7 +239,7 @@ namespace NadekoBot.Modules.Utility.Services || a.Name.ToUpperInvariant().Contains(setting.Keyword.ToUpperInvariant()) || setting.Whitelist.Any(x => x.UserId == user.Id))); - if (!(g is null) + if (g is not null && setting.Enabled && setting.Blacklist.All(x => x.UserId != user.Id) && user.RoleIds.Contains(setting.FromRoleId)) @@ -247,7 +247,7 @@ namespace NadekoBot.Modules.Utility.Services try { addRole = addRole ?? user.Guild.GetRole(setting.AddRoleId); - if (addRole == null) + if (addRole is null) { await StopStreamRole(user.Guild).ConfigureAwait(false); Log.Warning("Stream role in server {0} no longer exists. Stopping.", setting.AddRoleId); @@ -278,7 +278,7 @@ namespace NadekoBot.Modules.Utility.Services try { addRole = addRole ?? user.Guild.GetRole(setting.AddRoleId); - if (addRole == null) + if (addRole is null) throw new StreamRoleNotFoundException(); await user.RemoveRoleAsync(addRole).ConfigureAwait(false); @@ -300,7 +300,7 @@ namespace NadekoBot.Modules.Utility.Services return; var addRole = guild.GetRole(setting.AddRoleId); - if (addRole == null) + if (addRole is null) return; if (setting.Enabled) diff --git a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs index 8d1e2bc54..5d7410d7a 100644 --- a/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/VerboseErrorsService.cs @@ -40,7 +40,7 @@ namespace NadekoBot.Modules.Utility.Services private async Task LogVerboseError(CommandInfo cmd, ITextChannel channel, string reason) { - if (channel == null || !guildsEnabled.Contains(channel.GuildId)) + if (channel is null || !guildsEnabled.Contains(channel.GuildId)) return; try diff --git a/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs b/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs index 3c7b0da94..f77bd86d2 100644 --- a/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs +++ b/src/NadekoBot/Modules/Utility/UnitConversionCommands.cs @@ -35,7 +35,7 @@ namespace NadekoBot.Modules.Utility { var originUnit = _service.Units.FirstOrDefault(x => x.Triggers.Select(y => y.ToUpperInvariant()).Contains(origin.ToUpperInvariant())); var targetUnit = _service.Units.FirstOrDefault(x => x.Triggers.Select(y => y.ToUpperInvariant()).Contains(target.ToUpperInvariant())); - if (originUnit == null || targetUnit == null) + if (originUnit is null || targetUnit is null) { await ReplyErrorLocalizedAsync("convert_not_found", Format.Bold(origin), Format.Bold(target)).ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index d40bfc1bc..877ba6d20 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -244,7 +244,7 @@ namespace NadekoBot.Modules.Utility [RequireContext(ContextType.Guild)] public async Task ChannelTopic([Leftover]ITextChannel channel = null) { - if (channel == null) + if (channel is null) channel = (ITextChannel)ctx.Channel; var topic = channel.Topic; diff --git a/src/NadekoBot/Modules/Xp/Club.cs b/src/NadekoBot/Modules/Xp/Club.cs index 29a222a28..84b643a93 100644 --- a/src/NadekoBot/Modules/Xp/Club.cs +++ b/src/NadekoBot/Modules/Xp/Club.cs @@ -80,7 +80,7 @@ namespace NadekoBot.Modules.Xp public async Task ClubIcon([Leftover] string url = null) { if ((!Uri.IsWellFormedUriString(url, UriKind.Absolute) && url != null) - || !await _service.SetClubIcon(ctx.User.Id, url == null ? null : new Uri(url))) + || !await _service.SetClubIcon(ctx.User.Id, url is null ? null : new Uri(url))) { await ReplyErrorLocalizedAsync("club_icon_error").ConfigureAwait(false); return; @@ -95,7 +95,7 @@ namespace NadekoBot.Modules.Xp { user = user ?? ctx.User; var club = _service.GetClubByMember(user); - if (club == null) + if (club is null) { await ErrorLocalizedAsync("club_user_not_in_club", Format.Bold(user.ToString())); return; @@ -171,7 +171,7 @@ namespace NadekoBot.Modules.Xp return Task.CompletedTask; var club = _service.GetClubWithBansAndApplications(ctx.User.Id); - if (club == null) + if (club is null) return ReplyErrorLocalizedAsync("club_not_exists_owner"); var bans = club @@ -202,7 +202,7 @@ namespace NadekoBot.Modules.Xp return Task.CompletedTask; var club = _service.GetClubWithBansAndApplications(ctx.User.Id); - if (club == null) + if (club is null) return ReplyErrorLocalizedAsync("club_not_exists_owner"); var apps = club diff --git a/src/NadekoBot/Modules/Xp/Services/ClubService.cs b/src/NadekoBot/Modules/Xp/Services/ClubService.cs index be68fb82f..f3e703a61 100644 --- a/src/NadekoBot/Modules/Xp/Services/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Services/ClubService.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Modules.Xp.Services uow.SaveChanges(); var xp = new LevelStats(du.TotalXp); - if (xp.Level >= 5 && du.Club == null) + if (xp.Level >= 5 && du.Club is null) { du.IsClubAdmin = true; du.Club = new ClubInfo() @@ -65,7 +65,7 @@ namespace NadekoBot.Modules.Xp.Services club = uow.Clubs.GetByOwner(from.Id); var newOwnerUser = uow.GetOrCreateUser(newOwner); - if (club == null || + if (club is null || club.Owner.UserId != from.Id || !club.Users.Contains(newOwnerUser)) return null; @@ -86,7 +86,7 @@ namespace NadekoBot.Modules.Xp.Services var club = uow.Clubs.GetByOwner(owner.Id); var adminUser = uow.GetOrCreateUser(toAdmin); - if (club == null || club.Owner.UserId != owner.Id || + if (club is null || club.Owner.UserId != owner.Id || !club.Users.Contains(adminUser)) throw new InvalidOperationException(); @@ -122,7 +122,7 @@ namespace NadekoBot.Modules.Xp.Services { var club = uow.Clubs.GetByOwner(ownerUserId); - if (club == null) + if (club is null) return false; club.ImageUrl = url.ToString(); @@ -148,7 +148,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow.Clubs.GetByName(name, discrim); - if (club == null) + if (club is null) return false; else return true; @@ -191,11 +191,11 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { var club = uow.Clubs.GetByOwnerOrAdmin(clubOwnerUserId); - if (club == null) + if (club is null) return false; var applicant = club.Applicants.FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant()); - if (applicant == null) + if (applicant is null) return false; applicant.User.Club = club; @@ -227,7 +227,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { var du = uow.GetOrCreateUser(user); - if (du.Club == null || du.Club.OwnerId == du.Id) + if (du.Club is null || du.Club.OwnerId == du.Id) return false; du.Club = null; @@ -245,7 +245,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { var club = uow.Clubs.GetByOwner(userId); - if (club == null) + if (club is null) return false; club.MinimumLevelReq = level; @@ -260,7 +260,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { var club = uow.Clubs.GetByOwner(userId); - if (club == null) + if (club is null) return false; club.Description = desc?.TrimTo(150, true); @@ -275,7 +275,7 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow.Clubs.GetByOwner(userId); - if (club == null) + if (club is null) return false; uow.Clubs.Remove(club); @@ -289,12 +289,12 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow.Clubs.GetByOwnerOrAdmin(bannerId); - if (club == null) + if (club is null) return false; var usr = club.Users.FirstOrDefault(x => x.ToString().ToUpperInvariant() == userName.ToUpperInvariant()) ?? club.Applicants.FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant())?.User; - if (usr == null) + if (usr is null) return false; if (club.OwnerId == usr.Id || (usr.IsClubAdmin && club.Owner.UserId != bannerId)) // can't ban the owner kek, whew @@ -322,11 +322,11 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow.Clubs.GetByOwnerOrAdmin(ownerUserId); - if (club == null) + if (club is null) return false; var ban = club.Bans.FirstOrDefault(x => x.User.ToString().ToUpperInvariant() == userName.ToUpperInvariant()); - if (ban == null) + if (ban is null) return false; club.Bans.Remove(ban); @@ -341,11 +341,11 @@ namespace NadekoBot.Modules.Xp.Services using (var uow = _db.GetDbContext()) { club = uow.Clubs.GetByOwnerOrAdmin(kickerId); - if (club == null) + if (club is null) return false; var usr = club.Users.FirstOrDefault(x => x.ToString().ToUpperInvariant() == userName.ToUpperInvariant()); - if (usr == null) + if (usr is null) return false; if (club.OwnerId == usr.Id || (usr.IsClubAdmin && club.Owner.UserId != kickerId)) diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index e1d507587..5256326ea 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -210,7 +210,7 @@ namespace NadekoBot.Modules.Xp.Services if (rrew != null) { var role = first.User.Guild.GetRole(rrew.RoleId); - if (!(role is null)) + if (role is not null) { if (rrew.Remove) { @@ -490,7 +490,7 @@ namespace NadekoBot.Modules.Xp.Services { ScanChannelForVoiceXp(after.VoiceChannel); } - else if (after.VoiceChannel == null) + else if (after.VoiceChannel is null) { // In this case, the user left the channel and the previous for loops didn't catch // it because it wasn't in any new channel. So we need to get rid of it. diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 65eb7a3a9..78aae3e5c 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -251,7 +251,7 @@ namespace NadekoBot.Modules.Xp [RequireContext(ContextType.Guild)] public async Task XpExclude(Channel _, [Leftover] IChannel channel = null) { - if (channel == null) + if (channel is null) channel = ctx.Channel; var ex = _service.ToggleExcludeChannel(ctx.Guild.Id, channel.Id); diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index 1eb88d1ab..5a53dfb29 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -104,7 +104,7 @@ namespace NadekoBot.Core.Services { if (string.IsNullOrWhiteSpace(prefix)) throw new ArgumentNullException(nameof(prefix)); - if (guild == null) + if (guild is null) throw new ArgumentNullException(nameof(guild)); using (var uow = _db.GetDbContext()) @@ -181,8 +181,8 @@ namespace NadekoBot.Core.Services "Channel: {2}\n\t" + "Message: {3}", usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} - (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} - (channel == 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} ); } @@ -209,8 +209,8 @@ namespace NadekoBot.Core.Services "Message: {3}\n\t" + "Error: {4}", usrMsg.Author + " [" + usrMsg.Author.Id + "]", // {0} - (channel == null ? "PRIVATE" : channel.Guild.Name + " [" + channel.Guild.Id + "]"), // {1} - (channel == 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} errorMessage //exec.Result.ErrorReason // {4} diff --git a/src/NadekoBot/Services/Common/ImageLoader.cs b/src/NadekoBot/Services/Common/ImageLoader.cs index 96a85713f..8b64ccbe8 100644 --- a/src/NadekoBot/Services/Common/ImageLoader.cs +++ b/src/NadekoBot/Services/Common/ImageLoader.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Core.Services.Common byte[][] vals = Array.Empty(); vals = await Task.WhenAll(tasks).ConfigureAwait(false); - if (vals.Any(x => x == null)) + if (vals.Any(x => x is null)) vals = vals.Where(x => x != null).ToArray(); await _db.KeyDeleteAsync(GetKey(key)).ConfigureAwait(false); diff --git a/src/NadekoBot/Services/GreetSettingsService.cs b/src/NadekoBot/Services/GreetSettingsService.cs index 17a5fe842..2833d2adc 100644 --- a/src/NadekoBot/Services/GreetSettingsService.cs +++ b/src/NadekoBot/Services/GreetSettingsService.cs @@ -70,7 +70,7 @@ namespace NadekoBot.Core.Services if (!conf.SendChannelByeMessage) return; var channel = (await user.Guild.GetTextChannelsAsync().ConfigureAwait(false)).SingleOrDefault(c => c.Id == conf.ByeMessageChannelId); - if (channel == null) //maybe warn the server owner that the channel is missing + if (channel is null) //maybe warn the server owner that the channel is missing return; if (GroupGreets) diff --git a/src/NadekoBot/Services/Impl/Localization.cs b/src/NadekoBot/Services/Impl/Localization.cs index bf7cd23e8..230dc01c5 100644 --- a/src/NadekoBot/Services/Impl/Localization.cs +++ b/src/NadekoBot/Services/Impl/Localization.cs @@ -35,7 +35,7 @@ namespace NadekoBot.Core.Services.Impl CultureInfo cultureInfo = null; try { - if (x.Value == null) + if (x.Value is null) return null; cultureInfo = new CultureInfo(x.Value); } @@ -108,7 +108,7 @@ namespace NadekoBot.Core.Services.Impl { _commandData.TryGetValue(key, out var toReturn); - if (toReturn == null) + if (toReturn is null) return new CommandData { Cmd = key, diff --git a/src/NadekoBot/Services/Impl/RedisCache.cs b/src/NadekoBot/Services/Impl/RedisCache.cs index b83c2d590..b7ba650ac 100644 --- a/src/NadekoBot/Services/Impl/RedisCache.cs +++ b/src/NadekoBot/Services/Impl/RedisCache.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Core.Services.Impl { var time = TimeSpan.FromHours(period); var _db = Redis.GetDatabase(); - if ((bool?)_db.StringGet($"{_redisKey}_timelyclaim_{id}") == null) + if ((bool?)_db.StringGet($"{_redisKey}_timelyclaim_{id}") is null) { _db.StringSet($"{_redisKey}_timelyclaim_{id}", true, time); return null; @@ -104,7 +104,7 @@ namespace NadekoBot.Core.Services.Impl { var _db = Redis.GetDatabase(); time = _db.KeyTimeToLive($"{_redisKey}_affinity_{userId}"); - if (time == null) + if (time is null) { time = TimeSpan.FromMinutes(30); _db.StringSet($"{_redisKey}_affinity_{userId}", true, time); @@ -117,7 +117,7 @@ namespace NadekoBot.Core.Services.Impl { var _db = Redis.GetDatabase(); time = _db.KeyTimeToLive($"{_redisKey}_divorce_{userId}"); - if (time == null) + if (time is null) { time = TimeSpan.FromHours(6); _db.StringSet($"{_redisKey}_divorce_{userId}", true, time); @@ -182,7 +182,7 @@ namespace NadekoBot.Core.Services.Impl { var obj = await factory(param).ConfigureAwait(false); - if (obj == null) + if (obj is null) return default(TOut); await _db.StringSetAsync(key, JsonConvert.SerializeObject(obj), diff --git a/src/NadekoBot/Services/ShardsCoordinator.cs b/src/NadekoBot/Services/ShardsCoordinator.cs index 11a8468fb..e288cf66c 100644 --- a/src/NadekoBot/Services/ShardsCoordinator.cs +++ b/src/NadekoBot/Services/ShardsCoordinator.cs @@ -190,7 +190,7 @@ namespace NadekoBot.Core.Services JsonConvert.SerializeObject(msg), CommandFlags.FireAndForget); var p = _shardProcesses[shardId]; - if (p == null) + if (p is null) return; // ignore _shardProcesses[shardId] = null; try @@ -204,7 +204,7 @@ namespace NadekoBot.Core.Services private void OnDataReceived(RedisChannel ch, RedisValue data) { var msg = JsonConvert.DeserializeObject(data); - if (msg == null) + if (msg is null) return; var db = _redis.GetDatabase(); //sets the shard state @@ -316,7 +316,7 @@ namespace NadekoBot.Core.Services for (var i = 0; i < _shardProcesses.Length; i++) { var p = _shardProcesses[i]; - if (p == null || p.HasExited) + if (p is null || p.HasExited) { Log.Warning("Scheduling shard {0} for restart because it's process is stopped.", i); _shardStartQueue.Enqueue(i); @@ -370,7 +370,7 @@ namespace NadekoBot.Core.Services Log.Error(ex, "Unhandled exception in RunAsync"); foreach (var p in _shardProcesses) { - if (p == null) + if (p is null) continue; try { diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index a838b92f7..aed7f838c 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -152,7 +152,7 @@ namespace NadekoBot.Extensions public static void ThrowIfNull(this T o, string name) where T : class { - if (o == null) + if (o is null) throw new ArgumentNullException(nameof(name)); } @@ -194,7 +194,7 @@ namespace NadekoBot.Extensions public static ReactionEventWrapper OnReaction(this IUserMessage msg, DiscordSocketClient client, Func reactionAdded, Func reactionRemoved = null) { - if (reactionRemoved == null) + if (reactionRemoved is null) reactionRemoved = _ => Task.CompletedTask; var wrap = new ReactionEventWrapper(client, msg); @@ -348,7 +348,7 @@ namespace NadekoBot.Extensions public static long? GetImageSize(this HttpResponseMessage msg) { - if (msg.Content.Headers.ContentLength == null) + if (msg.Content.Headers.ContentLength is null) { return null; } @@ -381,7 +381,7 @@ namespace NadekoBot.Extensions .Where(x => x.GetInterfaces().Contains(typeof(INService)) && !x.GetTypeInfo().IsInterface && !x.GetTypeInfo().IsAbstract #if GLOBAL_NADEKO - && x.GetTypeInfo().GetCustomAttribute() == null + && x.GetTypeInfo().GetCustomAttribute() is null #endif ) .ToArray()); diff --git a/src/NadekoBot/_Extensions/IEnumerableExtensions.cs b/src/NadekoBot/_Extensions/IEnumerableExtensions.cs index 5a9d5f14f..fde64507e 100644 --- a/src/NadekoBot/_Extensions/IEnumerableExtensions.cs +++ b/src/NadekoBot/_Extensions/IEnumerableExtensions.cs @@ -108,7 +108,7 @@ namespace NadekoBot.Extensions /// public static IEnumerable Chunk(this IEnumerable source, int size) { - if (source == null) + if (source is null) { throw new ArgumentNullException(nameof(source)); } diff --git a/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs b/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs index b14a99161..85766757f 100644 --- a/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs +++ b/src/NadekoBot/_Extensions/IMessageChannelExtensions.cs @@ -76,7 +76,7 @@ namespace NadekoBot.Extensions var canPaginate = true; var sg = ctx.Guild as SocketGuild; - if (!(sg is null) && !sg.CurrentUser.GetPermissions((IGuildChannel) ctx.Channel).AddReactions) + if (sg is not null && !sg.CurrentUser.GetPermissions((IGuildChannel) ctx.Channel).AddReactions) canPaginate = false; if (!canPaginate) diff --git a/src/NadekoBot/_Extensions/IUserExtensions.cs b/src/NadekoBot/_Extensions/IUserExtensions.cs index 9e9de9fe1..4d2991c38 100644 --- a/src/NadekoBot/_Extensions/IUserExtensions.cs +++ b/src/NadekoBot/_Extensions/IUserExtensions.cs @@ -46,7 +46,7 @@ namespace NadekoBot.Extensions // This method is used by everything that fetches the avatar from a user public static Uri RealAvatarUrl(this IUser usr, ushort size = 128) { - return usr.AvatarId == null + return usr.AvatarId is null ? new Uri(usr.GetDefaultAvatarUrl()) : new Uri(usr.GetAvatarUrl(ImageFormat.Auto, size)); } @@ -54,7 +54,7 @@ namespace NadekoBot.Extensions // This method is only used for the xp card public static Uri RealAvatarUrl(this DiscordUser usr) { - return usr.AvatarId == null + return usr.AvatarId is null ? null : new Uri(usr.AvatarId.StartsWith("a_", StringComparison.InvariantCulture) ? $"{DiscordConfig.CDNUrl}avatars/{usr.UserId}/{usr.AvatarId}.gif" diff --git a/src/NadekoBot/_Extensions/LinkedListExtensions.cs b/src/NadekoBot/_Extensions/LinkedListExtensions.cs index 41adabfe8..7ffd8b5de 100644 --- a/src/NadekoBot/_Extensions/LinkedListExtensions.cs +++ b/src/NadekoBot/_Extensions/LinkedListExtensions.cs @@ -9,7 +9,7 @@ namespace NadekoBot.Extensions public static LinkedListNode? FindNode(this LinkedList list, Func predicate) { var node = list.First; - while (!(node is null)) + while (node is not null) { if (predicate(node.Value)) return node; diff --git a/src/NadekoBot/_Extensions/ProcessExtensions.cs b/src/NadekoBot/_Extensions/ProcessExtensions.cs index 54958cf81..cb34193d3 100644 --- a/src/NadekoBot/_Extensions/ProcessExtensions.cs +++ b/src/NadekoBot/_Extensions/ProcessExtensions.cs @@ -57,7 +57,7 @@ namespace NadekoBot.Extensions while (true) { var text = reader.ReadLine(); - if (text == null) + if (text is null) { return; } diff --git a/src/NadekoBot/_Extensions/StringExtensions.cs b/src/NadekoBot/_Extensions/StringExtensions.cs index 819d3f04f..f221ac1a4 100644 --- a/src/NadekoBot/_Extensions/StringExtensions.cs +++ b/src/NadekoBot/_Extensions/StringExtensions.cs @@ -69,9 +69,9 @@ namespace NadekoBot.Extensions /// String with the correct singular/plural form public static string SnPl(this string str, int? num, bool es = false) { - if (str == null) + if (str is null) throw new ArgumentNullException(nameof(str)); - if (num == null) + if (num is null) throw new ArgumentNullException(nameof(num)); return num == 1 ? str.Remove(str.Length - 1, es ? 2 : 1) : str; } diff --git a/src/ayu/Ayu.Discord.Voice/Ayu.Discord.Voice.csproj b/src/ayu/Ayu.Discord.Voice/Ayu.Discord.Voice.csproj index c09d8a89b..8d3dc5153 100644 --- a/src/ayu/Ayu.Discord.Voice/Ayu.Discord.Voice.csproj +++ b/src/ayu/Ayu.Discord.Voice/Ayu.Discord.Voice.csproj @@ -1,6 +1,7 @@  netstandard2.1 + 9.0 true CS8632 1.0.2 diff --git a/src/ayu/Ayu.Discord.Voice/SocketClient.cs b/src/ayu/Ayu.Discord.Voice/SocketClient.cs index 0d35c629c..b3bd04752 100644 --- a/src/ayu/Ayu.Discord.Voice/SocketClient.cs +++ b/src/ayu/Ayu.Discord.Voice/SocketClient.cs @@ -44,7 +44,7 @@ namespace Ayu.Discord.Gateway var data = bufferWriter.WrittenMemory.ToArray(); bufferWriter.Clear(); - if (!(pr is null)) + if (pr is not null) { await pr.Invoke(data); }