refactor: add SqlKata for SQL generation, move connection handling into ModelRepository
This commit is contained in:
@@ -130,6 +130,7 @@ namespace PluralKit.Bot
|
||||
// if we can't, big error. Every group name must be valid.
|
||||
throw new PKError(ctx.CreateGroupNotFoundError(ctx.PopArgument()));
|
||||
|
||||
// todo: remove this, the database query enforces the restriction
|
||||
if (restrictToSystem != null && group.System != restrictToSystem)
|
||||
throw Errors.NotOwnGroupError; // TODO: name *which* group?
|
||||
|
||||
|
@@ -49,14 +49,12 @@ namespace PluralKit.Bot
|
||||
// - A @mention of an account connected to the system (<@uid>)
|
||||
// - A system hid
|
||||
|
||||
await using var conn = await ctx.Database.Obtain();
|
||||
|
||||
// Direct IDs and mentions are both handled by the below method:
|
||||
if (input.TryParseMention(out var id))
|
||||
return await ctx.Repository.GetSystemByAccount(conn, id);
|
||||
return await ctx.Repository.GetSystemByAccount(id);
|
||||
|
||||
// Finally, try HID parsing
|
||||
var system = await ctx.Repository.GetSystemByHid(conn, input);
|
||||
var system = await ctx.Repository.GetSystemByHid(input);
|
||||
return system;
|
||||
}
|
||||
|
||||
@@ -71,16 +69,15 @@ namespace PluralKit.Bot
|
||||
// - a textual display name of a member *in your own system*
|
||||
|
||||
// First, if we have a system, try finding by member name in system
|
||||
await using var conn = await ctx.Database.Obtain();
|
||||
if (ctx.System != null && await ctx.Repository.GetMemberByName(conn, ctx.System.Id, input) is PKMember memberByName)
|
||||
if (ctx.System != null && await ctx.Repository.GetMemberByName(ctx.System.Id, input) is PKMember memberByName)
|
||||
return memberByName;
|
||||
|
||||
// Then, try member HID parsing:
|
||||
if (await ctx.Repository.GetMemberByHid(conn, input, restrictToSystem) is PKMember memberByHid)
|
||||
if (await ctx.Repository.GetMemberByHid(input, restrictToSystem) is PKMember memberByHid)
|
||||
return memberByHid;
|
||||
|
||||
// And if that again fails, we try finding a member with a display name matching the argument from the system
|
||||
if (ctx.System != null && await ctx.Repository.GetMemberByDisplayName(conn, ctx.System.Id, input) is PKMember memberByDisplayName)
|
||||
if (ctx.System != null && await ctx.Repository.GetMemberByDisplayName(ctx.System.Id, input) is PKMember memberByDisplayName)
|
||||
return memberByDisplayName;
|
||||
|
||||
// We didn't find anything, so we return null.
|
||||
@@ -107,12 +104,11 @@ namespace PluralKit.Bot
|
||||
{
|
||||
var input = ctx.PeekArgument();
|
||||
|
||||
await using var conn = await ctx.Database.Obtain();
|
||||
if (ctx.System != null && await ctx.Repository.GetGroupByName(conn, ctx.System.Id, input) is { } byName)
|
||||
if (ctx.System != null && await ctx.Repository.GetGroupByName(ctx.System.Id, input) is { } byName)
|
||||
return byName;
|
||||
if (await ctx.Repository.GetGroupByHid(conn, input, restrictToSystem) is { } byHid)
|
||||
if (await ctx.Repository.GetGroupByHid(input, restrictToSystem) is { } byHid)
|
||||
return byHid;
|
||||
if (await ctx.Repository.GetGroupByDisplayName(conn, ctx.System.Id, input) is { } byDisplayName)
|
||||
if (await ctx.Repository.GetGroupByDisplayName(ctx.System.Id, input) is { } byDisplayName)
|
||||
return byDisplayName;
|
||||
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user