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

@@ -279,7 +279,7 @@ public sealed class Bot
var _ = Task.Run(async () => var _ = Task.Run(async () =>
{ {
GuildConfig gc; GuildConfig gc;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
gc = uow.GuildConfigsForId(arg.Id); gc = uow.GuildConfigsForId(arg.Id);
} }

View File

@@ -155,7 +155,7 @@ public class ReplacementBuilder
_reps.TryAdd("%users%", () => c.Guilds.Sum(g => g.MemberCount).ToString()); _reps.TryAdd("%users%", () => c.Guilds.Sum(g => g.MemberCount).ToString());
/*NEW*/ /*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.usercount%", () => c.Guilds.Sum(g => g.MemberCount).ToString());
_reps.TryAdd("%shard.id%", () => c.ShardId.ToString()); _reps.TryAdd("%shard.id%", () => c.ShardId.ToString());
return this; return this;

View File

@@ -135,19 +135,19 @@ public partial class Administration
} }
rolesStr.AppendLine("\t\t\t\t ⟪" + groupNameText + "⟫"); 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; continue;
} }
else else
{ {
// first character is invisible space // first character is invisible space
if (Model.LevelRequirement == 0) if (model.LevelRequirement == 0)
rolesStr.AppendLine(" " + Role.Name); rolesStr.AppendLine(" " + role.Name);
else else
rolesStr.AppendLine(" " + Role.Name + $" (lvl {Model.LevelRequirement}+)"); rolesStr.AppendLine(" " + role.Name + $" (lvl {model.LevelRequirement}+)");
} }
} }
rolesStr.AppendLine(); rolesStr.AppendLine();

View File

@@ -90,7 +90,7 @@ public class AdministrationService : INService
public async Task SetDelMsgOnCmdState(ulong guildId, ulong chId, Administration.State newState) 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, var conf = uow.GuildConfigsForId(guildId,
set => set.Include(x => x.DelMsgOnCmdChannels)); 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) 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 gc = uow.GuildConfigsForId(guildId, set => set);
var roles = gc.GetAutoAssignableRoles(); var roles = gc.GetAutoAssignableRoles();
if(!roles.Remove(roleId) && roles.Count < 3) if(!roles.Remove(roleId) && roles.Count < 3)
@@ -122,7 +122,7 @@ public sealed class AutoAssignRoleService : INService
public async Task DisableAarAsync(ulong guildId) public async Task DisableAarAsync(ulong guildId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow await uow
.GuildConfigs .GuildConfigs
@@ -137,7 +137,7 @@ public sealed class AutoAssignRoleService : INService
public async Task SetAarRolesAsync(ulong guildId, IEnumerable<ulong> newRoles) 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); var gc = uow.GuildConfigsForId(guildId, set => set);
gc.SetAutoAssignableRoles(newRoles); gc.SetAutoAssignableRoles(newRoles);

View File

@@ -42,7 +42,7 @@ DELETE FROM Clubs;";
public async Task<int> ExecuteSql(string sql) public async Task<int> ExecuteSql(string sql)
{ {
int res; int res;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
res = await uow.Database.ExecuteSqlRawAsync(sql); res = await uow.Database.ExecuteSqlRawAsync(sql);
} }
@@ -92,7 +92,7 @@ DELETE FROM Clubs;";
public async Task PurgeUserAsync(ulong userId) public async Task PurgeUserAsync(ulong userId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
// get waifu info // get waifu info
var wi = await uow.Set<WaifuInfo>() 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) public async Task AddOverride(ulong guildId, string commandName, GuildPerm perm)
{ {
commandName = commandName.ToLowerInvariant(); commandName = commandName.ToLowerInvariant();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var over = await uow var over = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
@@ -84,7 +84,7 @@ public class DiscordPermOverrideService : INService, ILateBlocker
public async Task ClearAllOverrides(ulong guildId) public async Task ClearAllOverrides(ulong guildId)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var overrides = await uow var overrides = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()
@@ -106,8 +106,8 @@ public class DiscordPermOverrideService : INService, ILateBlocker
public async Task RemoveOverride(ulong guildId, string commandName) public async Task RemoveOverride(ulong guildId, string commandName)
{ {
commandName = commandName.ToLowerInvariant(); commandName = commandName.ToLowerInvariant();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var over = await uow var over = await uow
.Set<DiscordPermOverride>() .Set<DiscordPermOverride>()

View File

@@ -206,7 +206,7 @@ public sealed class LogCommandService : ILogCommandService
public async Task LogServer(ulong guildId, ulong channelId, bool value) 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); var logSetting = uow.LogSettingsFor(guildId);

View File

@@ -171,7 +171,7 @@ public class MuteService : INService
public async Task SetMuteRoleAsync(ulong guildId, string name) 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); var config = uow.GuildConfigsForId(guildId, set => set);
config.MuteRoleName = name; config.MuteRoleName = name;
@@ -189,7 +189,7 @@ public class MuteService : INService
if (!usr.RoleIds.Contains(muteRole.Id)) if (!usr.RoleIds.Contains(muteRole.Id))
await usr.AddRoleAsync(muteRole).ConfigureAwait(false); await usr.AddRoleAsync(muteRole).ConfigureAwait(false);
StopTimer(usr.GuildId, usr.Id, TimerType.Mute); 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, var config = uow.GuildConfigsForId(usr.Guild.Id,
set => set.Include(gc => gc.MutedUsers) set => set.Include(gc => gc.MutedUsers)
@@ -229,7 +229,7 @@ public class MuteService : INService
if (type == MuteType.All) if (type == MuteType.All)
{ {
StopTimer(guildId, usrId, TimerType.Mute); 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) var config = uow.GuildConfigsForId(guildId, set => set.Include(gc => gc.MutedUsers)
.Include(gc => gc.UnmuteTimers)); .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 = "") 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 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)); var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnmuteTimers));
config.UnmuteTimers.Add(new() config.UnmuteTimers.Add(new()
@@ -341,7 +341,7 @@ public class MuteService : INService
public async Task TimedBan(IGuild guild, IUser user, TimeSpan after, string reason) public async Task TimedBan(IGuild guild, IUser user, TimeSpan after, string reason)
{ {
await guild.AddBanAsync(user.Id, 0, reason).ConfigureAwait(false); 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)); var config = uow.GuildConfigsForId(guild.Id, set => set.Include(x => x.UnbanTimer));
config.UnbanTimer.Add(new() config.UnbanTimer.Add(new()
@@ -358,7 +358,7 @@ public class MuteService : INService
public async Task TimedRole(IGuildUser user, TimeSpan after, string reason, IRole role) public async Task TimedRole(IGuildUser user, TimeSpan after, string reason, IRole role)
{ {
await user.AddRoleAsync(role).ConfigureAwait(false); 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)); var config = uow.GuildConfigsForId(user.GuildId, set => set.Include(x => x.UnroleTimer));
config.UnroleTimer.Add(new() config.UnroleTimer.Add(new()

View File

@@ -52,7 +52,7 @@ public sealed class PlayingRotateService : INService
if (!_bss.Data.RotateStatuses) return; if (!_bss.Data.RotateStatuses) return;
IReadOnlyList<RotatingPlayingStatus> rotatingStatuses; IReadOnlyList<RotatingPlayingStatus> rotatingStatuses;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
rotatingStatuses = uow.RotatingStatus rotatingStatuses = uow.RotatingStatus
.AsNoTracking() .AsNoTracking()
@@ -81,7 +81,7 @@ public sealed class PlayingRotateService : INService
if (index < 0) if (index < 0)
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toRemove = await uow.RotatingStatus var toRemove = await uow.RotatingStatus
.AsQueryable() .AsQueryable()
.AsNoTracking() .AsNoTracking()
@@ -98,7 +98,7 @@ public sealed class PlayingRotateService : INService
public async Task AddPlaying(ActivityType t, string status) 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}; var toAdd = new RotatingPlayingStatus {Status = status, Type = t};
uow.Add(toAdd); uow.Add(toAdd);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -299,7 +299,7 @@ public class ProtectionService : INService
_antiRaidGuilds.AddOrUpdate(guildId, stats, (key, old) => stats); _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)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiRaidSetting));
@@ -370,7 +370,7 @@ public class ProtectionService : INService
return stats; return stats;
}); });
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting));
@@ -397,7 +397,7 @@ public class ProtectionService : INService
ChannelId = channelId ChannelId = channelId
}; };
bool added; 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 gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiSpamSetting).ThenInclude(x => x.IgnoredChannels));
var spam = gc.AntiSpamSetting; var spam = gc.AntiSpamSetting;
@@ -455,7 +455,7 @@ public class ProtectionService : INService
public async Task StartAntiAltAsync(ulong guildId, int minAgeMinutes, PunishmentAction action, public async Task StartAntiAltAsync(ulong guildId, int minAgeMinutes, PunishmentAction action,
int actionDurationMinutes = 0, ulong? roleId = null) 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)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
gc.AntiAltSetting = new() gc.AntiAltSetting = new()
{ {
@@ -473,8 +473,8 @@ public class ProtectionService : INService
{ {
if (!_antiAltGuilds.TryRemove(guildId, out _)) if (!_antiAltGuilds.TryRemove(guildId, out _))
return false; return false;
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.AntiAltSetting));
gc.AntiAltSetting = null; gc.AntiAltSetting = null;
await uow.SaveChangesAsync(); 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) public async Task<(AssignResult Result, bool AutoDelete, object extra)> Assign(IGuildUser guildUser, IRole role)
{ {
LevelStats userLevelData; LevelStats userLevelData;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id); var stats = uow.GetOrCreateUserXpStats(guildUser.Guild.Id, guildUser.Id);
userLevelData = new(stats.Xp + stats.AwardedXp); 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) public async Task<bool> SetNameAsync(ulong guildId, int group, string name)
{ {
var set = false; 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 gc = uow.GuildConfigsForId(guildId, y => y.Include(x => x.SelfAssignableRoleGroupNames));
var toUpdate = gc.SelfAssignableRoleGroupNames.FirstOrDefault(x => x.Number == group); 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() public async Task OnReadyAsync()
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
_autoCommands = uow _autoCommands = uow
.AutoCommands .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 // i can't just do ReadAsStreamAsync because dicord.net's image poops itself
var imgData = await sr.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 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); 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; var warnings = 1;
List<WarningPunishment> ps; List<WarningPunishment> ps;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments)) ps = uow.GuildConfigsForId(guildId, set => set.Include(x => x.WarnPunishments))
.WarnPunishments; .WarnPunishments;
@@ -206,7 +206,7 @@ public class UserPunishService : INService
public async Task CheckAllWarnExpiresAsync() public async Task CheckAllWarnExpiresAsync()
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var cleared = await uow.Database.ExecuteSqlRawAsync($@"UPDATE Warnings var cleared = await uow.Database.ExecuteSqlRawAsync($@"UPDATE Warnings
SET Forgiven = 1, SET Forgiven = 1,
@@ -228,7 +228,7 @@ WHERE GuildId in (SELECT GuildId FROM GuildConfigs WHERE WarnExpireHours > 0 AND
public async Task CheckWarnExpiresAsync(ulong guildId) public async Task CheckWarnExpiresAsync(ulong guildId)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(guildId, inc => inc); var config = uow.GuildConfigsForId(guildId, inc => inc);
@@ -265,7 +265,7 @@ WHERE GuildId={guildId}
public async Task WarnExpireAsync(ulong guildId, int days, bool delete) 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); 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) public async Task<bool> WarnClearAsync(ulong guildId, ulong userId, int index, string moderator)
{ {
var toReturn = true; var toReturn = true;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
if (index == 0) if (index == 0)
{ {

View File

@@ -122,7 +122,7 @@ public class VcRoleService : INService
if (missingRoles.Any()) if (missingRoles.Any())
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}"); Log.Warning($"Removing {missingRoles.Count} missing roles from {nameof(VcRoleService)}");
uow.RemoveRange(missingRoles); uow.RemoveRange(missingRoles);

View File

@@ -85,7 +85,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds) private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var guildItems = await uow.CustomReactions var guildItems = await uow.CustomReactions
.AsNoTracking() .AsNoTracking()
.Where(x => allGuildIds.Contains(x.GuildId.Value)) .Where(x => allGuildIds.Contains(x.GuildId.Value))
@@ -190,7 +190,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
private async Task OnJoinedGuild(GuildConfig gc) private async Task OnJoinedGuild(GuildConfig gc)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var crs = await uow var crs = await uow
.CustomReactions .CustomReactions
.AsNoTracking() .AsNoTracking()
@@ -217,7 +217,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
if (cr.Response.Contains("%target%", StringComparison.OrdinalIgnoreCase)) if (cr.Response.Contains("%target%", StringComparison.OrdinalIgnoreCase))
cr.AllowTarget = true; cr.AllowTarget = true;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
uow.CustomReactions.Add(cr); uow.CustomReactions.Add(cr);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -230,7 +230,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
public async Task<CustomReaction> EditAsync(ulong? guildId, int id, string message) public async Task<CustomReaction> EditAsync(ulong? guildId, int id, string message)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var cr = uow.CustomReactions.GetById(id); var cr = uow.CustomReactions.GetById(id);
if (cr is null || cr.GuildId != guildId) if (cr is null || cr.GuildId != guildId)
@@ -258,7 +258,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
public async Task<CustomReaction> DeleteAsync(ulong? guildId, int id) public async Task<CustomReaction> DeleteAsync(ulong? guildId, int id)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toDelete = uow.CustomReactions.GetById(id); var toDelete = uow.CustomReactions.GetById(id);
if (toDelete is null) if (toDelete is null)
@@ -477,7 +477,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
public async Task ResetCrReactions(ulong? maybeGuildId, int id) public async Task ResetCrReactions(ulong? maybeGuildId, int id)
{ {
CustomReaction cr; CustomReaction cr;
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
cr = uow.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
return; return;
@@ -594,7 +594,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
public async Task SetCrReactions(ulong? guildId, int id, IEnumerable<string> emojis) public async Task SetCrReactions(ulong? guildId, int id, IEnumerable<string> emojis)
{ {
CustomReaction cr; CustomReaction cr;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
cr = uow.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
@@ -612,7 +612,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
{ {
var newVal = false; var newVal = false;
CustomReaction cr; CustomReaction cr;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
cr = uow.CustomReactions.GetById(id); cr = uow.CustomReactions.GetById(id);
if (cr is null) if (cr is null)
@@ -711,7 +711,7 @@ public sealed class CustomReactionsService : IEarlyBehavior, IReadyExecutor
return false; return false;
} }
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
foreach (var entry in data) foreach (var entry in data)
{ {
var trigger = entry.Key; var trigger = entry.Key;

View File

@@ -40,7 +40,7 @@ public partial class Gambling
using (var img1 = GetDice(num1)) using (var img1 = GetDice(num1))
using (var img2 = GetDice(num2)) using (var img2 = GetDice(num2))
using (var img = new[] { img1, img2 }.Merge(out var format)) 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, await ctx.Channel.SendFileAsync(ms,
$"dice.{format.FileExtensions.First()}", $"dice.{format.FileExtensions.First()}",
@@ -116,7 +116,7 @@ public partial class Gambling
} }
using (var bitmap = dice.Merge(out var format)) 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) foreach (var d in dice)
{ {

View File

@@ -80,7 +80,7 @@ public partial class Gambling
num = 10; num = 10;
var (ImageStream, ToSend) = await InternalDraw(num, ctx.Guild.Id).ConfigureAwait(false); 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); await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
} }
@@ -95,7 +95,7 @@ public partial class Gambling
num = 10; num = 10;
var (ImageStream, ToSend) = await InternalDraw(num).ConfigureAwait(false); var (ImageStream, ToSend) = await InternalDraw(num).ConfigureAwait(false);
using (ImageStream) await using (ImageStream)
{ {
await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false); await ctx.Channel.SendFileAsync(ImageStream, num + " cards.jpg", ToSend).ConfigureAwait(false);
} }

View File

@@ -55,7 +55,7 @@ public partial class Gambling
} }
} }
using (var img = imgs.Merge(out var format)) 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) foreach (var i in imgs)
{ {

View File

@@ -187,7 +187,7 @@ public partial class Gambling : GamblingModule<GamblingService>
return; return;
var trs = new List<CurrencyTransaction>(); var trs = new List<CurrencyTransaction>();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
trs = uow.CurrencyTransactions.GetPageFor(userId, page); trs = uow.CurrencyTransactions.GetPageFor(userId, page);
} }
@@ -528,7 +528,7 @@ public partial class Gambling : GamblingModule<GamblingService>
{ {
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000); cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 10_000);
} }
@@ -542,7 +542,7 @@ public partial class Gambling : GamblingModule<GamblingService>
} }
else else
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList(); cleanRichest = uow.DiscordUser.GetTopRichest(_client.CurrentUser.Id, 9, page).ToList();
} }

View File

@@ -33,7 +33,7 @@ public class ShopService : IShopService, INService
if (newPrice <= 0) if (newPrice <= 0)
throw new ArgumentOutOfRangeException(nameof(newPrice)); throw new ArgumentOutOfRangeException(nameof(newPrice));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count) if (index >= entries.Count)
@@ -51,7 +51,7 @@ public class ShopService : IShopService, INService
if (string.IsNullOrWhiteSpace(newName)) if (string.IsNullOrWhiteSpace(newName))
throw new ArgumentNullException(nameof(newName)); throw new ArgumentNullException(nameof(newName));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
if (index >= entries.Count) if (index >= entries.Count)
@@ -69,7 +69,7 @@ public class ShopService : IShopService, INService
if (index2 < 0) if (index2 < 0)
throw new ArgumentOutOfRangeException(nameof(index2)); throw new ArgumentOutOfRangeException(nameof(index2));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
if (index1 >= entries.Count || index2 >= entries.Count || index1 == index2) if (index1 >= entries.Count || index2 >= entries.Count || index1 == index2)
@@ -89,7 +89,7 @@ public class ShopService : IShopService, INService
if (toIndex < 0) if (toIndex < 0)
throw new ArgumentOutOfRangeException(nameof(toIndex)); throw new ArgumentOutOfRangeException(nameof(toIndex));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var entries = GetEntriesInternal(uow, guildId); var entries = GetEntriesInternal(uow, guildId);
if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex) if (fromIndex >= entries.Count || toIndex >= entries.Count || fromIndex == toIndex)

View File

@@ -219,7 +219,7 @@ public class PlantPickService : INService
var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null; var pw = config.Generation.HasPassword ? GenerateCurrencyPassword().ToUpperInvariant() : null;
IUserMessage sent; 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); sent = await channel.SendFileAsync(stream, $"currency_image.{ext}", toSend).ConfigureAwait(false);
} }
@@ -259,7 +259,7 @@ public class PlantPickService : INService
{ {
long amount; long amount;
ulong[] ids; ulong[] ids;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
// this method will sum all plants with that password, // this method will sum all plants with that password,
// remove them, and get messageids of the removed plants // remove them, and get messageids of the removed plants
@@ -318,7 +318,7 @@ public class PlantPickService : INService
msgToSend += " " + GetText(gid, strs.pick_sn(prefix)); msgToSend += " " + GetText(gid, strs.pick_sn(prefix));
//get the image //get the image
using (var stream = GetRandomCurrencyImage(pass, out var ext)) await using (var stream = GetRandomCurrencyImage(pass, out var ext))
{ {
// send it // send it
var msg = await ch.SendFileAsync(stream, $"img.{ext}", msgToSend).ConfigureAwait(false); 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) 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() uow.PlantedCurrency.Add(new()
{ {

View File

@@ -39,8 +39,8 @@ public class WaifuService : INService
return false; return false;
var settings = _gss.Data; var settings = _gss.Data;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId); var waifu = uow.WaifuInfo.ByWaifuUserId(waifuId);
var ownerUser = uow.GetOrCreateUser(owner); var ownerUser = uow.GetOrCreateUser(owner);
@@ -116,7 +116,7 @@ public class WaifuService : INService
public async Task<bool> TryReset(IUser user) public async Task<bool> TryReset(IUser user)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var price = GetResetPrice(user); var price = GetResetPrice(user);
if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true)) if (!await _cs.RemoveAsync(user.Id, "Waifu Reset", price, gamble: true))
@@ -161,7 +161,7 @@ public class WaifuService : INService
WaifuClaimResult result; WaifuClaimResult result;
WaifuInfo w; WaifuInfo w;
bool isAffinity; bool isAffinity;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
w = uow.WaifuInfo.ByWaifuUserId(target.Id); w = uow.WaifuInfo.ByWaifuUserId(target.Id);
isAffinity = (w?.Affinity?.UserId == user.Id); isAffinity = (w?.Affinity?.UserId == user.Id);
@@ -251,7 +251,7 @@ public class WaifuService : INService
DiscordUser oldAff = null; DiscordUser oldAff = null;
var success = false; var success = false;
TimeSpan? remaining = null; TimeSpan? remaining = null;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var w = uow.WaifuInfo.ByWaifuUserId(user.Id); var w = uow.WaifuInfo.ByWaifuUserId(user.Id);
var newAff = target is null ? null : uow.GetOrCreateUser(target); var newAff = target is null ? null : uow.GetOrCreateUser(target);
@@ -323,7 +323,7 @@ public class WaifuService : INService
TimeSpan? remaining = null; TimeSpan? remaining = null;
long amount = 0; long amount = 0;
WaifuInfo w = null; WaifuInfo w = null;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
w = uow.WaifuInfo.ByWaifuUserId(targetId); w = uow.WaifuInfo.ByWaifuUserId(targetId);
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
@@ -375,7 +375,7 @@ public class WaifuService : INService
return false; return false;
} }
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id, var w = uow.WaifuInfo.ByWaifuUserId(giftedWaifu.Id,
set => set.Include(x => x.Items) set => set.Include(x => x.Items)

View File

@@ -89,7 +89,7 @@ public partial class Gambling
if (index < 0) if (index < 0)
return; return;
ShopEntry entry; ShopEntry entry;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
.Include(x => x.ShopEntries) .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)) 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<ShopEntryItem>().Remove(item); var x = uow.Set<ShopEntryItem>().Remove(item);
uow.SaveChanges(); uow.SaveChanges();
@@ -183,7 +183,7 @@ public partial class Gambling
await _cs.AddAsync(ctx.User.Id, await _cs.AddAsync(ctx.User.Id,
$"Shop error refund - {entry.Name}", $"Shop error refund - {entry.Name}",
entry.Price).ConfigureAwait(false); entry.Price).ConfigureAwait(false);
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
@@ -232,7 +232,7 @@ public partial class Gambling
RoleId = role.Id, RoleId = role.Id,
RoleName = role.Name RoleName = role.Name
}; };
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
@@ -263,7 +263,7 @@ public partial class Gambling
AuthorId = ctx.User.Id, AuthorId = ctx.User.Id,
Items = new(), Items = new(),
}; };
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
@@ -294,7 +294,7 @@ public partial class Gambling
ShopEntry entry; ShopEntry entry;
var rightType = false; var rightType = false;
var added = false; var added = false;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id, var entries = new IndexedCollection<ShopEntry>(uow.GuildConfigsForId(ctx.Guild.Id,
set => set.Include(x => x.ShopEntries) set => set.Include(x => x.ShopEntries)
@@ -327,7 +327,7 @@ public partial class Gambling
if (index < 0) if (index < 0)
return; return;
ShopEntry removed; ShopEntry removed;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set var config = uow.GuildConfigsForId(ctx.Guild.Id, set => set
.Include(x => x.ShopEntries) .Include(x => x.ShopEntries)

View File

@@ -172,7 +172,7 @@ public partial class Gambling
Interlocked.Add(ref _totalPaidOut, result.Won); Interlocked.Add(ref _totalPaidOut, result.Won);
long ownedAmount; long ownedAmount;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
ownedAmount = uow.Set<DiscordUser>() ownedAmount = uow.Set<DiscordUser>()
.FirstOrDefault(x => x.UserId == ctx.User.Id) .FirstOrDefault(x => x.UserId == ctx.User.Id)
@@ -243,7 +243,7 @@ public partial class Gambling
msg = GetText(strs.slot_jackpot(30)); msg = GetText(strs.slot_jackpot(30));
} }
using (var imgStream = bgImage.ToStream()) await using (var imgStream = bgImage.ToStream())
{ {
await ctx.Channel.SendFileAsync(imgStream, await ctx.Channel.SendFileAsync(imgStream,
filename: "result.png", filename: "result.png",

View File

@@ -32,7 +32,7 @@ public partial class Games
if (_service.ChatterBotGuilds.TryRemove(channel.Guild.Id, out _)) 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); uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, false);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -43,7 +43,7 @@ public partial class Games
_service.ChatterBotGuilds.TryAdd(channel.Guild.Id, new(() => _service.CreateSession(), true)); _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); uow.GuildConfigs.SetCleverbotEnabled(ctx.Guild.Id, true);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -54,7 +54,8 @@ public class PollRunner
var _ = OnVoted?.Invoke(msg, usr); var _ = OnVoted?.Invoke(msg, usr);
} }
finally { _locker.Release(); } finally { _locker.Release(); }
using (var uow = _db.GetDbContext())
await using (var uow = _db.GetDbContext())
{ {
var trackedPoll = uow.Poll.FirstOrDefault(x => x.Id == Poll.Id); var trackedPoll = uow.Poll.FirstOrDefault(x => x.Id == Poll.Id);
trackedPoll.Votes.Add(voteObj); trackedPoll.Votes.Add(voteObj);

View File

@@ -66,7 +66,7 @@ public partial class Games : NadekoModule<GamesService>
return; return;
} }
using (var imgStream = new MemoryStream()) await using (var imgStream = new MemoryStream())
{ {
lock (gr) lock (gr)
{ {

View File

@@ -379,7 +379,7 @@ public class Help : NadekoModule<HelpService>
}); });
} }
using var ms = new MemoryStream(); await using var ms = new MemoryStream();
await oldVersionObject.ResponseStream.CopyToAsync(ms); await oldVersionObject.ResponseStream.CopyToAsync(ms);
var versionListString = Encoding.UTF8.GetString(ms.ToArray()); var versionListString = Encoding.UTF8.GetString(ms.ToArray());
@@ -415,7 +415,7 @@ public class Help : NadekoModule<HelpService>
} }
// also send the file, but indented one, to chat // 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); await ctx.Channel.SendFileAsync(rDataStream, "cmds.json", GetText(strs.commandlist_regen)).ConfigureAwait(false);
} }

View File

@@ -49,7 +49,7 @@ public sealed partial class Music
List<MusicPlaylist> playlists; List<MusicPlaylist> playlists;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num); playlists = uow.MusicPlaylists.GetPlaylistsOnPage(num);
} }
@@ -71,7 +71,7 @@ public sealed partial class Music
var success = false; var success = false;
try try
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id); var pl = uow.MusicPlaylists.FirstOrDefault(x => x.Id == id);
@@ -105,7 +105,7 @@ public sealed partial class Music
return; return;
MusicPlaylist mpl; MusicPlaylist mpl;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
mpl = uow.MusicPlaylists.GetWithSongs(id); mpl = uow.MusicPlaylists.GetWithSongs(id);
} }
@@ -144,7 +144,7 @@ public sealed partial class Music
}).ToList(); }).ToList();
MusicPlaylist playlist; MusicPlaylist playlist;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
playlist = new() playlist = new()
{ {
@@ -203,7 +203,7 @@ public sealed partial class Music
} }
MusicPlaylist mpl; MusicPlaylist mpl;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
mpl = uow.MusicPlaylists.GetWithSongs(id); mpl = uow.MusicPlaylists.GetWithSongs(id);
} }

View File

@@ -345,8 +345,8 @@ public sealed class MusicService : IMusicService
{ {
if (_settings.TryGetValue(guildId, out var settings)) if (_settings.TryGetValue(guildId, out var settings))
return settings; return settings;
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId); var toReturn = _settings[guildId] = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -358,7 +358,7 @@ public sealed class MusicService : IMusicService
Action<MusicPlayerSettings, TState> action, Action<MusicPlayerSettings, TState> action,
TState state) TState state)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId); var ms = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
action(ms, state); action(ms, state);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();
@@ -438,7 +438,7 @@ public sealed class MusicService : IMusicService
public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId) public async Task<QualityPreset> GetMusicQualityAsync(ulong guildId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId); var settings = await uow.MusicPlayerSettings.ForGuildAsync(guildId);
return settings.QualityPreset; return settings.QualityPreset;
} }

View File

@@ -45,7 +45,7 @@ public partial class Permissions
} }
var name = command.Name.ToLowerInvariant(); 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 config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.CommandCooldowns));
var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CommandCooldown>()); var localSet = CommandCooldowns.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet<CommandCooldown>());

View File

@@ -40,7 +40,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
enabled = config.FilterInvites = !config.FilterInvites; enabled = config.FilterInvites = !config.FilterInvites;
@@ -66,7 +66,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
FilterChannelId removed; 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 config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterInvitesChannelIds));
var match = new FilterChannelId() var match = new FilterChannelId()
@@ -105,7 +105,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
enabled = config.FilterLinks = !config.FilterLinks; enabled = config.FilterLinks = !config.FilterLinks;
@@ -131,7 +131,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
FilterLinksChannelId removed; 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 config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterLinksChannelIds));
var match = new FilterLinksChannelId() var match = new FilterLinksChannelId()
@@ -170,7 +170,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GuildConfigsForId(channel.Guild.Id, set => set); var config = uow.GuildConfigsForId(channel.Guild.Id, set => set);
enabled = config.FilterWords = !config.FilterWords; enabled = config.FilterWords = !config.FilterWords;
@@ -196,7 +196,7 @@ public partial class Permissions
var channel = (ITextChannel)ctx.Channel; var channel = (ITextChannel)ctx.Channel;
FilterChannelId removed; 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)); var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilterWordsChannelIds));
@@ -240,7 +240,7 @@ public partial class Permissions
return; return;
FilteredWord removed; 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)); var config = uow.GuildConfigsForId(channel.Guild.Id, set => set.Include(gc => gc.FilteredWords));

View File

@@ -26,7 +26,7 @@ public partial class Permissions : NadekoModule<PermissionService>
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task Verbose(PermissionAction action = null) 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); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle. if (action is null) action = new(!config.VerbosePermissions); // New behaviour, can toggle.
@@ -68,7 +68,7 @@ public partial class Permissions : NadekoModule<PermissionService>
return; return;
} }
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
config.PermissionRole = role.Id.ToString(); config.PermissionRole = role.Id.ToString();
@@ -87,7 +87,7 @@ public partial class Permissions : NadekoModule<PermissionService>
[Priority(1)] [Priority(1)]
public async Task PermRole(Reset _) public async Task PermRole(Reset _)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
config.PermissionRole = null; config.PermissionRole = null;
@@ -143,7 +143,7 @@ public partial class Permissions : NadekoModule<PermissionService>
try try
{ {
Permissionv2 p; Permissionv2 p;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions); var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);
@@ -175,7 +175,7 @@ public partial class Permissions : NadekoModule<PermissionService>
try try
{ {
Permissionv2 fromPerm; Permissionv2 fromPerm;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GcWithPermissionsv2For(ctx.Guild.Id); var config = uow.GcWithPermissionsv2For(ctx.Guild.Id);
var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions); var permsCol = new PermissionsCollection<Permissionv2>(config.Permissions);

View File

@@ -71,7 +71,7 @@ public class PermissionService : ILateBlocker, INService
public async Task AddPermissions(ulong guildId, params Permissionv2[] perms) 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 config = uow.GcWithPermissionsv2For(guildId);
//var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions); //var orderedPerms = new PermissionsCollection<Permissionv2>(config.Permissions);
@@ -178,7 +178,7 @@ public class PermissionService : ILateBlocker, INService
public async Task Reset(ulong guildId) public async Task Reset(ulong guildId)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var config = uow.GcWithPermissionsv2For(guildId); var config = uow.GcWithPermissionsv2For(guildId);
config.Permissions = Permissionv2.GetDefaultPermlist; config.Permissions = Permissionv2.GetDefaultPermlist;

View File

@@ -48,7 +48,7 @@ public partial class Searches : NadekoModule<SearchesService>
var av = usr.RealAvatarUrl(128); var av = usr.RealAvatarUrl(128);
if (av is null) if (av is null)
return; 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( await ctx.Channel.SendFileAsync(
picStream, picStream,
@@ -626,7 +626,8 @@ public partial class Searches : NadekoModule<SearchesService>
new PointF(x, 50) new PointF(x, 50)
})); }));
} }
using (var ms = img.ToStream())
await using (var ms = img.ToStream())
{ {
await ctx.Channel.SendFileAsync(ms, $"colors.png").ConfigureAwait(false); await ctx.Channel.SendFileAsync(ms, $"colors.png").ConfigureAwait(false);
} }

View File

@@ -32,7 +32,6 @@ public class FeedsService : INService
.AsQueryable() .AsQueryable()
.Where(x => guildConfigIds.Contains(x.Id)) .Where(x => guildConfigIds.Contains(x.Id))
.Include(x => x.FeedSubs) .Include(x => x.FeedSubs)
.ThenInclude(x => x.GuildConfig)
.ToList() .ToList()
.SelectMany(x => x.FeedSubs) .SelectMany(x => x.FeedSubs)
.GroupBy(x => x.Url.ToLower()) .GroupBy(x => x.Url.ToLower())

View File

@@ -339,7 +339,7 @@ public sealed class StreamNotificationService : INService
public async Task<int> ClearAllStreams(ulong guildId) public async Task<int> 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)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));
uow.RemoveRange(gc.FollowedStreams); uow.RemoveRange(gc.FollowedStreams);
@@ -354,7 +354,7 @@ public sealed class StreamNotificationService : INService
public async Task<FollowedStream> UnfollowStreamAsync(ulong guildId, int index) public async Task<FollowedStream> UnfollowStreamAsync(ulong guildId, int index)
{ {
FollowedStream fs; FollowedStream fs;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var fss = uow.Set<FollowedStream>() var fss = uow.Set<FollowedStream>()
.AsQueryable() .AsQueryable()
@@ -400,7 +400,7 @@ public sealed class StreamNotificationService : INService
return null; return null;
FollowedStream fs; FollowedStream fs;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams)); var gc = uow.GuildConfigsForId(guildId, set => set.Include(x => x.FollowedStreams));

View File

@@ -84,7 +84,7 @@ public partial class Searches
} }
var streams = new List<FollowedStream>(); var streams = new List<FollowedStream>();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var all = uow var all = uow
.GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams)) .GuildConfigsForId(ctx.Guild.Id, set => set.Include(gc => gc.FollowedStreams))

View File

@@ -57,7 +57,7 @@ public partial class Utility
return; 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 config = uow.GuildConfigsForId(ctx.Guild.Id, set => set.Include(x => x.CommandAliases));
var toAdd = new CommandAlias() var toAdd = new CommandAlias()

View File

@@ -44,7 +44,7 @@ public partial class Utility
return; return;
IEnumerable<Quote> quotes; IEnumerable<Quote> quotes;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order); quotes = uow.Quotes.GetGroup(ctx.Guild.Id, page, order);
} }
@@ -67,7 +67,7 @@ public partial class Utility
keyword = keyword.ToUpperInvariant(); keyword = keyword.ToUpperInvariant();
Quote quote; Quote quote;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword); quote = await uow.Quotes.GetRandomQuoteByKeywordAsync(ctx.Guild.Id, keyword);
//if (quote != null) //if (quote != null)
@@ -95,7 +95,7 @@ public partial class Utility
public async Task QuoteShow(int id) public async Task QuoteShow(int id)
{ {
Quote quote; Quote quote;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quote = uow.Quotes.GetById(id); quote = uow.Quotes.GetById(id);
if (quote?.GuildId != ctx.Guild.Id) if (quote?.GuildId != ctx.Guild.Id)
@@ -132,7 +132,7 @@ public partial class Utility
keyword = keyword.ToUpperInvariant(); keyword = keyword.ToUpperInvariant();
Quote keywordquote; Quote keywordquote;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text); keywordquote = await uow.Quotes.SearchQuoteKeywordTextAsync(ctx.Guild.Id, keyword, text);
} }
@@ -157,7 +157,7 @@ public partial class Utility
.WithDefault(Context) .WithDefault(Context)
.Build(); .Build();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quote = uow.Quotes.GetById(id); quote = uow.Quotes.GetById(id);
} }
@@ -186,7 +186,7 @@ public partial class Utility
keyword = keyword.ToUpperInvariant(); keyword = keyword.ToUpperInvariant();
Quote q; Quote q;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
uow.Quotes.Add(q = new() uow.Quotes.Add(q = new()
{ {
@@ -209,7 +209,7 @@ public partial class Utility
var success = false; var success = false;
string response; string response;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var q = uow.Quotes.GetById(id); var q = uow.Quotes.GetById(id);
@@ -241,7 +241,7 @@ public partial class Utility
keyword = keyword.ToUpperInvariant(); keyword = keyword.ToUpperInvariant();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant()); uow.Quotes.RemoveAllByKeyword(ctx.Guild.Id, keyword.ToUpperInvariant());
@@ -289,7 +289,7 @@ public partial class Utility
public async Task QuotesExport() public async Task QuotesExport()
{ {
IEnumerable<Quote> quotes; IEnumerable<Quote> quotes;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
quotes = uow.Quotes quotes = uow.Quotes
.GetForGuild(ctx.Guild.Id) .GetForGuild(ctx.Guild.Id)

View File

@@ -107,7 +107,7 @@ public partial class Utility
.WithTitle(GetText(isServer ? strs.reminder_server_list : strs.reminder_list)); .WithTitle(GetText(isServer ? strs.reminder_server_list : strs.reminder_list));
List<Reminder> rems; List<Reminder> rems;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
if (isServer) if (isServer)
{ {
@@ -164,7 +164,7 @@ public partial class Utility
return; return;
Reminder rem = null; Reminder rem = null;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var rems = isServer var rems = isServer
? uow.Reminders ? uow.Reminders
@@ -219,7 +219,7 @@ public partial class Utility
ServerId = ctx.Guild?.Id ?? 0 ServerId = ctx.Guild?.Id ?? 0
}; };
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
uow.Reminders.Add(rem); uow.Reminders.Add(rem);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -231,7 +231,7 @@ public class PatreonRewardsService : INService
{ {
var eligibleFor = (int)(cents * settings.PatreonCurrencyPerCent); var eligibleFor = (int)(cents * settings.PatreonCurrencyPerCent);
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var users = uow.Set<RewardedUser>(); var users = uow.Set<RewardedUser>();
var usr = await users.FirstOrDefaultAsyncEF(x => x.PatreonUserId == patreonUserId); var usr = await users.FirstOrDefaultAsyncEF(x => x.PatreonUserId == patreonUserId);

View File

@@ -61,7 +61,7 @@ public class RemindService : INService
private async Task RemoveReminders(List<Reminder> reminders) private async Task RemoveReminders(List<Reminder> reminders)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
uow.Set<Reminder>() uow.Set<Reminder>()
.RemoveRange(reminders); .RemoveRange(reminders);

View File

@@ -138,7 +138,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
public async Task<bool> TriggerExternal(ulong guildId, int index) public async Task<bool> TriggerExternal(ulong guildId, int index)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toTrigger = await uow.Repeaters var toTrigger = await uow.Repeaters
.AsNoTracking() .AsNoTracking()
@@ -290,8 +290,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
private async Task RemoveRepeaterInternal(Repeater r) private async Task RemoveRepeaterInternal(Repeater r)
{ {
_noRedundant.TryRemove(r.Id); _noRedundant.TryRemove(r.Id);
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow await uow
.Repeaters .Repeaters
.DeleteAsync(x => x.Id == r.Id); .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) private async Task SetRepeaterLastMessageInternal(int repeaterId, ulong lastMsgId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.Repeaters await uow.Repeaters
.AsQueryable() .AsQueryable()
.Where(x => x.Id == repeaterId) .Where(x => x.Id == repeaterId)
@@ -345,7 +345,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
DateAdded = DateTime.UtcNow 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) if (await uow.Repeaters.CountAsyncEF(x => x.GuildId == guildId) < MAX_REPEATERS)
uow.Repeaters.Add(rep); uow.Repeaters.Add(rep);
@@ -365,8 +365,8 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
{ {
if (index > MAX_REPEATERS * 2) if (index > MAX_REPEATERS * 2)
throw new ArgumentOutOfRangeException(nameof(index)); throw new ArgumentOutOfRangeException(nameof(index));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toRemove = await uow.Repeaters var toRemove = await uow.Repeaters
.AsNoTracking() .AsNoTracking()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
@@ -398,7 +398,7 @@ where ((guildid >> 22) % {_creds.TotalShards}) == {_client.ShardId};")
public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index) public async Task<bool?> ToggleRedundantAsync(ulong guildId, int index)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var toToggle = await uow var toToggle = await uow
.Repeaters .Repeaters
.AsQueryable() .AsQueryable()

View File

@@ -70,7 +70,7 @@ public class StreamRoleService : INService
userName.ThrowIfNull(nameof(userName)); userName.ThrowIfNull(nameof(userName));
var success = false; var success = false;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
@@ -135,7 +135,7 @@ public class StreamRoleService : INService
{ {
keyword = keyword?.Trim()?.ToLowerInvariant(); keyword = keyword?.Trim()?.ToLowerInvariant();
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
@@ -181,7 +181,7 @@ public class StreamRoleService : INService
addRole.ThrowIfNull(nameof(addRole)); addRole.ThrowIfNull(nameof(addRole));
StreamRoleSettings setting; StreamRoleSettings setting;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id); var streamRoleSettings = uow.GetStreamRoleSettings(fromRole.Guild.Id);
@@ -208,7 +208,7 @@ public class StreamRoleService : INService
/// <param name="guildId">Guild's Id</param> /// <param name="guildId">Guild's Id</param>
public async Task StopStreamRole(IGuild guild, bool cleanup = false) 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); var streamRoleSettings = uow.GetStreamRoleSettings(guild.Id);
streamRoleSettings.Enabled = false; streamRoleSettings.Enabled = false;

View File

@@ -441,7 +441,7 @@ public partial class Utility : NadekoModule
return msg; 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); await ctx.User.SendFileAsync(stream, title, title, false).ConfigureAwait(false);
} }

View File

@@ -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); var club = uow.Clubs.GetByOwner(ownerUserId);

View File

@@ -168,7 +168,7 @@ public class XpService : INService
var group = toAddTo.GroupBy(x => (GuildId: x.Guild.Id, x.User)); var group = toAddTo.GroupBy(x => (GuildId: x.Guild.Id, x.User));
if (toAddTo.Count == 0) continue; if (toAddTo.Count == 0) continue;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
foreach (var item in group) foreach (var item in group)
{ {
@@ -450,7 +450,7 @@ public class XpService : INService
public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type) 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); var user = uow.GetOrCreateUserXpStats(guildId, userId);
user.NotifyOnLevelUp = type; user.NotifyOnLevelUp = type;
@@ -477,7 +477,7 @@ public class XpService : INService
public async Task ChangeNotificationType(IUser user, XpNotificationLocation type) public async Task ChangeNotificationType(IUser user, XpNotificationLocation type)
{ {
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var du = uow.GetOrCreateUser(user); var du = uow.GetOrCreateUser(user);
du.NotifyOnLevelUp = type; du.NotifyOnLevelUp = type;
@@ -724,7 +724,7 @@ public class XpService : INService
int totalXp; int totalXp;
int globalRank; int globalRank;
int guildRank; int guildRank;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
du = uow.GetOrCreateUser(user); du = uow.GetOrCreateUser(user);
totalXp = du.TotalXp; totalXp = du.TotalXp;
@@ -1044,7 +1044,7 @@ public class XpService : INService
.Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y) .Resize(_template.User.Icon.Size.X, _template.User.Icon.Size.Y)
.ApplyRoundedCorners( .ApplyRoundedCorners(
Math.Max(_template.User.Icon.Size.X, _template.User.Icon.Size.Y) / 2)); 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(); data = stream.ToArray();
} }
@@ -1157,7 +1157,7 @@ public class XpService : INService
.ApplyRoundedCorners( .ApplyRoundedCorners(
Math.Max(_template.Club.Icon.Size.X, _template.Club.Icon.Size.Y) / 2.0f)); 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(); data = tds.ToArray();
} }
@@ -1207,7 +1207,7 @@ public class XpService : INService
public async Task ResetXpRewards(ulong guildId) public async Task ResetXpRewards(ulong guildId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var guildConfig = uow.GuildConfigsForId(guildId, var guildConfig = uow.GuildConfigsForId(guildId,
set => set set => set
.Include(x => x.XpSettings) .Include(x => x.XpSettings)

View File

@@ -29,7 +29,7 @@ public partial class Xp : NadekoModule<XpService>
user = user ?? ctx.User; user = user ?? ctx.User;
await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false); await ctx.Channel.TriggerTypingAsync().ConfigureAwait(false);
var (img, fmt) = await _service.GenerateXpImageAsync((IGuildUser)user).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()}") await ctx.Channel.SendFileAsync(img, $"{ctx.Guild.Id}_{user.Id}_xp.{fmt.FileExtensions.FirstOrDefault()}")
.ConfigureAwait(false); .ConfigureAwait(false);

View File

@@ -4,6 +4,7 @@
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<LangVersion>10.0</LangVersion> <LangVersion>10.0</LangVersion>
<EnablePreviewFeatures>True</EnablePreviewFeatures> <EnablePreviewFeatures>True</EnablePreviewFeatures>
<ImplicitUsings>true</ImplicitUsings>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory> <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
<OutputType>exe</OutputType> <OutputType>exe</OutputType>
<ApplicationIcon>nadeko_icon.ico</ApplicationIcon> <ApplicationIcon>nadeko_icon.ico</ApplicationIcon>

View File

@@ -345,7 +345,7 @@ public class GreetSettingsService : INService
return false; return false;
} }
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions(); conf.DmGreetMessageText = settings.DmGreetMessageText?.SanitizeMentions();
@@ -376,7 +376,7 @@ public class GreetSettingsService : INService
public async Task<bool> SetGreet(ulong guildId, ulong channelId, bool? value = null) public async Task<bool> SetGreet(ulong guildId, ulong channelId, bool? value = null)
{ {
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage; enabled = conf.SendChannelGreetMessage = value ?? !conf.SendChannelGreetMessage;
@@ -415,7 +415,7 @@ public class GreetSettingsService : INService
public async Task<bool> SetGreetDm(ulong guildId, bool? value = null) public async Task<bool> SetGreetDm(ulong guildId, bool? value = null)
{ {
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage; enabled = conf.SendDmGreetMessage = value ?? !conf.SendDmGreetMessage;
@@ -503,7 +503,7 @@ public class GreetSettingsService : INService
public async Task<bool> SetBye(ulong guildId, ulong channelId, bool? value = null) public async Task<bool> SetBye(ulong guildId, ulong channelId, bool? value = null)
{ {
bool enabled; bool enabled;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage; enabled = conf.SendChannelByeMessage = value ?? !conf.SendChannelByeMessage;
@@ -544,7 +544,7 @@ public class GreetSettingsService : INService
if (timer < 0 || timer > 600) if (timer < 0 || timer > 600)
return; return;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.AutoDeleteByeMessagesTimer = timer; conf.AutoDeleteByeMessagesTimer = timer;
@@ -561,7 +561,7 @@ public class GreetSettingsService : INService
if (timer < 0 || timer > 600) if (timer < 0 || timer > 600)
return; return;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
var conf = uow.GuildConfigsForId(id, set => set); var conf = uow.GuildConfigsForId(id, set => set);
conf.AutoDeleteGreetMessagesTimer = timer; conf.AutoDeleteGreetMessagesTimer = timer;
@@ -592,8 +592,8 @@ public class GreetSettingsService : INService
{ {
if (timer < 0 || timer > 600) if (timer < 0 || timer > 600)
throw new ArgumentOutOfRangeException(nameof(timer)); throw new ArgumentOutOfRangeException(nameof(timer));
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.BoostMessageDeleteAfter = timer; conf.BoostMessageDeleteAfter = timer;
@@ -605,7 +605,7 @@ public class GreetSettingsService : INService
public async Task<bool> ToggleBoost(ulong guildId, ulong channelId) public async Task<bool> ToggleBoost(ulong guildId, ulong channelId)
{ {
using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
var conf = uow.GuildConfigsForId(guildId, set => set); var conf = uow.GuildConfigsForId(guildId, set => set);
conf.SendBoostMessage = !conf.SendBoostMessage; conf.SendBoostMessage = !conf.SendBoostMessage;
conf.BoostMessageChannelId = channelId; conf.BoostMessageChannelId = channelId;

View File

@@ -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)); 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); InternalChange(userId, userName, discrim, avatar, reason, amount, gamble, uow);
await uow.SaveChangesAsync(); 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."); throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length.");
var userIdHashSet = new HashSet<ulong>(idArray.Length); var userIdHashSet = new HashSet<ulong>(idArray.Length);
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
for (var i = 0; i < idArray.Length; i++) 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."); throw new ArgumentException("Cannot perform bulk operation. Arrays are not of equal length.");
var userIdHashSet = new HashSet<ulong>(idArray.Length); var userIdHashSet = new HashSet<ulong>(idArray.Length);
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
for (var i = 0; i < idArray.Length; i++) for (var i = 0; i < idArray.Length; i++)
{ {
@@ -144,7 +144,7 @@ public class CurrencyService : ICurrencyService, INService
} }
bool result; bool result;
using (var uow = _db.GetDbContext()) await using (var uow = _db.GetDbContext())
{ {
result = InternalChange(userId, userName, userDiscrim, avatar, reason, -amount, gamble, uow); result = InternalChange(userId, userName, userDiscrim, avatar, reason, -amount, gamble, uow);
await uow.SaveChangesAsync(); await uow.SaveChangesAsync();

View File

@@ -16,7 +16,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
private readonly IBotCredentials _creds; private readonly IBotCredentials _creds;
private readonly DateTime _started; 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 Author => "Kwoth#2452";
public string Library => "Discord.Net"; public string Library => "Discord.Net";
public double MessagesPerSecond => MessageCounter / GetUptime().TotalSeconds; public double MessagesPerSecond => MessageCounter / GetUptime().TotalSeconds;
@@ -42,7 +42,7 @@ public class StatsService : IStatsService, IReadyExecutor, INService, IDisposabl
_started = DateTime.UtcNow; _started = DateTime.UtcNow;
_client.MessageReceived += _ => Task.FromResult(Interlocked.Increment(ref _messageCounter)); _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 => _client.ChannelCreated += c =>
{ {

View File

@@ -41,7 +41,7 @@ public static class IUserExtensions
public static async Task<IUserMessage> SendFileAsync(this IUser user, string filePath, string caption = null, string text = null, bool isTTS = false) public static async Task<IUserMessage> 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); return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(file, caption ?? "x", text, isTTS).ConfigureAwait(false);
} }