diff --git a/src/NadekoBot/Common/Collections/IndexedCollection.cs b/src/NadekoBot/Common/Collections/IndexedCollection.cs index 3e2365af2..7a8775ee8 100644 --- a/src/NadekoBot/Common/Collections/IndexedCollection.cs +++ b/src/NadekoBot/Common/Collections/IndexedCollection.cs @@ -89,7 +89,7 @@ public class IndexedCollection : IList where T : class, IIndexed { if (removed = Source.Remove(item)) { - for (int i = 0; i < Source.Count; i++) + for (var i = 0; i < Source.Count; i++) { if (Source[i].Index != i) Source[i].Index = i; @@ -104,7 +104,7 @@ public class IndexedCollection : IList where T : class, IIndexed lock (_locker) { Source.Insert(index, item); - for (int i = index; i < Source.Count; i++) + for (var i = index; i < Source.Count; i++) { Source[i].Index = i; } @@ -116,7 +116,7 @@ public class IndexedCollection : IList where T : class, IIndexed lock (_locker) { Source.RemoveAt(index); - for (int i = index; i < Source.Count; i++) + for (var i = index; i < Source.Count; i++) { Source[i].Index = i; } diff --git a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs index a58c90ba8..93100b7d1 100644 --- a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs +++ b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs @@ -69,7 +69,7 @@ public class ReplacementBuilder _reps.TryAdd("%members%", () => g != null && g is SocketGuild sg ? sg.MemberCount.ToString() : "?"); _reps.TryAdd("%server_time%", () => { - TimeZoneInfo to = TimeZoneInfo.Local; + var to = TimeZoneInfo.Local; if (g != null) { if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz)) @@ -88,7 +88,7 @@ public class ReplacementBuilder _reps.TryAdd("%server.boost_level%", () => ((int)g.PremiumTier).ToString()); _reps.TryAdd("%server.time%", () => { - TimeZoneInfo to = TimeZoneInfo.Local; + var to = TimeZoneInfo.Local; if (g != null) { if (GuildTimezoneService.AllServices.TryGetValue(client.CurrentUser.Id, out var tz)) diff --git a/src/NadekoBot/Common/TypeReaders/Models/StoopidTime.cs b/src/NadekoBot/Common/TypeReaders/Models/StoopidTime.cs index 3767fccc9..aef7aa3aa 100644 --- a/src/NadekoBot/Common/TypeReaders/Models/StoopidTime.cs +++ b/src/NadekoBot/Common/TypeReaders/Models/StoopidTime.cs @@ -22,7 +22,7 @@ public class StoopidTime throw new ArgumentException("Invalid string input format."); } - string output = ""; + var output = string.Empty; var namesAndValues = new Dictionary(); foreach (var groupName in _regex.GetGroupNames()) diff --git a/src/NadekoBot/Common/Yml/MultilineScalarFlowStyleEmitter.cs b/src/NadekoBot/Common/Yml/MultilineScalarFlowStyleEmitter.cs index 058c8a06f..fe3360ecf 100644 --- a/src/NadekoBot/Common/Yml/MultilineScalarFlowStyleEmitter.cs +++ b/src/NadekoBot/Common/Yml/MultilineScalarFlowStyleEmitter.cs @@ -14,10 +14,10 @@ public class MultilineScalarFlowStyleEmitter : ChainedEventEmitter if (typeof(string).IsAssignableFrom(eventInfo.Source.Type)) { - string value = eventInfo.Source.Value as string; + var value = eventInfo.Source.Value as string; if (!string.IsNullOrEmpty(value)) { - bool isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0; + var isMultiLine = value.IndexOfAny(new char[] { '\r', '\n', '\x85', '\x2028', '\x2029' }) >= 0; if (isMultiLine) eventInfo = new ScalarEventInfo(eventInfo.Source) { diff --git a/src/NadekoBot/Db/Models/ClubInfo.cs b/src/NadekoBot/Db/Models/ClubInfo.cs index 8a3b2a220..d32231447 100644 --- a/src/NadekoBot/Db/Models/ClubInfo.cs +++ b/src/NadekoBot/Db/Models/ClubInfo.cs @@ -9,7 +9,7 @@ public class ClubInfo : DbEntity public string Name { get; set; } public int Discrim { get; set; } - public string ImageUrl { get; set; } = ""; + public string ImageUrl { get; set; } = string.Empty; public int MinimumLevelReq { get; set; } = 5; public int Xp { get; set; } = 0; diff --git a/src/NadekoBot/Db/Models/Waifu.cs b/src/NadekoBot/Db/Models/Waifu.cs index 59c730bb4..95634ef4c 100644 --- a/src/NadekoBot/Db/Models/Waifu.cs +++ b/src/NadekoBot/Db/Models/Waifu.cs @@ -20,7 +20,7 @@ public class WaifuInfo : DbEntity public override string ToString() { var claimer = "no one"; - var status = ""; + var status = string.Empty; var waifuUsername = Waifu.Username.TrimTo(20); var claimerUsername = Claimer?.Username.TrimTo(20); @@ -61,7 +61,7 @@ public class WaifuLbResult public override string ToString() { var claimer = "no one"; - var status = ""; + var status = string.Empty; var waifuUsername = Username.TrimTo(20); var claimerUsername = Claimer?.TrimTo(20); diff --git a/src/NadekoBot/Db/NadekoContext.cs b/src/NadekoBot/Db/NadekoContext.cs index 113202322..bf486c04a 100644 --- a/src/NadekoBot/Db/NadekoContext.cs +++ b/src/NadekoBot/Db/NadekoContext.cs @@ -14,7 +14,7 @@ public class NadekoContextFactory : IDesignTimeDbContextFactory { LogSetup.SetupLogger(-2); var optionsBuilder = new DbContextOptionsBuilder(); - IBotCredentials creds = new BotCredsProvider().GetCreds(); + var creds = new BotCredsProvider().GetCreds(); var builder = new SqliteConnectionStringBuilder(creds.Db.ConnectionString); builder.DataSource = Path.Combine(AppContext.BaseDirectory, builder.DataSource); optionsBuilder.UseSqlite(builder.ToString()); diff --git a/src/NadekoBot/Modules/Administration/ProtectionCommands.cs b/src/NadekoBot/Modules/Administration/ProtectionCommands.cs index c4bfe2bea..6737bb1e9 100644 --- a/src/NadekoBot/Modules/Administration/ProtectionCommands.cs +++ b/src/NadekoBot/Modules/Administration/ProtectionCommands.cs @@ -261,7 +261,7 @@ public partial class Administration if (string.IsNullOrWhiteSpace(ignoredString)) ignoredString = "none"; - string add = ""; + var add = string.Empty; if (settings.MuteTime > 0) { add = $" ({TimeSpan.FromMinutes(settings.MuteTime):hh\\hmm\\m})"; diff --git a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs index 28d18de67..2d9b052e4 100644 --- a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs @@ -92,7 +92,7 @@ public partial class Administration if (ctx.User.Id != guser.Guild.OwnerId && guser.GetRoles().Max(x => x.Position) <= role.Position) return; - bool success = _service.RemoveSar(role.Guild.Id, role.Id); + var success = _service.RemoveSar(role.Guild.Id, role.Id); if (!success) { await ReplyErrorLocalizedAsync(strs.self_assign_not).ConfigureAwait(false); @@ -124,7 +124,7 @@ public partial class Administration foreach (var kvp in roleGroups) { - var groupNameText = ""; + var groupNameText = string.Empty; if (!groups.TryGetValue(kvp.Key, out var name)) { groupNameText = Format.Bold(GetText(strs.self_assign_group(kvp.Key))); @@ -168,7 +168,7 @@ public partial class Administration [BotPerm(GuildPerm.ManageRoles)] public async Task Togglexclsar() { - bool areExclusive = _service.ToggleEsar(ctx.Guild.Id); + var areExclusive = _service.ToggleEsar(ctx.Guild.Id); if (areExclusive) await ReplyConfirmLocalizedAsync(strs.self_assign_excl).ConfigureAwait(false); else @@ -184,7 +184,7 @@ public partial class Administration if (level < 0) return; - bool succ = _service.SetLevelReq(ctx.Guild.Id, role, level); + var succ = _service.SetLevelReq(ctx.Guild.Id, role, level); if (!succ) { diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index 0ad7b3121..a8b9ed23c 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -332,7 +332,7 @@ public partial class Administration [OwnerOnly] public async Task Restart() { - bool success = _coord.RestartBot(); + var success = _coord.RestartBot(); if (!success) { await ReplyErrorLocalizedAsync(strs.restart_fail).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs index faeab172f..64480cada 100644 --- a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs @@ -73,7 +73,7 @@ DELETE FROM Clubs;"; { if (reader.HasRows) { - for (int i = 0; i < reader.FieldCount; i++) + for (var i = 0; i < reader.FieldCount; i++) { result.ColumnNames.Add(reader.GetName(i)); } diff --git a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs index 2f1d8dab2..a1ebfb347 100644 --- a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs @@ -153,7 +153,7 @@ public sealed class LogCommandService : ILogCommandService public LogSetting GetGuildLogSettings(ulong guildId) { - GuildLogSettings.TryGetValue(guildId, out LogSetting logSetting); + GuildLogSettings.TryGetValue(guildId, out var logSetting); return logSetting; } @@ -164,7 +164,7 @@ public sealed class LogCommandService : ILogCommandService public bool LogIgnore(ulong gid, ulong itemId, IgnoredItemType itemType) { - int removed = 0; + var removed = 0; using (var uow = _db.GetDbContext()) { var logSetting = uow.LogSettingsFor(gid); @@ -197,7 +197,7 @@ public sealed class LogCommandService : ILogCommandService private string CurrentTime(IGuild g) { - DateTime time = DateTime.UtcNow; + var time = DateTime.UtcNow; if (g != null) time = TimeZoneInfo.ConvertTime(time, _tz.GetTimeZoneOrUtc(g.Id)); @@ -243,7 +243,7 @@ public sealed class LogCommandService : ILogCommandService var g = after.Guild; - if (!GuildLogSettings.TryGetValue(g.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(g.Id, out var logSetting) || (logSetting.UserUpdatedId is null)) return; @@ -375,7 +375,7 @@ public sealed class LogCommandService : ILogCommandService if (beforeVch == afterVch) return; - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.LogVoicePresenceTTSId is null)) return; @@ -384,7 +384,7 @@ public sealed class LogCommandService : ILogCommandService .ConfigureAwait(false)) is null) return; - var str = ""; + var str = string.Empty; if (beforeVch?.Guild == afterVch?.Guild) { str = GetText(logChannel.Guild, strs.log_vc_moved(usr.Username, beforeVch?.Name, afterVch?.Name)); @@ -415,7 +415,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.UserMutedId is null)) return; @@ -423,7 +423,7 @@ public sealed class LogCommandService : ILogCommandService if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserMuted) .ConfigureAwait(false)) is null) return; - var mutes = ""; + var mutes = string.Empty; var mutedLocalized = GetText(logChannel.Guild, strs.muted_sn); switch (muteType) { @@ -459,7 +459,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.UserMutedId is null)) return; @@ -468,7 +468,7 @@ public sealed class LogCommandService : ILogCommandService .ConfigureAwait(false)) is null) return; - var mutes = ""; + var mutes = string.Empty; var unmutedLocalized = GetText(logChannel.Guild, strs.unmuted_sn); switch (muteType) { @@ -511,7 +511,7 @@ public sealed class LogCommandService : ILogCommandService if (users.Length == 0) return; - if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(users.First().Guild.Id, out var logSetting) || (logSetting.LogOtherId is null)) return; ITextChannel logChannel; @@ -519,7 +519,7 @@ public sealed class LogCommandService : ILogCommandService .ConfigureAwait(false)) is null) return; - var punishment = ""; + var punishment = string.Empty; switch (action) { case PunishmentAction.Mute: @@ -579,7 +579,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -680,7 +680,7 @@ public sealed class LogCommandService : ILogCommandService var after = (IGuildChannel) cafter; - if (!GuildLogSettings.TryGetValue(before.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting) || (logSetting.ChannelUpdatedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -731,7 +731,7 @@ public sealed class LogCommandService : ILogCommandService if (!(ich is IGuildChannel ch)) return; - if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) || (logSetting.ChannelDestroyedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == ch.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -771,7 +771,7 @@ public sealed class LogCommandService : ILogCommandService if (!(ich is IGuildChannel ch)) return; - if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(ch.Guild.Id, out var logSetting) || logSetting.ChannelCreatedId is null) return; @@ -816,7 +816,7 @@ public sealed class LogCommandService : ILogCommandService if (beforeVch == afterVch) return; - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.LogVoicePresenceId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == iusr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -869,7 +869,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.UserLeftId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -904,7 +904,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting) || (logSetting.UserJoinedId is null)) return; @@ -945,7 +945,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting) || (logSetting.UserUnbannedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -980,7 +980,7 @@ public sealed class LogCommandService : ILogCommandService { try { - if (!GuildLogSettings.TryGetValue(guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting) || (logSetting.UserBannedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User)) return; @@ -1028,7 +1028,7 @@ public sealed class LogCommandService : ILogCommandService if (!(ch is ITextChannel channel)) return; - if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting) || (logSetting.MessageDeletedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel)) return; @@ -1086,7 +1086,7 @@ public sealed class LogCommandService : ILogCommandService if (before.Author.IsBot) return; - if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out LogSetting logSetting) + if (!GuildLogSettings.TryGetValue(channel.Guild.Id, out var logSetting) || (logSetting.MessageUpdatedId is null) || logSetting.LogIgnores.Any(ilc => ilc.LogItemId == channel.Id && ilc.ItemType == IgnoredItemType.Channel)) return; diff --git a/src/NadekoBot/Modules/Administration/Services/MuteService.cs b/src/NadekoBot/Modules/Administration/Services/MuteService.cs index 66254b7a4..fb5da98b7 100644 --- a/src/NadekoBot/Modules/Administration/Services/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Services/MuteService.cs @@ -156,7 +156,7 @@ public class MuteService : INService { try { - MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet muted); + MutedUsers.TryGetValue(usr.Guild.Id, out var muted); if (muted is null || !muted.Contains(usr.Id)) return Task.CompletedTask; @@ -198,7 +198,7 @@ public class MuteService : INService { UserId = usr.Id }); - if (MutedUsers.TryGetValue(usr.Guild.Id, out ConcurrentHashSet muted)) + if (MutedUsers.TryGetValue(usr.Guild.Id, out var muted)) muted.Add(usr.Id); config.UnmuteTimers.RemoveWhere(x => x.UserId == usr.Id); @@ -242,7 +242,7 @@ public class MuteService : INService { uow.Remove(toRemove); } - if (MutedUsers.TryGetValue(guildId, out ConcurrentHashSet muted)) + if (MutedUsers.TryGetValue(guildId, out var muted)) muted.TryRemove(usrId); config.UnmuteTimers.RemoveWhere(x => x.UserId == usrId); @@ -442,10 +442,10 @@ public class MuteService : INService public void StopTimer(ulong guildId, ulong userId, TimerType type) { - if (!Un_Timers.TryGetValue(guildId, out ConcurrentDictionary<(ulong, TimerType), Timer> userTimer)) + if (!Un_Timers.TryGetValue(guildId, out var userTimer)) return; - if (userTimer.TryRemove((userId, type), out Timer removed)) + if (userTimer.TryRemove((userId, type), out var removed)) { removed.Change(Timeout.Infinite, Timeout.Infinite); } diff --git a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs index ffeae378f..22a1b02a0 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs @@ -131,7 +131,7 @@ public class SelfAssignedRolesService : INService public async Task SetNameAsync(ulong guildId, int group, string name) { - bool set = false; + var set = false; using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames)); diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index cbf464d61..ec9286f3f 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -58,7 +58,7 @@ public class UserPunishService : INService Weight = weight, }; - int warnings = 1; + var warnings = 1; List ps; using (var uow = _db.GetDbContext()) { @@ -299,7 +299,7 @@ WHERE GuildId={guildId} public async Task WarnClearAsync(ulong guildId, ulong userId, int index, string moderator) { - bool toReturn = true; + var toReturn = true; using (var uow = _db.GetDbContext()) { if (index == 0) diff --git a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs index eba52993a..bce4ae82b 100644 --- a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs @@ -194,10 +194,10 @@ public class VcRoleService : INService ulong guildId; guildId = newVc?.Guild.Id ?? oldVc.Guild.Id; - if (VcRoles.TryGetValue(guildId, out ConcurrentDictionary guildVcRoles)) + if (VcRoles.TryGetValue(guildId, out var guildVcRoles)) { //remove old - if (oldVc != null && guildVcRoles.TryGetValue(oldVc.Id, out IRole role)) + if (oldVc != null && guildVcRoles.TryGetValue(oldVc.Id, out var role)) { Assign(false, gusr, role); } diff --git a/src/NadekoBot/Modules/Administration/VcRoleCommands.cs b/src/NadekoBot/Modules/Administration/VcRoleCommands.cs index 6e7d4ad67..f4fb76296 100644 --- a/src/NadekoBot/Modules/Administration/VcRoleCommands.cs +++ b/src/NadekoBot/Modules/Administration/VcRoleCommands.cs @@ -66,7 +66,7 @@ public partial class Administration { var guild = (SocketGuild)ctx.Guild; string text; - if (_service.VcRoles.TryGetValue(ctx.Guild.Id, out ConcurrentDictionary roles)) + if (_service.VcRoles.TryGetValue(ctx.Guild.Id, out var roles)) { if (!roles.Any()) { diff --git a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs index aaddc4a6e..e3cd6d0f9 100644 --- a/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs +++ b/src/NadekoBot/Modules/CustomReactions/CustomReactions.cs @@ -199,7 +199,7 @@ public class CustomReactions : NadekoModule return; } - List succ = new List(); + var succ = new List(); foreach (var emojiStr in emojiStrs) { diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index f460f0ec3..4a34a760c 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -403,7 +403,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor { var pc = _perms.GetCacheFor(guild.Id); if (!pc.Permissions.CheckPermissions(msg, cr.Trigger, "ActualCustomReactions", - out int index)) + out var index)) { if (pc.Verbose) { diff --git a/src/NadekoBot/Modules/Gambling/Common/Deck.cs b/src/NadekoBot/Modules/Gambling/Common/Deck.cs index 4d5732cbe..b7fe56790 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Deck.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Deck.cs @@ -58,7 +58,7 @@ public class Deck { get { - var str = ""; + var str = string.Empty; if (Number <= 10 && Number > 1) { @@ -106,7 +106,7 @@ public class Deck public string GetEmojiString() { - var str = ""; + var str = string.Empty; str += _regIndicators[this.Number - 1]; str += _suitToSuitChar[this.Suit]; diff --git a/src/NadekoBot/Modules/Gambling/Common/Events/GameStatusEvent.cs b/src/NadekoBot/Modules/Gambling/Common/Events/GameStatusEvent.cs index 35046b462..93aaad2dc 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Events/GameStatusEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Events/GameStatusEvent.cs @@ -71,7 +71,7 @@ public class GameStatusEvent : ICurrencyEvent private async void OnTimerTick(object state) { var potEmpty = PotEmptied; - List toAward = new List(); + var toAward = new List(); while (_toAward.TryDequeue(out var x)) { toAward.Add(x); diff --git a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs index 8bbd70d66..80a91e1eb 100644 --- a/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs +++ b/src/NadekoBot/Modules/Gambling/Common/Events/ReactionEvent.cs @@ -67,7 +67,7 @@ public class ReactionEvent : ICurrencyEvent private async void OnTimerTick(object state) { var potEmpty = PotEmptied; - List toAward = new List(); + var toAward = new List(); while (_toAward.TryDequeue(out var x)) { toAward.Add(x); diff --git a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs index 35e9fab8b..a4f900826 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4/Connect4.cs @@ -79,7 +79,7 @@ public sealed class Connect4Game : IDisposable _cs = cs; _rng = new NadekoRandom(); - for (int i = 0; i < NumberOfColumns * NumberOfRows; i++) + for (var i = 0; i < NumberOfColumns * NumberOfRows; i++) { _gameState[i] = Field.Empty; } @@ -169,7 +169,7 @@ public sealed class Connect4Game : IDisposable return false; var start = NumberOfRows * inputCol; - for (int i = start; i < start + NumberOfRows; i++) + for (var i = start; i < start + NumberOfRows; i++) { if (_gameState[i] == Field.Empty) { @@ -181,12 +181,12 @@ public sealed class Connect4Game : IDisposable //check winnning condition // ok, i'll go from [0-2] in rows (and through all columns) and check upward if 4 are connected - for (int i = 0; i < NumberOfRows - 3; i++) + for (var i = 0; i < NumberOfRows - 3; i++) { if (CurrentPhase == Phase.Ended) break; - for (int j = 0; j < NumberOfColumns; j++) + for (var j = 0; j < NumberOfColumns; j++) { if (CurrentPhase == Phase.Ended) break; @@ -194,7 +194,7 @@ public sealed class Connect4Game : IDisposable var first = _gameState[i + j * NumberOfRows]; if (first != Field.Empty) { - for (int k = 1; k < 4; k++) + for (var k = 1; k < 4; k++) { var next = _gameState[i + k + j * NumberOfRows]; if (next == first) @@ -211,12 +211,12 @@ public sealed class Connect4Game : IDisposable } // i'll go [0-1] in columns (and through all rows) and check to the right if 4 are connected - for (int i = 0; i < NumberOfColumns - 3; i++) + for (var i = 0; i < NumberOfColumns - 3; i++) { if (CurrentPhase == Phase.Ended) break; - for (int j = 0; j < NumberOfRows; j++) + for (var j = 0; j < NumberOfRows; j++) { if (CurrentPhase == Phase.Ended) break; @@ -224,7 +224,7 @@ public sealed class Connect4Game : IDisposable var first = _gameState[j + i * NumberOfRows]; if (first != Field.Empty) { - for (int k = 1; k < 4; k++) + for (var k = 1; k < 4; k++) { var next = _gameState[j + (i + k) * NumberOfRows]; if (next == first) @@ -239,12 +239,12 @@ public sealed class Connect4Game : IDisposable } //need to check diagonal now - for (int col = 0; col < NumberOfColumns; col++) + for (var col = 0; col < NumberOfColumns; col++) { if (CurrentPhase == Phase.Ended) break; - for (int row = 0; row < NumberOfRows; row++) + for (var row = 0; row < NumberOfRows; row++) { if (CurrentPhase == Phase.Ended) break; @@ -256,7 +256,7 @@ public sealed class Connect4Game : IDisposable var same = 1; //top left - for (int i = 1; i < 4; i++) + for (var i = 1; i < 4; i++) { //while going top left, rows are increasing, columns are decreasing var curRow = row + i; @@ -283,7 +283,7 @@ public sealed class Connect4Game : IDisposable same = 1; //top right - for (int i = 1; i < 4; i++) + for (var i = 1; i < 4; i++) { //while going top right, rows are increasing, columns are increasing var curRow = row + i; @@ -361,7 +361,7 @@ public sealed class Connect4Game : IDisposable private bool IsColumnFull(int column) { var start = NumberOfRows * column; - for (int i = start; i < start + NumberOfRows; i++) + for (var i = start; i < start + NumberOfRows; i++) { if (_gameState[i] == Field.Empty) return false; diff --git a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs index a0daa78f9..2737ebf89 100644 --- a/src/NadekoBot/Modules/Gambling/Connect4Commands.cs +++ b/src/NadekoBot/Modules/Gambling/Connect4Commands.cs @@ -84,7 +84,7 @@ public partial class Gambling var _ = Task.Run(async () => { - bool success = false; + var success = false; if (int.TryParse(arg.Content, out var col)) { success = await game.Input(arg.Author.Id, col).ConfigureAwait(false); @@ -181,9 +181,9 @@ public partial class Gambling game.CurrentPhase == Connect4Game.Phase.P2Move) sb.AppendLine(GetText(strs.connect4_player_to_move(Format.Bold(game.CurrentPlayer.Username)))); - for (int i = Connect4Game.NumberOfRows; i > 0; i--) + for (var i = Connect4Game.NumberOfRows; i > 0; i--) { - for (int j = 0; j < Connect4Game.NumberOfColumns; j++) + for (var j = 0; j < Connect4Game.NumberOfColumns; j++) { var cur = game.GameState[i + (j * Connect4Game.NumberOfRows) - 1]; @@ -197,7 +197,7 @@ public partial class Gambling sb.AppendLine(); } - for (int i = 0; i < Connect4Game.NumberOfColumns; i++) + for (var i = 0; i < Connect4Game.NumberOfColumns; i++) { sb.Append(numbers[i]); } diff --git a/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs b/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs index 06a2722c2..a1b35ee76 100644 --- a/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs @@ -136,14 +136,14 @@ public partial class Gambling { Match match; if ((match = fudgeRegex.Match(arg)).Length != 0 && - int.TryParse(match.Groups["n1"].ToString(), out int n1) && + int.TryParse(match.Groups["n1"].ToString(), out var n1) && n1 > 0 && n1 < 500) { var rng = new NadekoRandom(); var rolls = new List(); - for (int i = 0; i < n1; i++) + for (var i = 0; i < n1; i++) { rolls.Add(_fateRolls[rng.Next(0, _fateRolls.Length)]); } @@ -158,16 +158,16 @@ public partial class Gambling { var rng = new NadekoRandom(); if (int.TryParse(match.Groups["n1"].ToString(), out n1) && - int.TryParse(match.Groups["n2"].ToString(), out int n2) && + int.TryParse(match.Groups["n2"].ToString(), out var n2) && n1 <= 50 && n2 <= 100000 && n1 > 0 && n2 > 0) { - if (!int.TryParse(match.Groups["add"].Value, out int add)) + if (!int.TryParse(match.Groups["add"].Value, out var add)) add = 0; - if (!int.TryParse(match.Groups["sub"].Value, out int sub)) + if (!int.TryParse(match.Groups["sub"].Value, out var sub)) sub = 0; var arr = new int[n1]; - for (int i = 0; i < n1; i++) + for (var i = 0; i < n1; i++) { arr[i] = rng.Next(1, n2 + 1); } diff --git a/src/NadekoBot/Modules/Gambling/DrawCommands.cs b/src/NadekoBot/Modules/Gambling/DrawCommands.cs index a77fcb4e4..0df10ec78 100644 --- a/src/NadekoBot/Modules/Gambling/DrawCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DrawCommands.cs @@ -31,7 +31,7 @@ public partial class Gambling if (num < 1 || num > 10) throw new ArgumentOutOfRangeException(nameof(num)); - Deck cards = guildId is null ? new Deck() : _allDecks.GetOrAdd(ctx.Guild, (s) => new Deck()); + var 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 46612eef8..b8aca01eb 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -197,7 +197,7 @@ public partial class Gambling : GamblingModule ((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString() ?? $"{userId}"))) .WithOkColor(); - var desc = ""; + var desc = string.Empty; foreach (var tr in trs) { var type = tr.Amount > 0 ? "🔵" : "🔴"; @@ -517,7 +517,7 @@ public partial class Gambling : GamblingModule var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args); - List cleanRichest = new List(); + var cleanRichest = new List(); // it's pointless to have clean on dm context if (ctx.Guild is null) { diff --git a/src/NadekoBot/Modules/Gambling/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Gambling/PlantAndPickCommands.cs index 17009ad15..7a62fdb1b 100644 --- a/src/NadekoBot/Modules/Gambling/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Gambling/PlantAndPickCommands.cs @@ -84,7 +84,7 @@ public partial class Gambling #endif public async Task GenCurrency() { - bool enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id); + var enabled = _service.ToggleCurrencyGeneration(ctx.Guild.Id, ctx.Channel.Id); if (enabled) { await ReplyConfirmLocalizedAsync(strs.curgen_enabled).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs b/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs index db4f68aac..9889bd7e7 100644 --- a/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/CurrencyEventsService.cs @@ -31,8 +31,8 @@ public class CurrencyEventsService : INService public async Task TryCreateEventAsync(ulong guildId, ulong channelId, CurrencyEvent.Type type, EventOptions opts, Func embed) { - SocketGuild g = _client.GetGuild(guildId); - SocketTextChannel ch = g?.GetChannel(channelId) as SocketTextChannel; + var g = _client.GetGuild(guildId); + var ch = g?.GetChannel(channelId) as SocketTextChannel; if (ch is null) return false; diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index d00d3af6b..09ff0df82 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -59,7 +59,7 @@ public partial class Gambling var embed = _eb.Create().WithOkColor() .WithTitle(GetText(strs.shop)); - for (int i = 0; i < theseEntries.Length; i++) + for (var i = 0; i < theseEntries.Length; i++) { var entry = theseEntries[i]; embed.AddField( @@ -292,8 +292,8 @@ public partial class Gambling Text = itemText }; ShopEntry entry; - bool rightType = false; - bool added = false; + var rightType = false; + var added = false; using (var uow = _db.GetDbContext()) { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, diff --git a/src/NadekoBot/Modules/Gambling/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/SlotCommands.cs index 899329bb5..27e3b388a 100644 --- a/src/NadekoBot/Modules/Gambling/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/SlotCommands.cs @@ -122,7 +122,7 @@ public partial class Gambling return; //multi vs how many times it occured var dict = new Dictionary(); - for (int i = 0; i < tests; i++) + for (var i = 0; i < tests; i++) { var res = SlotMachine.Pull(); if (dict.ContainsKey(res.Multiplier)) @@ -133,7 +133,7 @@ public partial class Gambling var sb = new StringBuilder(); const int bet = 1; - int payout = 0; + var payout = 0; foreach (var key in dict.Keys.OrderByDescending(x => x)) { sb.AppendLine($"x{key} occured {dict[key]} times. {dict[key] * 1.0f / tests * 100}%"); diff --git a/src/NadekoBot/Modules/Games/Common/Acrophobia/Acrophobia.cs b/src/NadekoBot/Modules/Games/Common/Acrophobia/Acrophobia.cs index 6e69d71a0..8d3890726 100644 --- a/src/NadekoBot/Modules/Games/Common/Acrophobia/Acrophobia.cs +++ b/src/NadekoBot/Modules/Games/Common/Acrophobia/Acrophobia.cs @@ -106,7 +106,7 @@ public sealed class AcrophobiaGame : IDisposable var lettersArr = new char[wordCount]; - for (int i = 0; i < wordCount; i++) + for (var i = 0; i < wordCount; i++) { var randChar = (char)_rng.Next(65, 91); lettersArr[i] = randChar == 'X' ? (char)_rng.Next(65, 88) : randChar; @@ -160,7 +160,7 @@ public sealed class AcrophobiaGame : IDisposable if (inputWords.Length != StartingLetters.Length) // number of words must be the same as the number of the starting letters return false; - for (int i = 0; i < StartingLetters.Length; i++) + for (var i = 0; i < StartingLetters.Length; i++) { var letter = StartingLetters[i]; diff --git a/src/NadekoBot/Modules/Games/Common/PollRunner.cs b/src/NadekoBot/Modules/Games/Common/PollRunner.cs index 2a6d4e13c..49f833a57 100644 --- a/src/NadekoBot/Modules/Games/Common/PollRunner.cs +++ b/src/NadekoBot/Modules/Games/Common/PollRunner.cs @@ -33,7 +33,7 @@ public class PollRunner return false; // has to be an integer - if (!int.TryParse(msg.Content, out int vote)) + if (!int.TryParse(msg.Content, out var vote)) return false; --vote; if (vote < 0 || vote >= Poll.Answers.Count) diff --git a/src/NadekoBot/Modules/Games/Common/TicTacToe.cs b/src/NadekoBot/Modules/Games/Common/TicTacToe.cs index 89ebd7392..12eaa6786 100644 --- a/src/NadekoBot/Modules/Games/Common/TicTacToe.cs +++ b/src/NadekoBot/Modules/Games/Common/TicTacToe.cs @@ -250,7 +250,7 @@ public class TicTacToe _phase = Phase.Ended; } - var reason = ""; + var reason = string.Empty; if (_phase == Phase.Ended) // if user won, stop receiving moves { diff --git a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestion.cs b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestion.cs index 4c9aab9e1..6821609e7 100644 --- a/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestion.cs +++ b/src/NadekoBot/Modules/Games/Common/Trivia/TriviaQuestion.cs @@ -46,15 +46,15 @@ public class TriviaQuestion return true; } - int levDistanceClean = CleanAnswer.LevenshteinDistance(cleanGuess); - int levDistanceNormal = Answer.LevenshteinDistance(guess); + var levDistanceClean = CleanAnswer.LevenshteinDistance(cleanGuess); + var levDistanceNormal = Answer.LevenshteinDistance(guess); return JudgeGuess(CleanAnswer.Length, cleanGuess.Length, levDistanceClean) || JudgeGuess(Answer.Length, guess.Length, levDistanceNormal); } private static bool JudgeGuess(int guessLength, int answerLength, int levDistance) { - foreach (Tuple level in strictness) + foreach (var level in strictness) { if (guessLength <= level.Item1 || answerLength <= level.Item1) { diff --git a/src/NadekoBot/Modules/Games/PollCommands.cs b/src/NadekoBot/Modules/Games/PollCommands.cs index 0f0a708f2..a804e5ac4 100644 --- a/src/NadekoBot/Modules/Games/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/PollCommands.cs @@ -105,7 +105,7 @@ public partial class Games .OrderByDescending(x => x.votes) .ToArray(); - for (int i = 0; i < stats.Length; i++) + for (var i = 0; i < stats.Length; i++) { var (Index, votes, Text) = stats[i]; sb.AppendLine(GetText(strs.poll_result( diff --git a/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs b/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs index 44b96415a..f691cc5e4 100644 --- a/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs +++ b/src/NadekoBot/Modules/Games/Services/ChatterbotService.cs @@ -60,7 +60,7 @@ public class ChatterBotService : IEarlyBehavior if (channel is null) return null; - if (!ChatterBotGuilds.TryGetValue(channel.Guild.Id, out Lazy lazyCleverbot)) + if (!ChatterBotGuilds.TryGetValue(channel.Guild.Id, out var lazyCleverbot)) return null; cleverbot = lazyCleverbot.Value; @@ -107,7 +107,7 @@ public class ChatterBotService : IEarlyBehavior return false; try { - var message = PrepareMessage(usrMsg, out IChatterBotSession cbs); + var message = PrepareMessage(usrMsg, out var cbs); if (message is null || cbs is null) return false; @@ -115,7 +115,7 @@ public class ChatterBotService : IEarlyBehavior if (!pc.Permissions.CheckPermissions(usrMsg, "cleverbot", "Games".ToLowerInvariant(), - out int index)) + out var index)) { if (pc.Verbose) { diff --git a/src/NadekoBot/Modules/Games/SpeedTypingCommands.cs b/src/NadekoBot/Modules/Games/SpeedTypingCommands.cs index ee7683d25..586c9f68e 100644 --- a/src/NadekoBot/Modules/Games/SpeedTypingCommands.cs +++ b/src/NadekoBot/Modules/Games/SpeedTypingCommands.cs @@ -48,7 +48,7 @@ public partial class Games [RequireContext(ContextType.Guild)] public async Task TypeStop() { - if (_service.RunningContests.TryRemove(ctx.Guild.Id, out TypingGame game)) + if (_service.RunningContests.TryRemove(ctx.Guild.Id, out var game)) { await game.Stop().ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Games/TicTacToeCommands.cs b/src/NadekoBot/Modules/Games/TicTacToeCommands.cs index 3bb88a0c3..83ff30210 100644 --- a/src/NadekoBot/Modules/Games/TicTacToeCommands.cs +++ b/src/NadekoBot/Modules/Games/TicTacToeCommands.cs @@ -34,7 +34,7 @@ public partial class Games await _sem.WaitAsync(1000).ConfigureAwait(false); try { - if (_service.TicTacToeGames.TryGetValue(channel.Id, out TicTacToe game)) + if (_service.TicTacToeGames.TryGetValue(channel.Id, out var game)) { var _ = Task.Run(async () => { diff --git a/src/NadekoBot/Modules/Games/TriviaCommands.cs b/src/NadekoBot/Modules/Games/TriviaCommands.cs index 43a0969ea..0faea70ac 100644 --- a/src/NadekoBot/Modules/Games/TriviaCommands.cs +++ b/src/NadekoBot/Modules/Games/TriviaCommands.cs @@ -72,7 +72,7 @@ public partial class Games [RequireContext(ContextType.Guild)] public async Task Tl() { - if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out TriviaGame trivia)) + if (_service.RunningTrivias.TryGetValue(ctx.Guild.Id, out var trivia)) { await SendConfirmAsync(GetText(strs.leaderboard), trivia.GetLeaderboard()).ConfigureAwait(false); return; @@ -87,7 +87,7 @@ public partial class Games { var channel = (ITextChannel)ctx.Channel; - if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out TriviaGame trivia)) + if (_service.RunningTrivias.TryGetValue(channel.Guild.Id, out var trivia)) { await trivia.StopGame().ConfigureAwait(false); return; diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index b6b15e604..e4fa55a4b 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -283,7 +283,7 @@ public class Help : NadekoModule if (com is null) { - IMessageChannel ch = channel is ITextChannel + var ch = channel is ITextChannel ? await ((IGuildUser)ctx.User).GetOrCreateDMChannelAsync().ConfigureAwait(false) : channel; try diff --git a/src/NadekoBot/Modules/Help/Services/HelpService.cs b/src/NadekoBot/Modules/Help/Services/HelpService.cs index 9ae47a0fe..cca4ec320 100644 --- a/src/NadekoBot/Modules/Help/Services/HelpService.cs +++ b/src/NadekoBot/Modules/Help/Services/HelpService.cs @@ -135,7 +135,7 @@ public class HelpService : ILateExecutor, INService var userPerm = (UserPermAttribute)cmd.Preconditions .FirstOrDefault(ca => ca is UserPermAttribute); - string userPermString = string.Empty; + var userPermString = string.Empty; if (userPerm is not null) { if (userPerm.UserPermissionAttribute.ChannelPermission is ChannelPermission cPerm) diff --git a/src/NadekoBot/Modules/Music/Common/Impl/MusicPlayer.cs b/src/NadekoBot/Modules/Music/Common/Impl/MusicPlayer.cs index 4224f850c..62987ac4f 100644 --- a/src/NadekoBot/Modules/Music/Common/Impl/MusicPlayer.cs +++ b/src/NadekoBot/Modules/Music/Common/Impl/MusicPlayer.cs @@ -106,7 +106,7 @@ public sealed class MusicPlayer : IMusicPlayer { // wait until a song is available in the queue // or until the queue is resumed - var track = _queue.GetCurrent(out int index); + var track = _queue.GetCurrent(out var index); if (track is null || IsStopped) { diff --git a/src/NadekoBot/Modules/Music/Common/Impl/MusicQueue.cs b/src/NadekoBot/Modules/Music/Common/Impl/MusicQueue.cs index f3a9d3c0e..f6b5cffde 100644 --- a/src/NadekoBot/Modules/Music/Common/Impl/MusicQueue.cs +++ b/src/NadekoBot/Modules/Music/Common/Impl/MusicQueue.cs @@ -85,7 +85,7 @@ public sealed partial class MusicQueue : IMusicQueue return Enqueue(trackInfo, queuer, out index); } - LinkedListNode currentNode = _tracks.First!; + var currentNode = _tracks.First!; int i; for (i = 1; i <= _index; i++) { diff --git a/src/NadekoBot/Modules/Music/Music.cs b/src/NadekoBot/Modules/Music/Music.cs index 3775b5524..fbe21efe5 100644 --- a/src/NadekoBot/Modules/Music/Music.cs +++ b/src/NadekoBot/Modules/Music/Music.cs @@ -280,7 +280,7 @@ public sealed partial class Music : NadekoModule IEmbedBuilder printAction(int curPage) { - string desc = string.Empty; + var desc = string.Empty; var current = mp.GetCurrentTrack(out var currentIndex); if (current is not null) { @@ -288,7 +288,7 @@ public sealed partial class Music : NadekoModule } var repeatType = mp.Repeat; - var add = ""; + var add = string.Empty; if (mp.IsStopped) add += Format.Bold(GetText(strs.queue_stopped(Format.Code(Prefix + "play")))) + "\n"; // var mps = mp.MaxPlaytimeSeconds; diff --git a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs index 8afa0d8f1..7d88b5888 100644 --- a/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs +++ b/src/NadekoBot/Modules/Permissions/Common/PermissionExtensions.cs @@ -11,7 +11,7 @@ public static class PermissionExtensions { var perms = permsEnumerable as List ?? permsEnumerable.ToList(); - for (int i = perms.Count - 1; i >= 0; i--) + for (var i = perms.Count - 1; i >= 0; i--) { var perm = perms[i]; @@ -68,7 +68,7 @@ public static class PermissionExtensions public static string GetCommand(this Permissionv2 perm, string prefix, SocketGuild guild = null) { - var com = ""; + var com = string.Empty; switch (perm.PrimaryTarget) { case PrimaryPermissionType.User: diff --git a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs index 90a056212..3a7a73ef6 100644 --- a/src/NadekoBot/Modules/Permissions/Services/FilterService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/FilterService.cs @@ -33,7 +33,7 @@ public sealed class FilterService : IEarlyBehavior public ConcurrentHashSet FilteredWordsForChannel(ulong channelId, ulong guildId) { - ConcurrentHashSet words = new ConcurrentHashSet(); + var words = new ConcurrentHashSet(); if (WordFilteringChannels.Contains(channelId)) ServerFilteredWords.TryGetValue(guildId, out words); return words; diff --git a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs index f14a0ca25..b25a7a97d 100644 --- a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs @@ -119,8 +119,8 @@ public class PermissionService : ILateBlocker, INService { var resetCommand = commandName == "resetperms"; - PermissionCache pc = GetCacheFor(guild.Id); - if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out int index)) + var pc = GetCacheFor(guild.Id); + if (!resetCommand && !pc.Permissions.CheckPermissions(msg, commandName, moduleName, out var index)) { if (pc.Verbose) { diff --git a/src/NadekoBot/Modules/Searches/Common/StreamNotifications/Providers/TwitchHelixProvider.cs b/src/NadekoBot/Modules/Searches/Common/StreamNotifications/Providers/TwitchHelixProvider.cs index 1f572f743..827b6dfb7 100644 --- a/src/NadekoBot/Modules/Searches/Common/StreamNotifications/Providers/TwitchHelixProvider.cs +++ b/src/NadekoBot/Modules/Searches/Common/StreamNotifications/Providers/TwitchHelixProvider.cs @@ -35,8 +35,8 @@ // if (_token != default && (DateTime.UtcNow - _token.Expiry) > TimeSpan.FromHours(1)) // return; // -// const string clientId = ""; -// const string clientSecret = ""; +// const string clientId = string.Empty; +// const string clientSecret = string.Empty; // // var client = _httpClientFactory.CreateClient(); // var res = await client.PostAsync("https://id.twitch.tv/oauth2/token" + diff --git a/src/NadekoBot/Modules/Searches/MemegenCommands.cs b/src/NadekoBot/Modules/Searches/MemegenCommands.cs index a6bff615f..1a0f59814 100644 --- a/src/NadekoBot/Modules/Searches/MemegenCommands.cs +++ b/src/NadekoBot/Modules/Searches/MemegenCommands.cs @@ -55,7 +55,7 @@ public partial class Searches await ctx.SendPaginatedConfirmAsync(page, curPage => { - var templates = ""; + var templates = string.Empty; foreach (var template in data.Skip(curPage * 15).Take(15)) { templates += $"**{template.Name}:**\n key: `{template.Id}`\n"; diff --git a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs index 149181f3f..e5ba8f869 100644 --- a/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs +++ b/src/NadekoBot/Modules/Searches/PathOfExileCommands.cs @@ -85,7 +85,7 @@ public partial class Searches { var sb = new System.Text.StringBuilder(); sb.AppendLine($"```{"#",-5}{"Character Name",-23}{"League",-10}{"Class",-13}{"Level",-3}"); - for (int i = 0; i < tempList.Count; i++) + for (var i = 0; i < tempList.Count; i++) { var character = tempList[i]; @@ -131,7 +131,7 @@ public partial class Searches var sb = new System.Text.StringBuilder(); sb.AppendLine($"```{"#",-5}{"League Name",-23}"); - for (int i = 0; i < leagues.Count; i++) + for (var i = 0; i < leagues.Count; i++) { var league = leagues[i]; @@ -168,8 +168,8 @@ public partial class Searches { var obj = JObject.Parse(await http.GetStringAsync(res).ConfigureAwait(false)); - float chaosEquivalent = 0.0F; - float conversionEquivalent = 0.0F; + var chaosEquivalent = 0.0F; + var conversionEquivalent = 0.0F; // poe.ninja API does not include a "chaosEquivalent" property for Chaos Orbs. if (cleanCurrency == "Chaos Orb") diff --git a/src/NadekoBot/Modules/Searches/PlaceCommands.cs b/src/NadekoBot/Modules/Searches/PlaceCommands.cs index 8ff5352cd..75e0f5501 100644 --- a/src/NadekoBot/Modules/Searches/PlaceCommands.cs +++ b/src/NadekoBot/Modules/Searches/PlaceCommands.cs @@ -36,7 +36,7 @@ public partial class Searches [NadekoCommand, Aliases] public async Task Place(PlaceType placeType, uint width = 0, uint height = 0) { - var url = ""; + var url = string.Empty; switch (placeType) { case PlaceType.Cage: diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 4fd800b50..73d11dfa4 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -75,7 +75,7 @@ public partial class Searches : NadekoModule } else { - Func f = StandardConversions.CelsiusToFahrenheit; + var f = StandardConversions.CelsiusToFahrenheit; var tz = ctx.Guild is null ? TimeZoneInfo.Utc @@ -616,7 +616,7 @@ public partial class Searches : NadekoModule using (var img = new Image(colorObjects.Length * 50, 50)) { - for (int i = 0; i < colorObjects.Length; i++) + for (var i = 0; i < colorObjects.Length; i++) { var x = i * 50; img.Mutate(m => m.FillPolygon(colorObjects[i], new PointF[] { diff --git a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs index 7e2160b08..c8dfe044d 100644 --- a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs @@ -72,7 +72,7 @@ public class FeedsService : INService .Reverse() // start from the oldest .ToList(); - if (!_lastPosts.TryGetValue(kvp.Key, out DateTime lastFeedUpdate)) + if (!_lastPosts.TryGetValue(kvp.Key, out var lastFeedUpdate)) { lastFeedUpdate = _lastPosts[kvp.Key] = items.Any() ? items[items.Count - 1].LastUpdate : DateTime.UtcNow; diff --git a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs index f4022d15e..c31956bcb 100644 --- a/src/NadekoBot/Modules/Searches/Services/SearchesService.cs +++ b/src/NadekoBot/Modules/Searches/Services/SearchesService.cs @@ -77,7 +77,7 @@ public class SearchesService : INService public async Task GetRipPictureAsync(string text, Uri imgUrl) { - byte[] data = await _cache.GetOrAddCachedDataAsync($"nadeko_rip_{text}_{imgUrl}", + var data = await _cache.GetOrAddCachedDataAsync($"nadeko_rip_{text}_{imgUrl}", GetRipPictureFactory, (text, imgUrl), TimeSpan.FromDays(1)).ConfigureAwait(false); @@ -388,7 +388,7 @@ public class SearchesService : INService return new MtgData[0]; var tasks = new List>(cards.Length); - for (int i = 0; i < cards.Length; i++) + for (var i = 0; i < cards.Length; i++) { var card = cards[i]; diff --git a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs index 42b98fea0..fece60a92 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs @@ -83,7 +83,7 @@ public partial class Searches return; } - List streams = new List(); + var streams = new List(); using (var uow = _db.GetDbContext()) { var all = uow diff --git a/src/NadekoBot/Modules/Utility/InfoCommands.cs b/src/NadekoBot/Modules/Utility/InfoCommands.cs index 79944bd54..2fa9eade7 100644 --- a/src/NadekoBot/Modules/Utility/InfoCommands.cs +++ b/src/NadekoBot/Modules/Utility/InfoCommands.cs @@ -133,9 +133,9 @@ public partial class Utility if (page < 0) return; - int startCount = page * activityPerPage; + var startCount = page * activityPerPage; - StringBuilder str = new StringBuilder(); + var str = new StringBuilder(); foreach (var kvp in CmdHandler.UserMessagesSent.OrderByDescending(kvp => kvp.Value).Skip(page * activityPerPage).Take(activityPerPage)) { str.AppendLine(GetText(strs.activity_line( diff --git a/src/NadekoBot/Modules/Utility/RepeatCommands.cs b/src/NadekoBot/Modules/Utility/RepeatCommands.cs index 3a40df724..be32f7f61 100644 --- a/src/NadekoBot/Modules/Utility/RepeatCommands.cs +++ b/src/NadekoBot/Modules/Utility/RepeatCommands.cs @@ -187,7 +187,7 @@ public partial class Utility var executesInString = Format.Bold(executesIn.ToPrettyStringHM()); var message = Format.Sanitize(runner.Repeater.Message.TrimTo(50)); - string description = ""; + var description = string.Empty; if (_service.IsNoRedundant(runner.Repeater.Id)) { description = Format.Underline(Format.Bold(GetText(strs.no_redundant))) + "\n\n"; diff --git a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs index c96e803f5..2168f3bba 100644 --- a/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs +++ b/src/NadekoBot/Modules/Utility/Services/CommandMapService.cs @@ -67,7 +67,7 @@ public class CommandMapService : IInputTransformer, INService if (guild != null) { - if (AliasMaps.TryGetValue(guild.Id, out ConcurrentDictionary maps)) + if (AliasMaps.TryGetValue(guild.Id, out var maps)) { var keys = maps.Keys .OrderByDescending(x => x.Length); diff --git a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs index 2e3438316..0df8c8e2b 100644 --- a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs +++ b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs @@ -69,7 +69,7 @@ public class StreamRoleService : INService { userName.ThrowIfNull(nameof(userName)); - bool success = false; + var success = false; using (var uow = _db.GetDbContext()) { var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); diff --git a/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs b/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs index 10ad0fa3b..6d89aa53e 100644 --- a/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs +++ b/src/NadekoBot/Modules/Utility/StreamRoleCommands.cs @@ -39,7 +39,7 @@ public partial class Utility [RequireContext(ContextType.Guild)] public async Task StreamRoleKeyword([Leftover]string keyword = null) { - string kw = await this._service.SetKeyword(ctx.Guild, keyword).ConfigureAwait(false); + var kw = await this._service.SetKeyword(ctx.Guild, keyword).ConfigureAwait(false); if(string.IsNullOrWhiteSpace(keyword)) await ReplyConfirmLocalizedAsync(strs.stream_role_kw_reset).ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index 936c3f323..db2036c01 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -81,7 +81,7 @@ public partial class Utility : NadekoModule .Take(60) .ToArray()).ConfigureAwait(false); - int i = 0; + var i = 0; if (arr.Length == 0) await ReplyErrorLocalizedAsync(strs.nobody_playing_game).ConfigureAwait(false); else @@ -140,7 +140,7 @@ public partial class Utility : NadekoModule [RequireContext(ContextType.Guild)] public async Task CheckPerms(MeOrBot who = MeOrBot.Me) { - StringBuilder builder = new StringBuilder(); + var builder = new StringBuilder(); var user = who == MeOrBot.Me ? (IGuildUser)ctx.User : ((SocketGuild)ctx.Guild).CurrentUser; diff --git a/src/NadekoBot/Modules/Xp/Club.cs b/src/NadekoBot/Modules/Xp/Club.cs index 3fab0bdc5..e412fded5 100644 --- a/src/NadekoBot/Modules/Xp/Club.cs +++ b/src/NadekoBot/Modules/Xp/Club.cs @@ -62,7 +62,7 @@ public partial class Xp return; } - if (!_service.CreateClub(ctx.User, clubName, out ClubInfo club)) + if (!_service.CreateClub(ctx.User, clubName, out var club)) { await ReplyErrorLocalizedAsync(strs.club_create_error).ConfigureAwait(false); return; @@ -109,7 +109,7 @@ public partial class Xp return; } - if (!_service.GetClubByName(clubName, out ClubInfo club)) + if (!_service.GetClubByName(clubName, out var club)) { await ReplyErrorLocalizedAsync(strs.club_not_exists).ConfigureAwait(false); return; @@ -226,7 +226,7 @@ public partial class Xp if (string.IsNullOrWhiteSpace(clubName)) return; - if (!_service.GetClubByName(clubName, out ClubInfo club)) + if (!_service.GetClubByName(clubName, out var club)) { await ReplyErrorLocalizedAsync(strs.club_not_exists).ConfigureAwait(false); return; @@ -345,7 +345,7 @@ public partial class Xp [NadekoCommand, Aliases] public async Task ClubDisband() { - if (_service.Disband(ctx.User.Id, out ClubInfo club)) + if (_service.Disband(ctx.User.Id, out var club)) { await ReplyConfirmLocalizedAsync(strs.club_disbanded(Format.Bold(club.ToString()))); } diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 4473434c4..98af12660 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -339,7 +339,7 @@ public partial class Xp : NadekoModule await ctx.Channel.TriggerTypingAsync(); var socketGuild = ((SocketGuild)ctx.Guild); - List allUsers = new List(); + var allUsers = new List(); if (opts.Clean) { await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); @@ -370,14 +370,14 @@ public partial class Xp : NadekoModule return embed.WithDescription("-"); else { - for (int i = 0; i < users.Count; i++) + for (var i = 0; i < users.Count; i++) { var levelStats = new LevelStats(users[i].Xp + users[i].AwardedXp); var user = ((SocketGuild)ctx.Guild).GetUser(users[i].UserId); var userXpData = users[i]; - var awardStr = ""; + var awardStr = string.Empty; if (userXpData.AwardedXp > 0) awardStr = $"(+{userXpData.AwardedXp})"; else if (userXpData.AwardedXp < 0) @@ -408,7 +408,7 @@ public partial class Xp : NadekoModule embed.WithDescription("-"); else { - for (int i = 0; i < users.Length; i++) + for (var i = 0; i < users.Length; i++) { var user = users[i]; embed.AddField( diff --git a/src/NadekoBot/Services/Impl/CurrencyService.cs b/src/NadekoBot/Services/Impl/CurrencyService.cs index 256a4235f..2d3fd0148 100644 --- a/src/NadekoBot/Services/Impl/CurrencyService.cs +++ b/src/NadekoBot/Services/Impl/CurrencyService.cs @@ -94,9 +94,9 @@ public class CurrencyService : ICurrencyService, INService public async Task AddBulkAsync(IEnumerable userIds, IEnumerable reasons, IEnumerable amounts, bool gamble = false) { - ulong[] idArray = userIds as ulong[] ?? userIds.ToArray(); - string[] reasonArray = reasons as string[] ?? reasons.ToArray(); - long[] amountArray = amounts as long[] ?? amounts.ToArray(); + var idArray = userIds as ulong[] ?? userIds.ToArray(); + var reasonArray = reasons as string[] ?? reasons.ToArray(); + var amountArray = amounts as long[] ?? amounts.ToArray(); if (idArray.Length != reasonArray.Length || reasonArray.Length != amountArray.Length) throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length."); @@ -104,7 +104,7 @@ public class CurrencyService : ICurrencyService, INService var userIdHashSet = new HashSet(idArray.Length); using (var uow = _db.GetDbContext()) { - for (int i = 0; i < idArray.Length; i++) + for (var i = 0; i < idArray.Length; i++) { // i have to prevent same user changing more than once as it will cause db error if (userIdHashSet.Add(idArray[i])) @@ -126,7 +126,7 @@ public class CurrencyService : ICurrencyService, INService var userIdHashSet = new HashSet(idArray.Length); using (var uow = _db.GetDbContext()) { - for (int i = 0; i < idArray.Length; i++) + for (var i = 0; i < idArray.Length; i++) { // i have to prevent same user changing more than once as it will cause db error if (userIdHashSet.Add(idArray[i])) diff --git a/src/NadekoBot/Services/Impl/FontProvider.cs b/src/NadekoBot/Services/Impl/FontProvider.cs index d2fd411b4..3a154a195 100644 --- a/src/NadekoBot/Services/Impl/FontProvider.cs +++ b/src/NadekoBot/Services/Impl/FontProvider.cs @@ -23,7 +23,7 @@ public class FontProvider : INService { try { - string fontsfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts); + var fontsfolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Fonts); FallBackFonts.Add(_fonts.Install(Path.Combine(fontsfolder, "seguiemj.ttf"))); FallBackFonts.AddRange(_fonts.InstallCollection(Path.Combine(fontsfolder, "msgothic.ttc"))); FallBackFonts.AddRange(_fonts.InstallCollection(Path.Combine(fontsfolder, "segoe.ttc"))); diff --git a/src/NadekoBot/Services/Impl/GoogleApiService.cs b/src/NadekoBot/Services/Impl/GoogleApiService.cs index 307a110c4..ae8b23901 100644 --- a/src/NadekoBot/Services/Impl/GoogleApiService.cs +++ b/src/NadekoBot/Services/Impl/GoogleApiService.cs @@ -151,7 +151,7 @@ public class GoogleApiService : IGoogleApiService, INService string nextPageToken = null; - List toReturn = new List(count); + var toReturn = new List(count); do { @@ -178,7 +178,7 @@ public class GoogleApiService : IGoogleApiService, INService await Task.Yield(); var videoIdsList = videoIds as List ?? videoIds.ToList(); - Dictionary toReturn = new Dictionary(); + var toReturn = new Dictionary(); if (!videoIdsList.Any()) return toReturn; diff --git a/src/NadekoBot/Services/Impl/RedisCache.cs b/src/NadekoBot/Services/Impl/RedisCache.cs index 4b6ebb3d1..296f9420b 100644 --- a/src/NadekoBot/Services/Impl/RedisCache.cs +++ b/src/NadekoBot/Services/Impl/RedisCache.cs @@ -174,7 +174,7 @@ public class RedisCache : IDataCache { var _db = Redis.GetDatabase(); - RedisValue data = await _db.StringGetAsync(key).ConfigureAwait(false); + var data = await _db.StringGetAsync(key).ConfigureAwait(false); if (!data.HasValue) { var obj = await factory(param).ConfigureAwait(false); diff --git a/src/NadekoBot/Services/Impl/RedisImagesCache.cs b/src/NadekoBot/Services/Impl/RedisImagesCache.cs index 950387513..5d1367717 100644 --- a/src/NadekoBot/Services/Impl/RedisImagesCache.cs +++ b/src/NadekoBot/Services/Impl/RedisImagesCache.cs @@ -21,7 +21,7 @@ public sealed class RedisImagesCache : IImageCache, IReadyExecutor private IDatabase _db => _con.GetDatabase(); private const string _basePath = "data/"; - private const string _cardsPath = "data/images/cards"; + private const string _cardsPath = $"{_basePath}images/cards"; public ImageUrls ImageUrls { get; private set; } diff --git a/src/NadekoBot/Services/Impl/SoundCloudApiService.cs b/src/NadekoBot/Services/Impl/SoundCloudApiService.cs index c1206b7d8..37340f2b8 100644 --- a/src/NadekoBot/Services/Impl/SoundCloudApiService.cs +++ b/src/NadekoBot/Services/Impl/SoundCloudApiService.cs @@ -18,7 +18,7 @@ public class SoundCloudApiService : INService if (string.IsNullOrWhiteSpace(url)) throw new ArgumentNullException(nameof(url)); - string response = ""; + var response = string.Empty; using (var http = _httpFactory.CreateClient()) { @@ -37,7 +37,7 @@ public class SoundCloudApiService : INService if (string.IsNullOrWhiteSpace(query)) throw new ArgumentNullException(nameof(query)); - var response = ""; + var response = string.Empty; using (var http = _httpFactory.CreateClient()) { response = await http.GetStringAsync(new Uri($"https://scapi.nadeko.bot/tracks?q={Uri.EscapeDataString(query)}")).ConfigureAwait(false); @@ -55,17 +55,17 @@ public class SoundCloudApiService : INService public class SoundCloudVideo { - public string Kind { get; set; } = ""; + public string Kind { get; set; } = string.Empty; public long Id { get; set; } = 0; public SoundCloudUser User { get; set; } = new SoundCloudUser(); - public string Title { get; set; } = ""; + public string Title { get; set; } = string.Empty; public string FullName => User.Name + " - " + Title; public bool? Streamable { get; set; } = false; public int Duration { get; set; } [JsonProperty("permalink_url")] - public string TrackLink { get; set; } = ""; + public string TrackLink { get; set; } = string.Empty; [JsonProperty("artwork_url")] - public string ArtworkUrl { get; set; } = ""; + public string ArtworkUrl { get; set; } = string.Empty; } public class SoundCloudUser diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index cdd076f32..7c3c0c4d0 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -103,8 +103,8 @@ public static class Extensions // https://github.com/SixLabors/Samples/blob/master/ImageSharp/AvatarWithRoundedCorner/Program.cs public static IImageProcessingContext ApplyRoundedCorners(this IImageProcessingContext ctx, float cornerRadius) { - Size size = ctx.GetCurrentSize(); - IPathCollection corners = BuildCorners(size.Width, size.Height, cornerRadius); + var size = ctx.GetCurrentSize(); + var corners = BuildCorners(size.Width, size.Height, cornerRadius); ctx.SetGraphicsOptions(new GraphicsOptions() { @@ -125,18 +125,18 @@ public static class Extensions var rect = new RectangularPolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); // then cut out of the square a circle so we are left with a corner - IPath cornerTopLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); + var cornerTopLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); // corner is now a corner shape positions top left //lets make 3 more positioned correctly, we can do that by translating the original around the center of the image - float rightPos = imageWidth - cornerTopLeft.Bounds.Width + 1; - float bottomPos = imageHeight - cornerTopLeft.Bounds.Height + 1; + var rightPos = imageWidth - cornerTopLeft.Bounds.Width + 1; + var bottomPos = imageHeight - cornerTopLeft.Bounds.Height + 1; // move it across the width of the image - the width of the shape - IPath cornerTopRight = cornerTopLeft.RotateDegree(90).Translate(rightPos, 0); - IPath cornerBottomLeft = cornerTopLeft.RotateDegree(-90).Translate(0, bottomPos); - IPath cornerBottomRight = cornerTopLeft.RotateDegree(180).Translate(rightPos, bottomPos); + var cornerTopRight = cornerTopLeft.RotateDegree(90).Translate(rightPos, 0); + var cornerBottomLeft = cornerTopLeft.RotateDegree(-90).Translate(0, bottomPos); + var cornerBottomRight = cornerTopLeft.RotateDegree(180).Translate(rightPos, bottomPos); return new PathCollection(cornerTopLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight); } diff --git a/src/NadekoBot/_Extensions/StringExtensions.cs b/src/NadekoBot/_Extensions/StringExtensions.cs index 5e90bbb9a..8414bf85d 100644 --- a/src/NadekoBot/_Extensions/StringExtensions.cs +++ b/src/NadekoBot/_Extensions/StringExtensions.cs @@ -11,8 +11,8 @@ public static class StringExtensions { public static string PadBoth(this string str, int length) { - int spaces = length - str.Length; - int padLeft = spaces / 2 + str.Length; + var spaces = length - str.Length; + var padLeft = spaces / 2 + str.Length; return str.PadLeft(padLeft).PadRight(length); } diff --git a/src/ayu/Ayu.Discord.Voice/SocketClient.cs b/src/ayu/Ayu.Discord.Voice/SocketClient.cs index b3bd04752..44b7f1099 100644 --- a/src/ayu/Ayu.Discord.Voice/SocketClient.cs +++ b/src/ayu/Ayu.Discord.Voice/SocketClient.cs @@ -22,7 +22,7 @@ namespace Ayu.Discord.Gateway var bufferWriter = new ArrayBufferWriter(CHUNK_SIZE); try { - using (_ws = new ClientWebSocket()) + using (_ws = new()) { await _ws.ConnectAsync(url, cancel).ConfigureAwait(false); // WebsocketConnected!.Invoke(this); @@ -94,10 +94,10 @@ namespace Ayu.Discord.Gateway var ws = _ws; if (ws is null) throw new WebSocketException("Websocket is disconnected."); - for (int i = 0; i < data.Length; i += 4096) + for (var i = 0; i < data.Length; i += 4096) { var count = i + 4096 > data.Length ? data.Length - i : 4096; - await ws.SendAsync(new ArraySegment(data, i, count), + await ws.SendAsync(new(data, i, count), WebSocketMessageType.Text, i + count >= data.Length, CancellationToken.None).ConfigureAwait(false); @@ -115,7 +115,7 @@ namespace Ayu.Discord.Gateway if (ws is null) throw new WebSocketException("Websocket is disconnected."); - await ws.SendAsync(new ArraySegment(data, 0, data.Length), + await ws.SendAsync(new(data, 0, data.Length), WebSocketMessageType.Binary, true, CancellationToken.None).ConfigureAwait(false); diff --git a/src/ayu/Ayu.Discord.Voice/VoiceClient.cs b/src/ayu/Ayu.Discord.Voice/VoiceClient.cs index d7f88796a..86c9667ca 100644 --- a/src/ayu/Ayu.Discord.Voice/VoiceClient.cs +++ b/src/ayu/Ayu.Discord.Voice/VoiceClient.cs @@ -37,7 +37,7 @@ namespace Ayu.Discord.Voice this.channels = (int) channels; this.bitDepth = (int) bitDepthEnum; - this.Encoder = new LibOpusEncoder(this.sampleRate, this.channels, this.bitRate, this.frameDelay); + this.Encoder = new(this.sampleRate, this.channels, this.bitRate, this.frameDelay); Encode = bitDepthEnum switch { diff --git a/src/ayu/Ayu.Discord.Voice/VoiceGateway.cs b/src/ayu/Ayu.Discord.Voice/VoiceGateway.cs index 7233c4b3e..cca0935b1 100644 --- a/src/ayu/Ayu.Discord.Voice/VoiceGateway.cs +++ b/src/ayu/Ayu.Discord.Voice/VoiceGateway.cs @@ -46,14 +46,14 @@ namespace Ayu.Discord.Voice private IPEndPoint? _udpEp; public uint Ssrc { get; private set; } - public string Ip { get; private set; } = ""; + public string Ip { get; private set; } = string.Empty; public int Port { get; private set; } = 0; public byte[] SecretKey { get; private set; } = Array.Empty(); - public string Mode { get; private set; } = ""; + public string Mode { get; private set; } = string.Empty; public ushort Sequence { get; set; } public uint NonceSequence { get; set; } public uint Timestamp { get; set; } - public string MyIp { get; private set; } = ""; + public string MyIp { get; private set; } = string.Empty; public ushort MyPort { get; private set; } private bool shouldResume = false; @@ -74,21 +74,21 @@ namespace Ayu.Discord.Voice //Log.Information("g: {GuildId} u: {UserId} sess: {Session} tok: {Token} ep: {Endpoint}", // guildId, userId, session, token, endpoint); - this._websocketUrl = new Uri($"wss://{_endpoint.Replace(":80", "")}?v=4"); - this._channel = Channel.CreateUnbounded(new UnboundedChannelOptions + this._websocketUrl = new($"wss://{_endpoint.Replace(":80", "")}?v=4"); + this._channel = Channel.CreateUnbounded(new() { SingleReader = true, SingleWriter = false, AllowSynchronousContinuations = false, }); - ConnectingFinished = new TaskCompletionSource(); + ConnectingFinished = new(); - _rng = new Random(); + _rng = new(); - _ws = new SocketClient(); - _udpClient = new UdpClient(); - _stopCancellationSource = new CancellationTokenSource(); + _ws = new(); + _udpClient = new(); + _stopCancellationSource = new(); _stopCancellationToken = _stopCancellationSource.Token; _ws.PayloadReceived += _ws_PayloadReceived; @@ -216,7 +216,7 @@ namespace Ayu.Discord.Voice private Task ResumeAsync() { shouldResume = false; - return SendCommandPayloadAsync(new VoicePayload + return SendCommandPayloadAsync(new() { OpCode = VoiceOpCode.Resume, Data = JToken.FromObject(new VoiceResume @@ -234,7 +234,7 @@ namespace Ayu.Discord.Voice //Log.Information("Received ready {GuildId}, {Session}, {Token}", guildId, session, token); - _udpEp = new IPEndPoint(IPAddress.Parse(ready.Ip), ready.Port); + _udpEp = new(IPAddress.Parse(ready.Ip), ready.Port); var ssrcBytes = BitConverter.GetBytes(Ssrc); var ipDiscoveryData = new byte[70]; @@ -265,7 +265,7 @@ namespace Ayu.Discord.Voice private Task HandleHelloAsync(VoiceHello data) { _receivedAck = true; - _heartbeatTimer = new Timer(async _ => + _heartbeatTimer = new(async _ => { await SendHeartbeatAsync(); }, default, data.HeartbeatInterval, data.HeartbeatInterval); @@ -279,7 +279,7 @@ namespace Ayu.Discord.Voice } private Task IdentifyAsync() - => SendCommandPayloadAsync(new VoicePayload + => SendCommandPayloadAsync(new() { OpCode = VoiceOpCode.Identify, Data = JToken.FromObject(new VoiceIdentify @@ -292,13 +292,13 @@ namespace Ayu.Discord.Voice }); private Task SelectProtocol() - => SendCommandPayloadAsync(new VoicePayload + => SendCommandPayloadAsync(new() { OpCode = VoiceOpCode.SelectProtocol, Data = JToken.FromObject(new SelectProtocol { Protocol = "udp", - Data = new SelectProtocol.ProtocolData() + Data = new() { Address = MyIp, Port = MyPort, @@ -319,7 +319,7 @@ namespace Ayu.Discord.Voice } _receivedAck = false; - await SendCommandPayloadAsync(new VoicePayload + await SendCommandPayloadAsync(new() { OpCode = VoiceOpCode.Heartbeat, Data = JToken.FromObject(_rng.Next()) @@ -327,7 +327,7 @@ namespace Ayu.Discord.Voice } public Task SendSpeakingAsync(VoiceSpeaking.State speaking) - => SendCommandPayloadAsync(new VoicePayload + => SendCommandPayloadAsync(new() { OpCode = VoiceOpCode.Speaking, Data = JToken.FromObject(new VoiceSpeaking