await usings and minor cleanup

This commit is contained in:
Kwoth
2021-12-20 03:02:02 +01:00
parent 1b2017024c
commit da2ee0c158
55 changed files with 176 additions and 174 deletions

View File

@@ -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));

View File

@@ -103,7 +103,7 @@ public sealed class AutoAssignRoleService : INService
public async Task<IReadOnlyList<ulong>> 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<ulong> newRoles)
{
using var uow = _db.GetDbContext();
await using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set);
gc.SetAutoAssignableRoles(newRoles);

View File

@@ -42,7 +42,7 @@ DELETE FROM Clubs;";
public async Task<int> 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<WaifuInfo>()

View File

@@ -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<DiscordPermOverride>()
@@ -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<DiscordPermOverride>()
@@ -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<DiscordPermOverride>()

View File

@@ -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);

View File

@@ -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()

View File

@@ -52,7 +52,7 @@ public sealed class PlayingRotateService : INService
if (!_bss.Data.RotateStatuses) return;
IReadOnlyList<RotatingPlayingStatus> 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();

View File

@@ -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();

View File

@@ -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<bool> 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);

View File

@@ -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);
}

View File

@@ -60,7 +60,7 @@ public class UserPunishService : INService
var warnings = 1;
List<WarningPunishment> 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<bool> 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)
{

View File

@@ -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);