Migrate GetSystemById
This commit is contained in:
parent
511cf0ab55
commit
c927967c3b
@ -8,12 +8,14 @@ namespace PluralKit.Bot
|
|||||||
public class Member
|
public class Member
|
||||||
{
|
{
|
||||||
private IDataStore _data;
|
private IDataStore _data;
|
||||||
|
private IDatabase _db;
|
||||||
private EmbedService _embeds;
|
private EmbedService _embeds;
|
||||||
|
|
||||||
public Member(IDataStore data, EmbedService embeds)
|
public Member(IDataStore data, EmbedService embeds, IDatabase db)
|
||||||
{
|
{
|
||||||
_data = data;
|
_data = data;
|
||||||
_embeds = embeds;
|
_embeds = embeds;
|
||||||
|
_db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task NewMember(Context ctx) {
|
public async Task NewMember(Context ctx) {
|
||||||
@ -66,7 +68,8 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
public async Task ViewMember(Context ctx, PKMember target)
|
public async Task ViewMember(Context ctx, PKMember target)
|
||||||
{
|
{
|
||||||
var system = await _data.GetSystemById(target.System);
|
|
||||||
|
var system = await _db.Execute(c => c.QuerySystem(target.System));
|
||||||
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system)));
|
await ctx.Reply(embed: await _embeds.CreateMemberEmbed(system, target, ctx.Guild, ctx.LookupContextFor(system)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ namespace PluralKit.Bot
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var system = ctx.SystemId != null ? await _data.GetSystemById(ctx.SystemId.Value) : null;
|
var system = ctx.SystemId != null ? await _db.Execute(c => c.QuerySystem(ctx.SystemId.Value)) : null;
|
||||||
await _tree.ExecuteCommand(new Context(_services, evt.Client, evt.Message, argPos, system, ctx));
|
await _tree.ExecuteCommand(new Context(_services, evt.Client, evt.Message, argPos, system, ctx));
|
||||||
}
|
}
|
||||||
catch (PKError)
|
catch (PKError)
|
||||||
|
@ -41,8 +41,8 @@ namespace PluralKit.Bot {
|
|||||||
|
|
||||||
// Send embed!
|
// Send embed!
|
||||||
await using var conn = await _db.Obtain();
|
await using var conn = await _db.Obtain();
|
||||||
var embed = _embed.CreateLoggedMessageEmbed(await _data.GetSystemById(ctx.SystemId.Value),
|
var embed = _embed.CreateLoggedMessageEmbed(await conn.QuerySystem(ctx.SystemId.Value),
|
||||||
await _data.GetMemberById(proxy.Member.Id), hookMessage, trigger.Id, trigger.Author, proxy.Content,
|
await conn.QueryMember(proxy.Member.Id), hookMessage, trigger.Id, trigger.Author, proxy.Content,
|
||||||
trigger.Channel);
|
trigger.Channel);
|
||||||
var url = $"https://discord.com/channels/{trigger.Channel.GuildId}/{trigger.ChannelId}/{hookMessage}";
|
var url = $"https://discord.com/channels/{trigger.Channel.GuildId}/{trigger.ChannelId}/{hookMessage}";
|
||||||
await logChannel.SendMessageAsync(content: url, embed: embed);
|
await logChannel.SendMessageAsync(content: url, embed: embed);
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
#nullable enable
|
#nullable enable
|
||||||
using System.Data;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Dapper;
|
using Dapper;
|
||||||
@ -8,6 +7,9 @@ namespace PluralKit.Core
|
|||||||
{
|
{
|
||||||
public static class ModelQueryExt
|
public static class ModelQueryExt
|
||||||
{
|
{
|
||||||
|
public static Task<PKSystem?> QuerySystem(this IPKConnection conn, int id) =>
|
||||||
|
conn.QueryFirstOrDefaultAsync<PKSystem?>("select * from systems where id = @id", new {id});
|
||||||
|
|
||||||
public static Task<PKMember?> QueryMember(this IPKConnection conn, int id) =>
|
public static Task<PKMember?> QueryMember(this IPKConnection conn, int id) =>
|
||||||
conn.QueryFirstOrDefaultAsync<PKMember?>("select * from members where id = @id", new {id});
|
conn.QueryFirstOrDefaultAsync<PKMember?>("select * from members where id = @id", new {id});
|
||||||
|
|
||||||
|
@ -51,12 +51,6 @@ namespace PluralKit.Core {
|
|||||||
|
|
||||||
public interface IDataStore
|
public interface IDataStore
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets a system by its internal system ID.
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>The <see cref="PKSystem"/> with the given internal ID, or null if no system was found.</returns>
|
|
||||||
Task<PKSystem> GetSystemById(int systemId);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a system by its user-facing human ID.
|
/// Gets a system by its user-facing human ID.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user