Updated a few things again

This commit is contained in:
Emotion 2023-08-03 15:23:30 +12:00
parent 7880f1f343
commit bd61b0bf72
No known key found for this signature in database
GPG key ID: D7D3E4C27A98C37B
3 changed files with 22 additions and 22 deletions

View file

@ -1,3 +1,4 @@
using Microsoft.EntityFrameworkCore;
using Ellie.Db;
using Ellie.Db.Models;
// todo fix these namespaces. It should only be Ellie.Bot.Db
@ -7,6 +8,6 @@ namespace Ellie.Extensions;
public static class DbExtensions
{
public static DiscordUser GetOrCreateUser(this EllieBaseContext ctx, IUser original, Func<IQueryable<DiscordUser>, IQueryable<DiscordUser>>? includes = null)
public static DiscordUser GetOrCreateUser(this DbContext ctx, IUser original, Func<IQueryable<DiscordUser>, IQueryable<DiscordUser>>? includes = null)
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId, includes);
}

View file

@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.104.0" />
<PackageReference Include="Discord.Net" Version="3.11.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>

View file

@ -110,28 +110,28 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
{
await using var uow = _db.GetDbContext();
var guildItems = await uow.Expressions.AsNoTracking()
var guildItems = await uow.Set<EllieExpression>().AsNoTracking()
.Where(x => allGuildIds.Contains(x.GuildId.Value))
.ToListAsync();
newguildExpressions = guildItems.GroupBy(k => k.GuildId!.Value)
.ToDictionary(g => g.Key,
g => g.Select(x =>
{
x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention);
return x;
})
{
x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention);
return x;
})
.ToArray())
.ToConcurrent();
_disabledGlobalExpressionGuilds = new(await uow.GuildConfigs
_disabledGlobalExpressionGuilds = new(await uow.Set<GuildConfig>()
.Where(x => x.DisableGlobalExpressions)
.Select(x => x.GuildId)
.ToListAsyncLinqToDB());
lock (_gexprWriteLock)
{
var globalItems = uow.Expressions.AsNoTracking()
var globalItems = uow.Set<EllieExpression>().AsNoTracking()
.Where(x => x.GuildId == null || x.GuildId == 0)
.AsEnumerable()
.Select(x =>
@ -344,7 +344,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
{
EllieExpression expr;
await using var uow = _db.GetDbContext();
expr = uow.Expressions.GetById(id);
expr = uow.Set<EllieExpression>().GetById(id);
if (expr is null)
return;
@ -459,7 +459,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
EllieExpression expr;
await using (var uow = _db.GetDbContext())
{
expr = uow.Expressions.GetById(id);
expr = uow.Set<EllieExpression>().GetById(id);
if (expr is null)
return;
@ -477,7 +477,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
EllieExpression expr;
await using (var uow = _db.GetDbContext())
{
expr = uow.Expressions.GetById(id);
expr = uow.Set<EllieExpression>().GetById(id);
if (expr is null || expr.GuildId != guildId)
return (false, false);
@ -501,7 +501,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
public EllieExpression GetExpression(ulong? guildId, int id)
{
using var uow = _db.GetDbContext();
var expr = uow.Expressions.GetById(id);
var expr = uow.Set<EllieExpression>().GetById(id);
if (expr is null || expr.GuildId != guildId)
return null;
@ -511,7 +511,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
public int DeleteAllExpressions(ulong guildId)
{
using var uow = _db.GetDbContext();
var count = uow.Expressions.ClearFromGuild(guildId);
var count = uow.Set<EllieExpression>().ClearFromGuild(guildId);
uow.SaveChanges();
newguildExpressions.TryRemove(guildId, out _);
@ -569,7 +569,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
foreach (var entry in data)
{
var trigger = entry.Key;
await uow.Expressions.AddRangeAsync(entry.Value.Where(expr => !string.IsNullOrWhiteSpace(expr.Res))
await uow.Set<EllieExpression>().AddRangeAsync(entry.Value.Where(expr => !string.IsNullOrWhiteSpace(expr.Res))
.Select(expr => new EllieExpression
{
GuildId = guildId,
@ -658,7 +658,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
private async Task OnJoinedGuild(GuildConfig gc)
{
await using var uow = _db.GetDbContext();
var exprs = await uow.Expressions.AsNoTracking().Where(x => x.GuildId == gc.GuildId).ToArrayAsync();
var exprs = await uow.Set<EllieExpression>().AsNoTracking().Where(x => x.GuildId == gc.GuildId).ToArrayAsync();
newguildExpressions[gc.GuildId] = exprs;
}
@ -682,7 +682,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
await using (var uow = _db.GetDbContext())
{
uow.Expressions.Add(expr);
uow.Set<EllieExpression>().Add(expr);
await uow.SaveChangesAsync();
}
@ -694,7 +694,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
public async Task<EllieExpression> EditAsync(ulong? guildId, int id, string message)
{
await using var uow = _db.GetDbContext();
var expr = uow.Expressions.GetById(id);
var expr = uow.Set<EllieExpression>().GetById(id);
if (expr is null || expr.GuildId != guildId)
return null;
@ -720,14 +720,14 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
public async Task<EllieExpression> DeleteAsync(ulong? guildId, int id)
{
await using var uow = _db.GetDbContext();
var toDelete = uow.Expressions.GetById(id);
var toDelete = uow.Set<EllieExpression>().GetById(id);
if (toDelete is null)
return null;
if ((toDelete.IsGlobal() && guildId is null) || guildId == toDelete.GuildId)
{
uow.Expressions.Remove(toDelete);
uow.Set<EllieExpression>().Remove(toDelete);
await uow.SaveChangesAsync();
await DeleteInternalAsync(guildId, id);
return toDelete;
@ -762,4 +762,3 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
return toReturn;
}
}