From 2de6d399ce8bb0166fc160c1d31d9a6be208d5ca Mon Sep 17 00:00:00 2001 From: Fiona Date: Mon, 22 Jun 2020 21:06:14 +1000 Subject: [PATCH 1/2] Create GetMemberByDisplayName() --- PluralKit.Core/Services/IDataStore.cs | 6 ++++++ PluralKit.Core/Services/PostgresDataStore.cs | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/PluralKit.Core/Services/IDataStore.cs b/PluralKit.Core/Services/IDataStore.cs index 522db4b5..9d16eb4c 100644 --- a/PluralKit.Core/Services/IDataStore.cs +++ b/PluralKit.Core/Services/IDataStore.cs @@ -149,6 +149,12 @@ namespace PluralKit.Core { /// /// The with the given name, or null if no member was found. Task GetMemberByName(PKSystem system, string name); + + /// + /// Gets a member by its display name within one system. + /// + /// The with the given name, or null if no member was found. + Task GetMemberByDisplayName(PKSystem system, string name); /// /// Gets all members inside a given system. diff --git a/PluralKit.Core/Services/PostgresDataStore.cs b/PluralKit.Core/Services/PostgresDataStore.cs index fd4bc579..4d1e2165 100644 --- a/PluralKit.Core/Services/PostgresDataStore.cs +++ b/PluralKit.Core/Services/PostgresDataStore.cs @@ -141,6 +141,12 @@ namespace PluralKit.Core { return await conn.QueryFirstOrDefaultAsync("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id }); } + public async Task GetMemberByDisplayName(PKSystem system, string name) { + // QueryFirst, since members can (in rare cases) share display names + using (var conn = await _conn.Obtain()) + return await conn.QueryFirstOrDefaultAsync("select * from members where lower(display_name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id }); + } + public IAsyncEnumerable GetSystemMembers(PKSystem system, bool orderByName) { var sql = "select * from members where system = @SystemID"; From 5ba0dd02739bdc6f6b26421450753604c7a891cc Mon Sep 17 00:00:00 2001 From: Fiona Date: Mon, 22 Jun 2020 21:06:25 +1000 Subject: [PATCH 2/2] allow for matching by member display name --- PluralKit.Bot/CommandSystem/Context.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/PluralKit.Bot/CommandSystem/Context.cs b/PluralKit.Bot/CommandSystem/Context.cs index e4ecfbd5..d79e5693 100644 --- a/PluralKit.Bot/CommandSystem/Context.cs +++ b/PluralKit.Bot/CommandSystem/Context.cs @@ -188,10 +188,11 @@ namespace PluralKit.Bot { var input = PeekArgument(); - // Member references can have one or two forms, depending on + // Member references can have one of three forms, depending on // whether you're in a system or not: // - A member hid // - A textual name of a member *in your own system* + // - a textual display name of a member *in your own system* // First, if we have a system, try finding by member name in system if (_senderSystem != null && await _data.GetMemberByName(_senderSystem, input) is PKMember memberByName) @@ -200,6 +201,10 @@ namespace PluralKit.Bot // Then, try member HID parsing: if (await _data.GetMemberByHid(input) 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 (_senderSystem != null && await _data.GetMemberByDisplayName(_senderSystem, input) is PKMember memberByDisplayName) + return memberByDisplayName; // We didn't find anything, so we return null. return null;