From da2ee0c1584490a795bc14740df64e417c35b0c6 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Mon, 20 Dec 2021 03:02:02 +0100 Subject: [PATCH] await usings and minor cleanup --- src/NadekoBot/Bot.cs | 2 +- .../Common/Replacements/ReplacementBuilder.cs | 2 +- .../SelfAssignedRolesCommands.cs | 10 +++++----- .../Services/AdministrationService.cs | 2 +- .../Services/AutoAssignRoleService.cs | 6 +++--- .../Services/DangerousCommandsService.cs | 4 ++-- .../Services/DiscordPermOverrideService.cs | 8 ++++---- .../Services/LogCommandService.cs | 2 +- .../Administration/Services/MuteService.cs | 12 ++++++------ .../Services/PlayingRotateService.cs | 6 +++--- .../Services/ProtectionService.cs | 12 ++++++------ .../Services/SelfAssignedRolesService.cs | 4 ++-- .../Administration/Services/SelfService.cs | 4 ++-- .../Services/UserPunishService.cs | 10 +++++----- .../Administration/Services/VcRoleService.cs | 2 +- .../Services/CustomReactionsService.cs | 18 +++++++++--------- .../Modules/Gambling/DiceRollCommands.cs | 4 ++-- src/NadekoBot/Modules/Gambling/DrawCommands.cs | 4 ++-- .../Modules/Gambling/FlipCoinCommands.cs | 2 +- src/NadekoBot/Modules/Gambling/Gambling.cs | 6 +++--- .../Gambling/Services/Impl/ShopService.cs | 8 ++++---- .../Gambling/Services/PlantPickService.cs | 8 ++++---- .../Modules/Gambling/Services/WaifuService.cs | 14 +++++++------- src/NadekoBot/Modules/Gambling/ShopCommands.cs | 14 +++++++------- src/NadekoBot/Modules/Gambling/SlotCommands.cs | 4 ++-- .../Modules/Games/CleverBotCommands.cs | 4 ++-- .../Modules/Games/Common/PollRunner.cs | 3 ++- src/NadekoBot/Modules/Games/Games.cs | 2 +- src/NadekoBot/Modules/Help/Help.cs | 4 ++-- .../Modules/Music/PlaylistCommands.cs | 10 +++++----- .../Modules/Music/Services/MusicService.cs | 8 ++++---- .../Modules/Permissions/CmdCdsCommands.cs | 2 +- .../Modules/Permissions/FilterCommands.cs | 14 +++++++------- .../Modules/Permissions/Permissions.cs | 10 +++++----- .../Permissions/Services/PermissionsService.cs | 4 ++-- src/NadekoBot/Modules/Searches/Searches.cs | 5 +++-- .../Modules/Searches/Services/FeedsService.cs | 1 - .../Services/StreamNotificationService.cs | 6 +++--- .../Searches/StreamNotificationCommands.cs | 2 +- .../Modules/Utility/CommandMapCommands.cs | 2 +- src/NadekoBot/Modules/Utility/QuoteCommands.cs | 18 +++++++++--------- .../Modules/Utility/RemindCommands.cs | 6 +++--- .../Utility/Services/PatreonRewardsService.cs | 2 +- .../Modules/Utility/Services/RemindService.cs | 2 +- .../Utility/Services/RepeaterService.cs | 16 ++++++++-------- .../Utility/Services/StreamRoleService.cs | 8 ++++---- src/NadekoBot/Modules/Utility/Utility.cs | 2 +- .../Modules/Xp/Services/ClubService.cs | 2 +- src/NadekoBot/Modules/Xp/Services/XpService.cs | 14 +++++++------- src/NadekoBot/Modules/Xp/Xp.cs | 2 +- src/NadekoBot/NadekoBot.csproj | 1 + src/NadekoBot/Services/GreetSettingsService.cs | 18 +++++++++--------- src/NadekoBot/Services/Impl/CurrencyService.cs | 8 ++++---- src/NadekoBot/Services/Impl/StatsService.cs | 4 ++-- src/NadekoBot/_Extensions/IUserExtensions.cs | 2 +- 55 files changed, 176 insertions(+), 174 deletions(-) diff --git a/src/NadekoBot/Bot.cs b/src/NadekoBot/Bot.cs index 2c9258515..0f0e9df03 100644 --- a/src/NadekoBot/Bot.cs +++ b/src/NadekoBot/Bot.cs @@ -279,7 +279,7 @@ public sealed class Bot var _ = Task.Run(async () => { GuildConfig gc; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { gc = uow.GuildConfigsForId(arg.Id); } diff --git a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs index 6b99d5e3f..a012e4354 100644 --- a/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs +++ b/src/NadekoBot/Common/Replacements/ReplacementBuilder.cs @@ -155,7 +155,7 @@ public class ReplacementBuilder _reps.TryAdd("%users%", () => c.Guilds.Sum(g => g.MemberCount).ToString()); /*NEW*/ - _reps.TryAdd("%shard.servercount%", () => c.Guilds.Count.ToString());S + _reps.TryAdd("%shard.servercount%", () => c.Guilds.Count.ToString()); _reps.TryAdd("%shard.usercount%", () => c.Guilds.Sum(g => g.MemberCount).ToString()); _reps.TryAdd("%shard.id%", () => c.ShardId.ToString()); return this; diff --git a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs index fc50219b7..5e9f6afb7 100644 --- a/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfAssignedRolesCommands.cs @@ -135,19 +135,19 @@ public partial class Administration } rolesStr.AppendLine("\t\t\t\t ⟪" + groupNameText + "⟫"); - foreach (var (Model, Role) in kvp.AsEnumerable()) + foreach (var (model, role) in kvp.AsEnumerable()) { - if (Role is null) + if (role is null) { continue; } else { // first character is invisible space - if (Model.LevelRequirement == 0) - rolesStr.AppendLine("‌‌ " + Role.Name); + if (model.LevelRequirement == 0) + rolesStr.AppendLine("‌‌ " + role.Name); else - rolesStr.AppendLine("‌‌ " + Role.Name + $" (lvl {Model.LevelRequirement}+)"); + rolesStr.AppendLine("‌‌ " + role.Name + $" (lvl {model.LevelRequirement}+)"); } } rolesStr.AppendLine(); diff --git a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs index 37e865906..66ca169aa 100644 --- a/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AdministrationService.cs @@ -90,7 +90,7 @@ public class AdministrationService : INService public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State newState) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set.Include(x => x.DelMsgOnCmdChannels)); diff --git a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs index 1e26169fa..dc11313a2 100644 --- a/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/AutoAssignRoleService.cs @@ -103,7 +103,7 @@ public sealed class AutoAssignRoleService : INService public async Task> ToggleAarAsync(ulong guildId, ulong roleId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var gc = uow.GuildConfigsForId(guildId, set => set); var roles = gc.GetAutoAssignableRoles(); if(!roles.Remove(roleId) && roles.Count < 3) @@ -122,7 +122,7 @@ public sealed class AutoAssignRoleService : INService public async Task DisableAarAsync(ulong guildId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); await uow .GuildConfigs @@ -137,7 +137,7 @@ public sealed class AutoAssignRoleService : INService public async Task SetAarRolesAsync(ulong guildId, IEnumerable newRoles) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var gc = uow.GuildConfigsForId(guildId, set => set); gc.SetAutoAssignableRoles(newRoles); diff --git a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs index 32a779a78..54c4f1900 100644 --- a/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DangerousCommandsService.cs @@ -42,7 +42,7 @@ DELETE FROM Clubs;"; public async Task ExecuteSql(string sql) { int res; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { res = await uow.Database.ExecuteSqlRawAsync(sql); } @@ -92,7 +92,7 @@ DELETE FROM Clubs;"; public async Task PurgeUserAsync(ulong userId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); // get waifu info var wi = await uow.Set() diff --git a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs index bfad42970..2584c837d 100644 --- a/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs +++ b/src/NadekoBot/Modules/Administration/Services/DiscordPermOverrideService.cs @@ -54,7 +54,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker public async Task AddOverride(ulong guildId, string commandName, GuildPerm perm) { commandName = commandName.ToLowerInvariant(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var over = await uow .Set() @@ -84,7 +84,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker public async Task ClearAllOverrides(ulong guildId) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var overrides = await uow .Set() @@ -106,8 +106,8 @@ public class DiscordPermOverrideService : INService, ILateBlocker public async Task RemoveOverride(ulong guildId, string commandName) { commandName = commandName.ToLowerInvariant(); - - using (var uow = _db.GetDbContext()) + + await using (var uow = _db.GetDbContext()) { var over = await uow .Set() diff --git a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs index b74bffb1f..58374222a 100644 --- a/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs +++ b/src/NadekoBot/Modules/Administration/Services/LogCommandService.cs @@ -206,7 +206,7 @@ public sealed class LogCommandService : ILogCommandService public async Task LogServer(ulong guildId, ulong channelId, bool value) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var logSetting = uow.LogSettingsFor(guildId); diff --git a/src/NadekoBot/Modules/Administration/Services/MuteService.cs b/src/NadekoBot/Modules/Administration/Services/MuteService.cs index 5b8d9dbd4..16b3abf5c 100644 --- a/src/NadekoBot/Modules/Administration/Services/MuteService.cs +++ b/src/NadekoBot/Modules/Administration/Services/MuteService.cs @@ -171,7 +171,7 @@ public class MuteService : INService public async Task SetMuteRoleAsync(ulong guildId, string name) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(guildId, set => set); config.MuteRoleName = name; @@ -189,7 +189,7 @@ public class MuteService : INService if (!usr.RoleIds.Contains(muteRole.Id)) await usr.AddRoleAsync(muteRole).ConfigureAwait(false); StopTimer(usr.GuildId, usr.Id, TimerType.Mute); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(usr.Guild.Id, set => set.Include(gc => gc.MutedUsers) @@ -229,7 +229,7 @@ public class MuteService : INService if (type == MuteType.All) { StopTimer(guildId, usrId, TimerType.Mute); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers) .Include(gc => gc.UnmuteTimers)); @@ -324,7 +324,7 @@ public class MuteService : INService public async Task TimedMute(IGuildUser user, IUser mod, TimeSpan after, MuteType muteType = MuteType.All, string reason = "") { await MuteUser(user, mod, muteType, reason).ConfigureAwait(false); // mute the user. This will also remove any previous unmute timers - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers)); config.UnmuteTimers.Add(new() @@ -341,7 +341,7 @@ public class MuteService : INService public async Task TimedBan(IGuild guild, IUser user, TimeSpan after, string reason) { await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer)); config.UnbanTimer.Add(new() @@ -358,7 +358,7 @@ public class MuteService : INService public async Task TimedRole(IGuildUser user, TimeSpan after, string reason, IRole role) { await user.AddRoleAsync(role).ConfigureAwait(false); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer)); config.UnroleTimer.Add(new() diff --git a/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs b/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs index 9ea476a52..65946c733 100644 --- a/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs +++ b/src/NadekoBot/Modules/Administration/Services/PlayingRotateService.cs @@ -52,7 +52,7 @@ public sealed class PlayingRotateService : INService if (!_bss.Data.RotateStatuses) return; IReadOnlyList rotatingStatuses; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { rotatingStatuses = uow.RotatingStatus .AsNoTracking() @@ -81,7 +81,7 @@ public sealed class PlayingRotateService : INService if (index < 0) throw new ArgumentOutOfRangeException(nameof(index)); - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var toRemove = await uow.RotatingStatus .AsQueryable() .AsNoTracking() @@ -98,7 +98,7 @@ public sealed class PlayingRotateService : INService public async Task AddPlaying(ActivityType t, string status) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var toAdd = new RotatingPlayingStatus {Status = status, Type = t}; uow.Add(toAdd); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs index 41af52a71..3c3aa8262 100644 --- a/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs +++ b/src/NadekoBot/Modules/Administration/Services/ProtectionService.cs @@ -299,7 +299,7 @@ public class ProtectionService : INService _antiRaidGuilds.AddOrUpdate(guildId, stats, (key, old) => stats); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting)); @@ -370,7 +370,7 @@ public class ProtectionService : INService return stats; }); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)); @@ -397,7 +397,7 @@ public class ProtectionService : INService ChannelId = channelId }; bool added; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels)); var spam = gc.AntiSpamSetting; @@ -455,7 +455,7 @@ public class ProtectionService : INService public async Task StartAntiAltAsync(ulong guildId, int minAgeMinutes, PunishmentAction action, int actionDurationMinutes = 0, ulong? roleId = null) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); gc.AntiAltSetting = new() { @@ -473,8 +473,8 @@ public class ProtectionService : INService { if (!_antiAltGuilds.TryRemove(guildId, out _)) return false; - - using var uow = _db.GetDbContext(); + + await using var uow = _db.GetDbContext(); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); gc.AntiAltSetting = null; await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs index 31c37d077..0cae7b0ec 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfAssignedRolesService.cs @@ -70,7 +70,7 @@ public class SelfAssignedRolesService : INService public async Task<(AssignResult Result, bool AutoDelete, object extra)> Assign(IGuildUser guildUser, IRole role) { LevelStats userLevelData; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id); userLevelData = new(stats.Xp + stats.AwardedXp); @@ -132,7 +132,7 @@ public class SelfAssignedRolesService : INService public async Task SetNameAsync(ulong guildId, int group, string name) { var set = false; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames)); var toUpdate = gc.SelfAssignableRoleGroupNames.FirstOrDefault(x => x.Number == group); diff --git a/src/NadekoBot/Modules/Administration/Services/SelfService.cs b/src/NadekoBot/Modules/Administration/Services/SelfService.cs index ff391ac5a..bdf91015d 100644 --- a/src/NadekoBot/Modules/Administration/Services/SelfService.cs +++ b/src/NadekoBot/Modules/Administration/Services/SelfService.cs @@ -101,7 +101,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService public async Task OnReadyAsync() { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); _autoCommands = uow .AutoCommands @@ -344,7 +344,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService // i can't just do ReadAsStreamAsync because dicord.net's image poops itself var imgData = await sr.Content.ReadAsByteArrayAsync().ConfigureAwait(false); - using (var imgStream = imgData.ToStream()) + await using (var imgStream = imgData.ToStream()) { await _client.CurrentUser.ModifyAsync(u => u.Avatar = new Image(imgStream)).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs index 898de4c3a..0841178b7 100644 --- a/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs +++ b/src/NadekoBot/Modules/Administration/Services/UserPunishService.cs @@ -60,7 +60,7 @@ public class UserPunishService : INService var warnings = 1; List ps; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)) .WarnPunishments; @@ -206,7 +206,7 @@ public class UserPunishService : INService public async Task CheckAllWarnExpiresAsync() { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var cleared = await uow.Database.ExecuteSqlRawAsync($@"UPDATE Warnings SET Forgiven = 1, @@ -228,7 +228,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND public async Task CheckWarnExpiresAsync(ulong guildId) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(guildId, inc => inc); @@ -265,7 +265,7 @@ WHERE GuildId={guildId} public async Task WarnExpireAsync(ulong guildId, int days, bool delete) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(guildId, inc => inc); @@ -300,7 +300,7 @@ WHERE GuildId={guildId} public async Task WarnClearAsync(ulong guildId, ulong userId, int index, string moderator) { var toReturn = true; - using (var uow = _db.GetDbContext()) + await 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 36964bfd6..f1a181877 100644 --- a/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs +++ b/src/NadekoBot/Modules/Administration/Services/VcRoleService.cs @@ -122,7 +122,7 @@ public class VcRoleService : INService if (missingRoles.Any()) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}"); uow.RemoveRange(missingRoles); diff --git a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs index 21a7d98bc..8b26f6db8 100644 --- a/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs +++ b/src/NadekoBot/Modules/CustomReactions/Services/CustomReactionsService.cs @@ -85,7 +85,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor private async Task ReloadInternal(IReadOnlyList allGuildIds) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var guildItems = await uow.CustomReactions .AsNoTracking() .Where(x => allGuildIds.Contains(x.GuildId.Value)) @@ -190,7 +190,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor private async Task OnJoinedGuild(GuildConfig gc) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var crs = await uow .CustomReactions .AsNoTracking() @@ -217,7 +217,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor if (cr.Response.Contains("%target%", StringComparison.OrdinalIgnoreCase)) cr.AllowTarget = true; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.CustomReactions.Add(cr); await uow.SaveChangesAsync(); @@ -230,7 +230,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor public async Task EditAsync(ulong? guildId, int id, string message) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var cr = uow.CustomReactions.GetById(id); if (cr is null || cr.GuildId != guildId) @@ -258,7 +258,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor public async Task DeleteAsync(ulong? guildId, int id) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var toDelete = uow.CustomReactions.GetById(id); if (toDelete is null) @@ -477,7 +477,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor public async Task ResetCrReactions(ulong? maybeGuildId, int id) { CustomReaction cr; - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); cr = uow.CustomReactions.GetById(id); if (cr is null) return; @@ -594,7 +594,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor public async Task SetCrReactions(ulong? guildId, int id, IEnumerable emojis) { CustomReaction cr; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { cr = uow.CustomReactions.GetById(id); if (cr is null) @@ -612,7 +612,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor { var newVal = false; CustomReaction cr; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { cr = uow.CustomReactions.GetById(id); if (cr is null) @@ -711,7 +711,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor return false; } - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); foreach (var entry in data) { var trigger = entry.Key; diff --git a/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs b/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs index c0a4bf573..b93f56fac 100644 --- a/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DiceRollCommands.cs @@ -40,7 +40,7 @@ public partial class Gambling using (var img1 = GetDice(num1)) using (var img2 = GetDice(num2)) using (var img = new[] { img1, img2 }.Merge(out var format)) - using (var ms = img.ToStream(format)) + await using (var ms = img.ToStream(format)) { await ctx.Channel.SendFileAsync(ms, $"dice.{format.FileExtensions.First()}", @@ -116,7 +116,7 @@ public partial class Gambling } using (var bitmap = dice.Merge(out var format)) - using (var ms = bitmap.ToStream(format)) + await using (var ms = bitmap.ToStream(format)) { foreach (var d in dice) { diff --git a/src/NadekoBot/Modules/Gambling/DrawCommands.cs b/src/NadekoBot/Modules/Gambling/DrawCommands.cs index c79cccc10..9e5a6977b 100644 --- a/src/NadekoBot/Modules/Gambling/DrawCommands.cs +++ b/src/NadekoBot/Modules/Gambling/DrawCommands.cs @@ -80,7 +80,7 @@ public partial class Gambling num = 10; var (ImageStream, ToSend) = await InternalDraw(num, ctx.Guild.Id).ConfigureAwait(false); - using (ImageStream) + await using (ImageStream) { await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false); } @@ -95,7 +95,7 @@ public partial class Gambling num = 10; var (ImageStream, ToSend) = await InternalDraw(num).ConfigureAwait(false); - using (ImageStream) + await using (ImageStream) { await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs b/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs index e78c46ada..97eeafd17 100644 --- a/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs +++ b/src/NadekoBot/Modules/Gambling/FlipCoinCommands.cs @@ -55,7 +55,7 @@ public partial class Gambling } } using (var img = imgs.Merge(out var format)) - using (var stream = img.ToStream(format)) + await using (var stream = img.ToStream(format)) { foreach (var i in imgs) { diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index b8aca01eb..6d06eb99d 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -187,7 +187,7 @@ public partial class Gambling : GamblingModule return; var trs = new List(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { trs = uow.CurrencyTransactions.GetPageFor(userId, page); } @@ -528,7 +528,7 @@ public partial class Gambling : GamblingModule { var now = DateTime.UtcNow; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000); } @@ -542,7 +542,7 @@ public partial class Gambling : GamblingModule } else { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); } diff --git a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs index da2c0113d..db8717640 100644 --- a/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/Impl/ShopService.cs @@ -33,7 +33,7 @@ public class ShopService : IShopService, INService if (newPrice <= 0) throw new ArgumentOutOfRangeException(nameof(newPrice)); - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var entries = GetEntriesInternal(uow, guildId); if (index >= entries.Count) @@ -51,7 +51,7 @@ public class ShopService : IShopService, INService if (string.IsNullOrWhiteSpace(newName)) throw new ArgumentNullException(nameof(newName)); - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var entries = GetEntriesInternal(uow, guildId); if (index >= entries.Count) @@ -69,7 +69,7 @@ public class ShopService : IShopService, INService if (index2 < 0) throw new ArgumentOutOfRangeException(nameof(index2)); - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var entries = GetEntriesInternal(uow, guildId); if (index1 >= entries.Count || index2 >= entries.Count || index1 == index2) @@ -89,7 +89,7 @@ public class ShopService : IShopService, INService if (toIndex < 0) throw new ArgumentOutOfRangeException(nameof(toIndex)); - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var entries = GetEntriesInternal(uow, guildId); if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex) diff --git a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs index 9c048e6b2..41c1bb92f 100644 --- a/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/PlantPickService.cs @@ -219,7 +219,7 @@ public class PlantPickService : INService var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null; IUserMessage sent; - using (var stream = GetRandomCurrencyImage(pw, out var ext)) + await using (var stream = GetRandomCurrencyImage(pw, out var ext)) { sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend).ConfigureAwait(false); } @@ -259,7 +259,7 @@ public class PlantPickService : INService { long amount; ulong[] ids; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { // this method will sum all plants with that password, // remove them, and get messageids of the removed plants @@ -318,7 +318,7 @@ public class PlantPickService : INService msgToSend += " " + GetText(gid, strs.pick_sn(prefix)); //get the image - using (var stream = GetRandomCurrencyImage(pass, out var ext)) + await using (var stream = GetRandomCurrencyImage(pass, out var ext)) { // send it var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false); @@ -362,7 +362,7 @@ public class PlantPickService : INService private async Task AddPlantToDatabase(ulong gid, ulong cid, ulong uid, ulong mid, long amount, string pass) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.PlantedCurrency.Add(new() { diff --git a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs index 178a967d7..4b9ceaa44 100644 --- a/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs +++ b/src/NadekoBot/Modules/Gambling/Services/WaifuService.cs @@ -39,8 +39,8 @@ public class WaifuService : INService return false; var settings = _gss.Data; - - using (var uow = _db.GetDbContext()) + + await using (var uow = _db.GetDbContext()) { var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId); var ownerUser = uow.GetOrCreateUser(owner); @@ -116,7 +116,7 @@ public class WaifuService : INService public async Task TryReset(IUser user) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var price = GetResetPrice(user); if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true)) @@ -161,7 +161,7 @@ public class WaifuService : INService WaifuClaimResult result; WaifuInfo w; bool isAffinity; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { w = uow.WaifuInfo.ByWaifuUserId(target.Id); isAffinity = (w?.Affinity?.UserId == user.Id); @@ -251,7 +251,7 @@ public class WaifuService : INService DiscordUser oldAff = null; var success = false; TimeSpan? remaining = null; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var w = uow.WaifuInfo.ByWaifuUserId(user.Id); var newAff = target is null ? null : uow.GetOrCreateUser(target); @@ -323,7 +323,7 @@ public class WaifuService : INService TimeSpan? remaining = null; long amount = 0; WaifuInfo w = null; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { w = uow.WaifuInfo.ByWaifuUserId(targetId); var now = DateTime.UtcNow; @@ -375,7 +375,7 @@ public class WaifuService : INService return false; } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id, set => set.Include(x => x.Items) diff --git a/src/NadekoBot/Modules/Gambling/ShopCommands.cs b/src/NadekoBot/Modules/Gambling/ShopCommands.cs index 2321c1aac..17c335a2a 100644 --- a/src/NadekoBot/Modules/Gambling/ShopCommands.cs +++ b/src/NadekoBot/Modules/Gambling/ShopCommands.cs @@ -89,7 +89,7 @@ public partial class Gambling if (index < 0) return; ShopEntry entry; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set .Include(x => x.ShopEntries) @@ -159,7 +159,7 @@ public partial class Gambling if (await _cs.RemoveAsync(ctx.User.Id, $"Shop purchase - {entry.Type}", entry.Price).ConfigureAwait(false)) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var x = uow.Set().Remove(item); uow.SaveChanges(); @@ -183,7 +183,7 @@ public partial class Gambling await _cs.AddAsync(ctx.User.Id, $"Shop error refund - {entry.Name}", entry.Price).ConfigureAwait(false); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) @@ -232,7 +232,7 @@ public partial class Gambling RoleId = role.Id, RoleName = role.Name }; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) @@ -263,7 +263,7 @@ public partial class Gambling AuthorId = ctx.User.Id, Items = new(), }; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) @@ -294,7 +294,7 @@ public partial class Gambling ShopEntry entry; var rightType = false; var added = false; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var entries = new IndexedCollection(uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.ShopEntries) @@ -327,7 +327,7 @@ public partial class Gambling if (index < 0) return; ShopEntry removed; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set .Include(x => x.ShopEntries) diff --git a/src/NadekoBot/Modules/Gambling/SlotCommands.cs b/src/NadekoBot/Modules/Gambling/SlotCommands.cs index faca0c92e..a85fc7557 100644 --- a/src/NadekoBot/Modules/Gambling/SlotCommands.cs +++ b/src/NadekoBot/Modules/Gambling/SlotCommands.cs @@ -172,7 +172,7 @@ public partial class Gambling Interlocked.Add(ref _totalPaidOut, result.Won); long ownedAmount; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { ownedAmount = uow.Set() .FirstOrDefault(x => x.UserId == ctx.User.Id) @@ -243,7 +243,7 @@ public partial class Gambling msg = GetText(strs.slot_jackpot(30)); } - using (var imgStream = bgImage.ToStream()) + await using (var imgStream = bgImage.ToStream()) { await ctx.Channel.SendFileAsync(imgStream, filename: "result.png", diff --git a/src/NadekoBot/Modules/Games/CleverBotCommands.cs b/src/NadekoBot/Modules/Games/CleverBotCommands.cs index 5a9f9d25c..285898dbd 100644 --- a/src/NadekoBot/Modules/Games/CleverBotCommands.cs +++ b/src/NadekoBot/Modules/Games/CleverBotCommands.cs @@ -32,7 +32,7 @@ public partial class Games if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out _)) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false); await uow.SaveChangesAsync(); @@ -43,7 +43,7 @@ public partial class Games _service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new(() => _service.CreateSession(), true)); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Games/Common/PollRunner.cs b/src/NadekoBot/Modules/Games/Common/PollRunner.cs index ca98d857e..35d6ca176 100644 --- a/src/NadekoBot/Modules/Games/Common/PollRunner.cs +++ b/src/NadekoBot/Modules/Games/Common/PollRunner.cs @@ -54,7 +54,8 @@ public class PollRunner var _ = OnVoted?.Invoke(msg, usr); } finally { _locker.Release(); } - using (var uow = _db.GetDbContext()) + + await using (var uow = _db.GetDbContext()) { var trackedPoll = uow.Poll.FirstOrDefault(x => x.Id == Poll.Id); trackedPoll.Votes.Add(voteObj); diff --git a/src/NadekoBot/Modules/Games/Games.cs b/src/NadekoBot/Modules/Games/Games.cs index 9e3587538..2aeb7e06b 100644 --- a/src/NadekoBot/Modules/Games/Games.cs +++ b/src/NadekoBot/Modules/Games/Games.cs @@ -66,7 +66,7 @@ public partial class Games : NadekoModule return; } - using (var imgStream = new MemoryStream()) + await using (var imgStream = new MemoryStream()) { lock (gr) { diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 7e99ea81d..e69cc41fd 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -379,7 +379,7 @@ public class Help : NadekoModule }); } - using var ms = new MemoryStream(); + await using var ms = new MemoryStream(); await oldVersionObject.ResponseStream.CopyToAsync(ms); var versionListString = Encoding.UTF8.GetString(ms.ToArray()); @@ -415,7 +415,7 @@ public class Help : NadekoModule } // also send the file, but indented one, to chat - using var rDataStream = new MemoryStream(Encoding.ASCII.GetBytes(readableData)); + await using var rDataStream = new MemoryStream(Encoding.ASCII.GetBytes(readableData)); await ctx.Channel.SendFileAsync(rDataStream, "cmds.json", GetText(strs.commandlist_regen)).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Music/PlaylistCommands.cs b/src/NadekoBot/Modules/Music/PlaylistCommands.cs index a348b1310..40a29e64f 100644 --- a/src/NadekoBot/Modules/Music/PlaylistCommands.cs +++ b/src/NadekoBot/Modules/Music/PlaylistCommands.cs @@ -49,7 +49,7 @@ public sealed partial class Music List playlists; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); } @@ -71,7 +71,7 @@ public sealed partial class Music var success = false; try { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id); @@ -105,7 +105,7 @@ public sealed partial class Music return; MusicPlaylist mpl; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { mpl = uow.MusicPlaylists.GetWithSongs(id); } @@ -144,7 +144,7 @@ public sealed partial class Music }).ToList(); MusicPlaylist playlist; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { playlist = new() { @@ -203,7 +203,7 @@ public sealed partial class Music } MusicPlaylist mpl; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { mpl = uow.MusicPlaylists.GetWithSongs(id); } diff --git a/src/NadekoBot/Modules/Music/Services/MusicService.cs b/src/NadekoBot/Modules/Music/Services/MusicService.cs index 9287516ad..b20181bec 100644 --- a/src/NadekoBot/Modules/Music/Services/MusicService.cs +++ b/src/NadekoBot/Modules/Music/Services/MusicService.cs @@ -345,8 +345,8 @@ public sealed class MusicService : IMusicService { if (_settings.TryGetValue(guildId, out var settings)) return settings; - - using var uow = _db.GetDbContext(); + + await using var uow = _db.GetDbContext(); var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId); await uow.SaveChangesAsync(); @@ -358,7 +358,7 @@ public sealed class MusicService : IMusicService Action action, TState state) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId); action(ms, state); await uow.SaveChangesAsync(); @@ -438,7 +438,7 @@ public sealed class MusicService : IMusicService public async Task GetMusicQualityAsync(ulong guildId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId); return settings.QualityPreset; } diff --git a/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs b/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs index 29d9ea015..55cbfd763 100644 --- a/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs +++ b/src/NadekoBot/Modules/Permissions/CmdCdsCommands.cs @@ -45,7 +45,7 @@ public partial class Permissions } var name = command.Name.ToLowerInvariant(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns)); var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet()); diff --git a/src/NadekoBot/Modules/Permissions/FilterCommands.cs b/src/NadekoBot/Modules/Permissions/FilterCommands.cs index bf0300fc3..2e4a42d72 100644 --- a/src/NadekoBot/Modules/Permissions/FilterCommands.cs +++ b/src/NadekoBot/Modules/Permissions/FilterCommands.cs @@ -40,7 +40,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterInvites = !config.FilterInvites; @@ -66,7 +66,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; FilterChannelId removed; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds)); var match = new FilterChannelId() @@ -105,7 +105,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterLinks = !config.FilterLinks; @@ -131,7 +131,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; FilterLinksChannelId removed; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds)); var match = new FilterLinksChannelId() @@ -170,7 +170,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); enabled = config.FilterWords = !config.FilterWords; @@ -196,7 +196,7 @@ public partial class Permissions var channel = (ITextChannel)ctx.Channel; FilterChannelId removed; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds)); @@ -240,7 +240,7 @@ public partial class Permissions return; FilteredWord removed; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords)); diff --git a/src/NadekoBot/Modules/Permissions/Permissions.cs b/src/NadekoBot/Modules/Permissions/Permissions.cs index a07006138..1cf3a4665 100644 --- a/src/NadekoBot/Modules/Permissions/Permissions.cs +++ b/src/NadekoBot/Modules/Permissions/Permissions.cs @@ -26,7 +26,7 @@ public partial class Permissions : NadekoModule [RequireContext(ContextType.Guild)] public async Task Verbose(PermissionAction action = null) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle. @@ -68,7 +68,7 @@ public partial class Permissions : NadekoModule return; } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); config.PermissionRole = role.Id.ToString(); @@ -87,7 +87,7 @@ public partial class Permissions : NadekoModule [Priority(1)] public async Task PermRole(Reset _) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); config.PermissionRole = null; @@ -143,7 +143,7 @@ public partial class Permissions : NadekoModule try { Permissionv2 p; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var permsCol = new PermissionsCollection(config.Permissions); @@ -175,7 +175,7 @@ public partial class Permissions : NadekoModule try { Permissionv2 fromPerm; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var permsCol = new PermissionsCollection(config.Permissions); diff --git a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs index 5d90c583e..faee98ccc 100644 --- a/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs +++ b/src/NadekoBot/Modules/Permissions/Services/PermissionsService.cs @@ -71,7 +71,7 @@ public class PermissionService : ILateBlocker, INService public async Task AddPermissions(ulong guildId, params Permissionv2[] perms) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(guildId); //var orderedPerms = new PermissionsCollection(config.Permissions); @@ -178,7 +178,7 @@ public class PermissionService : ILateBlocker, INService public async Task Reset(ulong guildId) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GcWithPermissionsv2For(guildId); config.Permissions = Permissionv2.GetDefaultPermlist; diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 12c7c269e..2dc9a94bf 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -48,7 +48,7 @@ public partial class Searches : NadekoModule var av = usr.RealAvatarUrl(128); if (av is null) return; - using (var picStream = await _service.GetRipPictureAsync(usr.Nickname ?? usr.Username, av).ConfigureAwait(false)) + await using (var picStream = await _service.GetRipPictureAsync(usr.Nickname ?? usr.Username, av).ConfigureAwait(false)) { await ctx.Channel.SendFileAsync( picStream, @@ -626,7 +626,8 @@ public partial class Searches : NadekoModule new PointF(x, 50) })); } - using (var ms = img.ToStream()) + + await using (var ms = img.ToStream()) { await ctx.Channel.SendFileAsync(ms, $"colors.png").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs index c8dfe044d..9c65c8c5e 100644 --- a/src/NadekoBot/Modules/Searches/Services/FeedsService.cs +++ b/src/NadekoBot/Modules/Searches/Services/FeedsService.cs @@ -32,7 +32,6 @@ public class FeedsService : INService .AsQueryable() .Where(x => guildConfigIds.Contains(x.Id)) .Include(x => x.FeedSubs) - .ThenInclude(x => x.GuildConfig) .ToList() .SelectMany(x => x.FeedSubs) .GroupBy(x => x.Url.ToLower()) diff --git a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs index 9c2dd90fb..527d02bfa 100644 --- a/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs +++ b/src/NadekoBot/Modules/Searches/Services/StreamNotificationService.cs @@ -339,7 +339,7 @@ public sealed class StreamNotificationService : INService public async Task ClearAllStreams(ulong guildId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); uow.RemoveRange(gc.FollowedStreams); @@ -354,7 +354,7 @@ public sealed class StreamNotificationService : INService public async Task UnfollowStreamAsync(ulong guildId, int index) { FollowedStream fs; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var fss = uow.Set() .AsQueryable() @@ -400,7 +400,7 @@ public sealed class StreamNotificationService : INService return null; FollowedStream fs; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); diff --git a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs index ab7786448..09056ce3e 100644 --- a/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs +++ b/src/NadekoBot/Modules/Searches/StreamNotificationCommands.cs @@ -84,7 +84,7 @@ public partial class Searches } var streams = new List(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var all = uow .GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) diff --git a/src/NadekoBot/Modules/Utility/CommandMapCommands.cs b/src/NadekoBot/Modules/Utility/CommandMapCommands.cs index 90fdd8614..e01e6b14e 100644 --- a/src/NadekoBot/Modules/Utility/CommandMapCommands.cs +++ b/src/NadekoBot/Modules/Utility/CommandMapCommands.cs @@ -57,7 +57,7 @@ public partial class Utility return; } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases)); var toAdd = new CommandAlias() diff --git a/src/NadekoBot/Modules/Utility/QuoteCommands.cs b/src/NadekoBot/Modules/Utility/QuoteCommands.cs index 9e39a5a85..6129b7a28 100644 --- a/src/NadekoBot/Modules/Utility/QuoteCommands.cs +++ b/src/NadekoBot/Modules/Utility/QuoteCommands.cs @@ -44,7 +44,7 @@ public partial class Utility return; IEnumerable quotes; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order); } @@ -67,7 +67,7 @@ public partial class Utility keyword = keyword.ToUpperInvariant(); Quote quote; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword); //if (quote != null) @@ -95,7 +95,7 @@ public partial class Utility public async Task QuoteShow(int id) { Quote quote; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { quote = uow.Quotes.GetById(id); if (quote?.GuildId != ctx.Guild.Id) @@ -132,7 +132,7 @@ public partial class Utility keyword = keyword.ToUpperInvariant(); Quote keywordquote; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); } @@ -157,7 +157,7 @@ public partial class Utility .WithDefault(Context) .Build(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { quote = uow.Quotes.GetById(id); } @@ -186,7 +186,7 @@ public partial class Utility keyword = keyword.ToUpperInvariant(); Quote q; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.Quotes.Add(q = new() { @@ -209,7 +209,7 @@ public partial class Utility var success = false; string response; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var q = uow.Quotes.GetById(id); @@ -241,7 +241,7 @@ public partial class Utility keyword = keyword.ToUpperInvariant(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant()); @@ -289,7 +289,7 @@ public partial class Utility public async Task QuotesExport() { IEnumerable quotes; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { quotes = uow.Quotes .GetForGuild(ctx.Guild.Id) diff --git a/src/NadekoBot/Modules/Utility/RemindCommands.cs b/src/NadekoBot/Modules/Utility/RemindCommands.cs index f038cc4ee..f8dc9352b 100644 --- a/src/NadekoBot/Modules/Utility/RemindCommands.cs +++ b/src/NadekoBot/Modules/Utility/RemindCommands.cs @@ -107,7 +107,7 @@ public partial class Utility .WithTitle(GetText(isServer ? strs.reminder_server_list : strs.reminder_list)); List rems; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { if (isServer) { @@ -164,7 +164,7 @@ public partial class Utility return; Reminder rem = null; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var rems = isServer ? uow.Reminders @@ -219,7 +219,7 @@ public partial class Utility ServerId = ctx.Guild?.Id ?? 0 }; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.Reminders.Add(rem); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs index a44a25ef8..4dc0a4de5 100644 --- a/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs +++ b/src/NadekoBot/Modules/Utility/Services/PatreonRewardsService.cs @@ -231,7 +231,7 @@ public class PatreonRewardsService : INService { var eligibleFor = (int)(cents * settings.PatreonCurrencyPerCent); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var users = uow.Set(); var usr = await users.FirstOrDefaultAsyncEF(x => x.PatreonUserId == patreonUserId); diff --git a/src/NadekoBot/Modules/Utility/Services/RemindService.cs b/src/NadekoBot/Modules/Utility/Services/RemindService.cs index 7270f12f5..1a0dfe280 100644 --- a/src/NadekoBot/Modules/Utility/Services/RemindService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RemindService.cs @@ -61,7 +61,7 @@ public class RemindService : INService private async Task RemoveReminders(List reminders) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { uow.Set() .RemoveRange(reminders); diff --git a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs index a4c7690f9..1bb5686a7 100644 --- a/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs +++ b/src/NadekoBot/Modules/Utility/Services/RepeaterService.cs @@ -138,7 +138,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") public async Task TriggerExternal(ulong guildId, int index) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var toTrigger = await uow.Repeaters .AsNoTracking() @@ -290,8 +290,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") private async Task RemoveRepeaterInternal(Repeater r) { _noRedundant.TryRemove(r.Id); - - using var uow = _db.GetDbContext(); + + await using var uow = _db.GetDbContext(); await uow .Repeaters .DeleteAsync(x => x.Id == r.Id); @@ -314,7 +314,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); await uow.Repeaters .AsQueryable() .Where(x => x.Id == repeaterId) @@ -345,7 +345,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") DateAdded = DateTime.UtcNow }; - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); if (await uow.Repeaters.CountAsyncEF(x => x.GuildId == guildId) < MAX_REPEATERS) uow.Repeaters.Add(rep); @@ -365,8 +365,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") { if (index > MAX_REPEATERS * 2) throw new ArgumentOutOfRangeException(nameof(index)); - - using var uow = _db.GetDbContext(); + + await using var uow = _db.GetDbContext(); var toRemove = await uow.Repeaters .AsNoTracking() .Where(x => x.GuildId == guildId) @@ -398,7 +398,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};") public async Task ToggleRedundantAsync(ulong guildId, int index) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var toToggle = await uow .Repeaters .AsQueryable() diff --git a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs index 8f52ab26c..f2001e957 100644 --- a/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs +++ b/src/NadekoBot/Modules/Utility/Services/StreamRoleService.cs @@ -70,7 +70,7 @@ public class StreamRoleService : INService userName.ThrowIfNull(nameof(userName)); var success = false; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); @@ -135,7 +135,7 @@ public class StreamRoleService : INService { keyword = keyword?.Trim()?.ToLowerInvariant(); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); @@ -181,7 +181,7 @@ public class StreamRoleService : INService addRole.ThrowIfNull(nameof(addRole)); StreamRoleSettings setting; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id); @@ -208,7 +208,7 @@ public class StreamRoleService : INService /// Guild's Id public async Task StopStreamRole(IGuild guild, bool cleanup = false) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); streamRoleSettings.Enabled = false; diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index bcf02243b..4788e8644 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -441,7 +441,7 @@ public partial class Utility : NadekoModule return msg; }) }); - using (var stream = await JsonConvert.SerializeObject(grouping, Formatting.Indented).ToStream().ConfigureAwait(false)) + await using (var stream = await JsonConvert.SerializeObject(grouping, Formatting.Indented).ToStream().ConfigureAwait(false)) { await ctx.User.SendFileAsync(stream, title, title, false).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Xp/Services/ClubService.cs b/src/NadekoBot/Modules/Xp/Services/ClubService.cs index 100598410..8d0b54c3e 100644 --- a/src/NadekoBot/Modules/Xp/Services/ClubService.cs +++ b/src/NadekoBot/Modules/Xp/Services/ClubService.cs @@ -115,7 +115,7 @@ public class ClubService : INService } } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var club = uow.Clubs.GetByOwner(ownerUserId); diff --git a/src/NadekoBot/Modules/Xp/Services/XpService.cs b/src/NadekoBot/Modules/Xp/Services/XpService.cs index 415d560c9..2d4109a9e 100644 --- a/src/NadekoBot/Modules/Xp/Services/XpService.cs +++ b/src/NadekoBot/Modules/Xp/Services/XpService.cs @@ -168,7 +168,7 @@ public class XpService : INService var group = toAddTo.GroupBy(x => (GuildId: x.Guild.Id, x.User)); if (toAddTo.Count == 0) continue; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { foreach (var item in group) { @@ -450,7 +450,7 @@ public class XpService : INService public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var user = uow.GetOrCreateUserXpStats(guildId, userId); user.NotifyOnLevelUp = type; @@ -477,7 +477,7 @@ public class XpService : INService public async Task ChangeNotificationType(IUser user, XpNotificationLocation type) { - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var du = uow.GetOrCreateUser(user); du.NotifyOnLevelUp = type; @@ -724,7 +724,7 @@ public class XpService : INService int totalXp; int globalRank; int guildRank; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { du = uow.GetOrCreateUser(user); totalXp = du.TotalXp; @@ -1044,7 +1044,7 @@ public class XpService : INService .Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y) .ApplyRoundedCorners( Math.Max(_template.User.Icon.Size.X, _template.User.Icon.Size.Y) / 2)); - using (var stream = tempDraw.ToStream()) + await using (var stream = tempDraw.ToStream()) { data = stream.ToArray(); } @@ -1157,7 +1157,7 @@ public class XpService : INService .ApplyRoundedCorners( Math.Max(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y) / 2.0f)); ; - using (var tds = tempDraw.ToStream()) + await using (var tds = tempDraw.ToStream()) { data = tds.ToArray(); } @@ -1207,7 +1207,7 @@ public class XpService : INService public async Task ResetXpRewards(ulong guildId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var guildConfig = uow.GuildConfigsForId(guildId, set => set .Include(x => x.XpSettings) diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index af104bc78..36d0de8c0 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -29,7 +29,7 @@ public partial class Xp : NadekoModule user = user ?? ctx.User; await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); var (img, fmt) = await _service.GenerateXpImageAsync((IGuildUser)user).ConfigureAwait(false); - using (img) + await using (img) { await ctx.Channel.SendFileAsync(img, $"{ctx.Guild.Id}_{user.Id}_xp.{fmt.FileExtensions.FirstOrDefault()}") .ConfigureAwait(false); diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 8bcf5ca87..a6dca48e3 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -4,6 +4,7 @@ net6.0 10.0 True + true $(MSBuildProjectDirectory) exe nadeko_icon.ico diff --git a/src/NadekoBot/Services/GreetSettingsService.cs b/src/NadekoBot/Services/GreetSettingsService.cs index 455e906b3..e515ad294 100644 --- a/src/NadekoBot/Services/GreetSettingsService.cs +++ b/src/NadekoBot/Services/GreetSettingsService.cs @@ -345,7 +345,7 @@ public class GreetSettingsService : INService return false; } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set); conf.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions(); @@ -376,7 +376,7 @@ public class GreetSettingsService : INService public async Task SetGreet(ulong guildId, ulong channelId, bool? value = null) { bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage; @@ -415,7 +415,7 @@ public class GreetSettingsService : INService public async Task SetGreetDm(ulong guildId, bool? value = null) { bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage; @@ -503,7 +503,7 @@ public class GreetSettingsService : INService public async Task SetBye(ulong guildId, ulong channelId, bool? value = null) { bool enabled; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set); enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage; @@ -544,7 +544,7 @@ public class GreetSettingsService : INService if (timer < 0 || timer > 600) return; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(guildId, set => set); conf.AutoDeleteByeMessagesTimer = timer; @@ -561,7 +561,7 @@ public class GreetSettingsService : INService if (timer < 0 || timer > 600) return; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { var conf = uow.GuildConfigsForId(id, set => set); conf.AutoDeleteGreetMessagesTimer = timer; @@ -592,8 +592,8 @@ public class GreetSettingsService : INService { if (timer < 0 || timer > 600) throw new ArgumentOutOfRangeException(nameof(timer)); - - using var uow = _db.GetDbContext(); + + await using var uow = _db.GetDbContext(); var conf = uow.GuildConfigsForId(guildId, set => set); conf.BoostMessageDeleteAfter = timer; @@ -605,7 +605,7 @@ public class GreetSettingsService : INService public async Task ToggleBoost(ulong guildId, ulong channelId) { - using var uow = _db.GetDbContext(); + await using var uow = _db.GetDbContext(); var conf = uow.GuildConfigsForId(guildId, set => set); conf.SendBoostMessage = !conf.SendBoostMessage; conf.BoostMessageChannelId = channelId; diff --git a/src/NadekoBot/Services/Impl/CurrencyService.cs b/src/NadekoBot/Services/Impl/CurrencyService.cs index 2d3fd0148..f5435fcec 100644 --- a/src/NadekoBot/Services/Impl/CurrencyService.cs +++ b/src/NadekoBot/Services/Impl/CurrencyService.cs @@ -58,7 +58,7 @@ public class CurrencyService : ICurrencyService, INService throw new ArgumentException("You can't add negative amounts. Use RemoveAsync method for that.", nameof(amount)); } - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { InternalChange(userId, userName, discrim, avatar, reason, amount, gamble, uow); await uow.SaveChangesAsync(); @@ -102,7 +102,7 @@ public class CurrencyService : ICurrencyService, INService throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length."); var userIdHashSet = new HashSet(idArray.Length); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { for (var i = 0; i < idArray.Length; i++) { @@ -124,7 +124,7 @@ public class CurrencyService : ICurrencyService, INService throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length."); var userIdHashSet = new HashSet(idArray.Length); - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { for (var i = 0; i < idArray.Length; i++) { @@ -144,7 +144,7 @@ public class CurrencyService : ICurrencyService, INService } bool result; - using (var uow = _db.GetDbContext()) + await using (var uow = _db.GetDbContext()) { result = InternalChange(userId, userName, userDiscrim, avatar, reason, -amount, gamble, uow); await uow.SaveChangesAsync(); diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index bbbb9032b..493bcfd3a 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -16,7 +16,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl private readonly IBotCredentials _creds; private readonly DateTime _started; - public const string BotVersion = "3.0.11"; + public const string BotVersion = "4.0.0"; public string Author => "Kwoth#2452"; public string Library => "Discord.Net"; public double MessagesPerSecond => MessageCounter / GetUptime().TotalSeconds; @@ -42,7 +42,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl _started = DateTime.UtcNow; _client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter)); - cmdHandler.CommandExecuted += (_, e) => Task.FromResult(Interlocked.Increment(ref _commandsRan)); + cmdHandler.CommandExecuted += (_, _) => Task.FromResult(Interlocked.Increment(ref _commandsRan)); _client.ChannelCreated += c => { diff --git a/src/NadekoBot/_Extensions/IUserExtensions.cs b/src/NadekoBot/_Extensions/IUserExtensions.cs index 8b9f8a7ae..1591940ca 100644 --- a/src/NadekoBot/_Extensions/IUserExtensions.cs +++ b/src/NadekoBot/_Extensions/IUserExtensions.cs @@ -41,7 +41,7 @@ public static class IUserExtensions public static async Task SendFileAsync(this IUser user, string filePath, string caption = null, string text = null, bool isTTS = false) { - using (var file = File.Open(filePath, FileMode.Open)) + await using (var file = File.Open(filePath, FileMode.Open)) { return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(file, caption ?? "x", text, isTTS).ConfigureAwait(false); }