From c927967c3bca75ec639e51a12c86e282164fdc20 Mon Sep 17 00:00:00 2001 From: Ske Date: Sat, 13 Jun 2020 19:42:04 +0200 Subject: [PATCH] Migrate GetSystemById --- PluralKit.Bot/Commands/Member.cs | 7 +++++-- PluralKit.Bot/Handlers/MessageCreated.cs | 2 +- PluralKit.Bot/Services/LogChannelService.cs | 4 ++-- PluralKit.Core/Models/ModelQueryExt.cs | 4 +++- PluralKit.Core/Services/IDataStore.cs | 6 ------ 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/PluralKit.Bot/Commands/Member.cs b/PluralKit.Bot/Commands/Member.cs index c90cd3c2..932906b9 100644 --- a/PluralKit.Bot/Commands/Member.cs +++ b/PluralKit.Bot/Commands/Member.cs @@ -8,12 +8,14 @@ namespace PluralKit.Bot public class Member { private IDataStore _data; + private IDatabase _db; private EmbedService _embeds; - public Member(IDataStore data, EmbedService embeds) + public Member(IDataStore data, EmbedService embeds, IDatabase db) { _data = data; _embeds = embeds; + _db = db; } public async Task NewMember(Context ctx) { @@ -66,7 +68,8 @@ namespace PluralKit.Bot 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))); } } diff --git a/PluralKit.Bot/Handlers/MessageCreated.cs b/PluralKit.Bot/Handlers/MessageCreated.cs index ec3ebd39..ec4652a6 100644 --- a/PluralKit.Bot/Handlers/MessageCreated.cs +++ b/PluralKit.Bot/Handlers/MessageCreated.cs @@ -94,7 +94,7 @@ namespace PluralKit.Bot 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)); } catch (PKError) diff --git a/PluralKit.Bot/Services/LogChannelService.cs b/PluralKit.Bot/Services/LogChannelService.cs index e6f19f8a..d122bb5f 100644 --- a/PluralKit.Bot/Services/LogChannelService.cs +++ b/PluralKit.Bot/Services/LogChannelService.cs @@ -41,8 +41,8 @@ namespace PluralKit.Bot { // Send embed! await using var conn = await _db.Obtain(); - var embed = _embed.CreateLoggedMessageEmbed(await _data.GetSystemById(ctx.SystemId.Value), - await _data.GetMemberById(proxy.Member.Id), hookMessage, trigger.Id, trigger.Author, proxy.Content, + var embed = _embed.CreateLoggedMessageEmbed(await conn.QuerySystem(ctx.SystemId.Value), + await conn.QueryMember(proxy.Member.Id), hookMessage, trigger.Id, trigger.Author, proxy.Content, trigger.Channel); var url = $"https://discord.com/channels/{trigger.Channel.GuildId}/{trigger.ChannelId}/{hookMessage}"; await logChannel.SendMessageAsync(content: url, embed: embed); diff --git a/PluralKit.Core/Models/ModelQueryExt.cs b/PluralKit.Core/Models/ModelQueryExt.cs index 2fb7e657..e91f41c4 100644 --- a/PluralKit.Core/Models/ModelQueryExt.cs +++ b/PluralKit.Core/Models/ModelQueryExt.cs @@ -1,5 +1,4 @@ #nullable enable -using System.Data; using System.Threading.Tasks; using Dapper; @@ -8,6 +7,9 @@ namespace PluralKit.Core { public static class ModelQueryExt { + public static Task QuerySystem(this IPKConnection conn, int id) => + conn.QueryFirstOrDefaultAsync("select * from systems where id = @id", new {id}); + public static Task QueryMember(this IPKConnection conn, int id) => conn.QueryFirstOrDefaultAsync("select * from members where id = @id", new {id}); diff --git a/PluralKit.Core/Services/IDataStore.cs b/PluralKit.Core/Services/IDataStore.cs index b7ac925a..d3d3b141 100644 --- a/PluralKit.Core/Services/IDataStore.cs +++ b/PluralKit.Core/Services/IDataStore.cs @@ -51,12 +51,6 @@ namespace PluralKit.Core { public interface IDataStore { - /// - /// Gets a system by its internal system ID. - /// - /// The with the given internal ID, or null if no system was found. - Task GetSystemById(int systemId); - /// /// Gets a system by its user-facing human ID. ///