Added several missing using statements

This commit is contained in:
Kwoth
2022-03-21 13:20:26 +01:00
parent 9ade3c9537
commit 1f14c9066e
3 changed files with 12 additions and 11 deletions

View File

@@ -30,7 +30,7 @@ public sealed class ImageOnlyChannelService : IEarlyBehavior
_client = client; _client = client;
_db = db; _db = db;
var uow = _db.GetDbContext(); using var uow = _db.GetDbContext();
_enabledOn = uow.ImageOnlyChannels.ToList() _enabledOn = uow.ImageOnlyChannels.ToList()
.GroupBy(x => x.GuildId) .GroupBy(x => x.GuildId)
.ToDictionary(x => x.Key, x => new ConcurrentHashSet<ulong>(x.Select(y => y.ChannelId))) .ToDictionary(x => x.Key, x => new ConcurrentHashSet<ulong>(x.Select(y => y.ChannelId)))

View File

@@ -60,7 +60,6 @@ public class GamblingService : INService, IReadyExecutor
await using var uow = _db.GetDbContext(); await using var uow = _db.GetDbContext();
await uow.CurrencyTransactions await uow.CurrencyTransactions
.DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days); .DeleteAsync(ct => ct.DateAdded == null || now - ct.DateAdded < days);
await uow.SaveChangesAsync();
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -3,6 +3,7 @@ using LinqToDB;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using NadekoBot.Common.ModuleBehaviors; using NadekoBot.Common.ModuleBehaviors;
using NadekoBot.Services.Database.Models;
using System.Net; using System.Net;
namespace NadekoBot.Modules.Searches; namespace NadekoBot.Modules.Searches;
@@ -31,12 +32,14 @@ public sealed class TranslateService : ITranslateService, ILateExecutor, IReadyE
public async Task OnReadyAsync() public async Task OnReadyAsync()
{ {
var ctx = _db.GetDbContext(); List<AutoTranslateChannel> cs;
await using (var ctx = _db.GetDbContext())
var guilds = _bot.AllGuildConfigs.Select(x => x.GuildId).ToList(); {
var cs = await ctx.AutoTranslateChannels.Include(x => x.Users) var guilds = _bot.AllGuildConfigs.Select(x => x.GuildId).ToList();
cs = await ctx.AutoTranslateChannels.Include(x => x.Users)
.Where(x => guilds.Contains(x.GuildId)) .Where(x => guilds.Contains(x.GuildId))
.ToListAsyncEF(); .ToListAsyncEF();
}
foreach (var c in cs) foreach (var c in cs)
{ {
@@ -103,7 +106,7 @@ public sealed class TranslateService : ITranslateService, ILateExecutor, IReadyE
public async Task<bool> ToggleAtl(ulong guildId, ulong channelId, bool autoDelete) public async Task<bool> ToggleAtl(ulong guildId, ulong channelId, bool autoDelete)
{ {
var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
var old = await ctx.AutoTranslateChannels.ToLinqToDBTable() var old = await ctx.AutoTranslateChannels.ToLinqToDBTable()
.FirstOrDefaultAsyncLinqToDB(x => x.ChannelId == channelId); .FirstOrDefaultAsyncLinqToDB(x => x.ChannelId == channelId);
@@ -164,7 +167,7 @@ public sealed class TranslateService : ITranslateService, ILateExecutor, IReadyE
if (!_google.Languages.ContainsKey(from) || !_google.Languages.ContainsKey(to)) if (!_google.Languages.ContainsKey(from) || !_google.Languages.ContainsKey(to))
return null; return null;
var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
var ch = await ctx.AutoTranslateChannels.GetByChannelId(channelId); var ch = await ctx.AutoTranslateChannels.GetByChannelId(channelId);
if (ch is null) if (ch is null)
@@ -206,14 +209,13 @@ public sealed class TranslateService : ITranslateService, ILateExecutor, IReadyE
public async Task<bool> UnregisterUser(ulong channelId, ulong userId) public async Task<bool> UnregisterUser(ulong channelId, ulong userId)
{ {
var ctx = _db.GetDbContext(); await using var ctx = _db.GetDbContext();
var rows = await ctx.AutoTranslateUsers.ToLinqToDBTable() var rows = await ctx.AutoTranslateUsers.ToLinqToDBTable()
.DeleteAsync(x => x.UserId == userId && x.Channel.ChannelId == channelId); .DeleteAsync(x => x.UserId == userId && x.Channel.ChannelId == channelId);
if (_users.TryGetValue(channelId, out var inner)) if (_users.TryGetValue(channelId, out var inner))
inner.TryRemove(userId, out _); inner.TryRemove(userId, out _);
await ctx.SaveChangesAsync();
return rows > 0; return rows > 0;
} }