Updated a few things again
This commit is contained in:
parent
7880f1f343
commit
bd61b0bf72
3 changed files with 22 additions and 22 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Ellie.Db;
|
using Ellie.Db;
|
||||||
using Ellie.Db.Models;
|
using Ellie.Db.Models;
|
||||||
// todo fix these namespaces. It should only be Ellie.Bot.Db
|
// todo fix these namespaces. It should only be Ellie.Bot.Db
|
||||||
|
@ -7,6 +8,6 @@ namespace Ellie.Extensions;
|
||||||
|
|
||||||
public static class DbExtensions
|
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);
|
=> ctx.GetOrCreateUser(original.Id, original.Username, original.Discriminator, original.AvatarId, includes);
|
||||||
}
|
}
|
|
@ -14,7 +14,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<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" />
|
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -110,28 +110,28 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
|
private async Task ReloadInternal(IReadOnlyList<ulong> allGuildIds)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
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))
|
.Where(x => allGuildIds.Contains(x.GuildId.Value))
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
newguildExpressions = guildItems.GroupBy(k => k.GuildId!.Value)
|
newguildExpressions = guildItems.GroupBy(k => k.GuildId!.Value)
|
||||||
.ToDictionary(g => g.Key,
|
.ToDictionary(g => g.Key,
|
||||||
g => g.Select(x =>
|
g => g.Select(x =>
|
||||||
{
|
{
|
||||||
x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention);
|
x.Trigger = x.Trigger.Replace(MENTION_PH, _client.CurrentUser.Mention);
|
||||||
return x;
|
return x;
|
||||||
})
|
})
|
||||||
.ToArray())
|
.ToArray())
|
||||||
.ToConcurrent();
|
.ToConcurrent();
|
||||||
|
|
||||||
_disabledGlobalExpressionGuilds = new(await uow.GuildConfigs
|
_disabledGlobalExpressionGuilds = new(await uow.Set<GuildConfig>()
|
||||||
.Where(x => x.DisableGlobalExpressions)
|
.Where(x => x.DisableGlobalExpressions)
|
||||||
.Select(x => x.GuildId)
|
.Select(x => x.GuildId)
|
||||||
.ToListAsyncLinqToDB());
|
.ToListAsyncLinqToDB());
|
||||||
|
|
||||||
lock (_gexprWriteLock)
|
lock (_gexprWriteLock)
|
||||||
{
|
{
|
||||||
var globalItems = uow.Expressions.AsNoTracking()
|
var globalItems = uow.Set<EllieExpression>().AsNoTracking()
|
||||||
.Where(x => x.GuildId == null || x.GuildId == 0)
|
.Where(x => x.GuildId == null || x.GuildId == 0)
|
||||||
.AsEnumerable()
|
.AsEnumerable()
|
||||||
.Select(x =>
|
.Select(x =>
|
||||||
|
@ -250,7 +250,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// todo print error etc
|
// todo print error etc
|
||||||
|
|
||||||
// if (await _cmdCds.TryBlock(guild, msg.Author, expr.Trigger))
|
// if (await _cmdCds.TryBlock(guild, msg.Author, expr.Trigger))
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
{
|
{
|
||||||
EllieExpression expr;
|
EllieExpression expr;
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
expr = uow.Expressions.GetById(id);
|
expr = uow.Set<EllieExpression>().GetById(id);
|
||||||
if (expr is null)
|
if (expr is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
EllieExpression expr;
|
EllieExpression expr;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
expr = uow.Expressions.GetById(id);
|
expr = uow.Set<EllieExpression>().GetById(id);
|
||||||
if (expr is null)
|
if (expr is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -477,7 +477,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
EllieExpression expr;
|
EllieExpression expr;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
expr = uow.Expressions.GetById(id);
|
expr = uow.Set<EllieExpression>().GetById(id);
|
||||||
|
|
||||||
if (expr is null || expr.GuildId != guildId)
|
if (expr is null || expr.GuildId != guildId)
|
||||||
return (false, false);
|
return (false, false);
|
||||||
|
@ -501,7 +501,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
public EllieExpression GetExpression(ulong? guildId, int id)
|
public EllieExpression GetExpression(ulong? guildId, int id)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
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)
|
if (expr is null || expr.GuildId != guildId)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
public int DeleteAllExpressions(ulong guildId)
|
public int DeleteAllExpressions(ulong guildId)
|
||||||
{
|
{
|
||||||
using var uow = _db.GetDbContext();
|
using var uow = _db.GetDbContext();
|
||||||
var count = uow.Expressions.ClearFromGuild(guildId);
|
var count = uow.Set<EllieExpression>().ClearFromGuild(guildId);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
|
|
||||||
newguildExpressions.TryRemove(guildId, out _);
|
newguildExpressions.TryRemove(guildId, out _);
|
||||||
|
@ -569,7 +569,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
foreach (var entry in data)
|
foreach (var entry in data)
|
||||||
{
|
{
|
||||||
var trigger = entry.Key;
|
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
|
.Select(expr => new EllieExpression
|
||||||
{
|
{
|
||||||
GuildId = guildId,
|
GuildId = guildId,
|
||||||
|
@ -658,7 +658,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
private async Task OnJoinedGuild(GuildConfig gc)
|
private async Task OnJoinedGuild(GuildConfig gc)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
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;
|
newguildExpressions[gc.GuildId] = exprs;
|
||||||
}
|
}
|
||||||
|
@ -682,7 +682,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
|
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
uow.Expressions.Add(expr);
|
uow.Set<EllieExpression>().Add(expr);
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -694,7 +694,7 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
public async Task<EllieExpression> EditAsync(ulong? guildId, int id, string message)
|
public async Task<EllieExpression> EditAsync(ulong? guildId, int id, string message)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
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)
|
if (expr is null || expr.GuildId != guildId)
|
||||||
return null;
|
return null;
|
||||||
|
@ -720,14 +720,14 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
public async Task<EllieExpression> DeleteAsync(ulong? guildId, int id)
|
public async Task<EllieExpression> DeleteAsync(ulong? guildId, int id)
|
||||||
{
|
{
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
var toDelete = uow.Expressions.GetById(id);
|
var toDelete = uow.Set<EllieExpression>().GetById(id);
|
||||||
|
|
||||||
if (toDelete is null)
|
if (toDelete is null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if ((toDelete.IsGlobal() && guildId is null) || guildId == toDelete.GuildId)
|
if ((toDelete.IsGlobal() && guildId is null) || guildId == toDelete.GuildId)
|
||||||
{
|
{
|
||||||
uow.Expressions.Remove(toDelete);
|
uow.Set<EllieExpression>().Remove(toDelete);
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
await DeleteInternalAsync(guildId, id);
|
await DeleteInternalAsync(guildId, id);
|
||||||
return toDelete;
|
return toDelete;
|
||||||
|
@ -762,4 +762,3 @@ public sealed class EllieExpressionsService : IExecOnMessage, IReadyExecutor
|
||||||
return toReturn;
|
return toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue