Merge pull request #186 from BeeFox-sys/feature/displayname-member-argument
Feature - display name as a member argument
This commit is contained in:
commit
09624340ec
@ -188,10 +188,11 @@ namespace PluralKit.Bot
|
|||||||
{
|
{
|
||||||
var input = PeekArgument();
|
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:
|
// whether you're in a system or not:
|
||||||
// - A member hid
|
// - A member hid
|
||||||
// - A textual name of a member *in your own system*
|
// - 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
|
// First, if we have a system, try finding by member name in system
|
||||||
if (_senderSystem != null && await _data.GetMemberByName(_senderSystem, input) is PKMember memberByName)
|
if (_senderSystem != null && await _data.GetMemberByName(_senderSystem, input) is PKMember memberByName)
|
||||||
@ -201,6 +202,10 @@ namespace PluralKit.Bot
|
|||||||
if (await _data.GetMemberByHid(input) is PKMember memberByHid)
|
if (await _data.GetMemberByHid(input) is PKMember memberByHid)
|
||||||
return 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.
|
// We didn't find anything, so we return null.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,12 @@ namespace PluralKit.Core {
|
|||||||
/// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns>
|
/// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns>
|
||||||
Task<PKMember> GetMemberByName(PKSystem system, string name);
|
Task<PKMember> GetMemberByName(PKSystem system, string name);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a member by its display name within one system.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>The <see cref="PKMember"/> with the given name, or null if no member was found.</returns>
|
||||||
|
Task<PKMember> GetMemberByDisplayName(PKSystem system, string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets all members inside a given system.
|
/// Gets all members inside a given system.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -141,6 +141,12 @@ namespace PluralKit.Core {
|
|||||||
return await conn.QueryFirstOrDefaultAsync<PKMember>("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id });
|
return await conn.QueryFirstOrDefaultAsync<PKMember>("select * from members where lower(name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<PKMember> 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<PKMember>("select * from members where lower(display_name) = lower(@Name) and system = @SystemID", new { Name = name, SystemID = system.Id });
|
||||||
|
}
|
||||||
|
|
||||||
public IAsyncEnumerable<PKMember> GetSystemMembers(PKSystem system, bool orderByName)
|
public IAsyncEnumerable<PKMember> GetSystemMembers(PKSystem system, bool orderByName)
|
||||||
{
|
{
|
||||||
var sql = "select * from members where system = @SystemID";
|
var sql = "select * from members where system = @SystemID";
|
||||||
|
Loading…
Reference in New Issue
Block a user