From 1e5ba5f9853a3d5f3ad1886963fb1f5716d81cba Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 1 May 2021 19:17:35 +0100 Subject: [PATCH 1/4] feat: case-insensitive "text" keyword matching for proxy tags --- PluralKit.Bot/Commands/MemberProxy.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/PluralKit.Bot/Commands/MemberProxy.cs b/PluralKit.Bot/Commands/MemberProxy.cs index d09ea4cf..44873fb8 100644 --- a/PluralKit.Bot/Commands/MemberProxy.cs +++ b/PluralKit.Bot/Commands/MemberProxy.cs @@ -26,6 +26,7 @@ namespace PluralKit.Bot { // // Make sure there's one and only one instance of "text" in the example proxy given var prefixAndSuffix = exampleProxy.Split("text"); + if (prefixAndSuffix.Length == 1) prefixAndSuffix = prefixAndSuffix[0].Split("TEXT"); if (prefixAndSuffix.Length < 2) throw Errors.ProxyMustHaveText; if (prefixAndSuffix.Length > 2) throw Errors.ProxyMultipleText; return new ProxyTag(prefixAndSuffix[0], prefixAndSuffix[1]); From cf93b8b3cc909cd956e84f0f9357783c324a15d0 Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 1 May 2021 19:18:04 +0100 Subject: [PATCH 2/4] fix: don't try matching commands if there is nothing to match --- PluralKit.Bot/Handlers/MessageCreated.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PluralKit.Bot/Handlers/MessageCreated.cs b/PluralKit.Bot/Handlers/MessageCreated.cs index 30ced3ee..002a641a 100644 --- a/PluralKit.Bot/Handlers/MessageCreated.cs +++ b/PluralKit.Bot/Handlers/MessageCreated.cs @@ -103,7 +103,7 @@ namespace PluralKit.Bot if (content == null) return false; // Check for command prefix - if (!HasCommandPrefix(content, shard.User?.Id ?? default, out var cmdStart)) + if (!HasCommandPrefix(content, shard.User?.Id ?? default, out var cmdStart) || cmdStart == content.Length) return false; // Trim leading whitespace from command without actually modifying the string From 517abf7ff14deec856d30d1d877381a55814ce6f Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 1 May 2021 19:20:00 +0100 Subject: [PATCH 3/4] feat: show member color in reply embed --- PluralKit.Bot/Proxy/ProxyService.cs | 9 ++++++--- PluralKit.Core/Database/Functions/ProxyMember.cs | 2 ++ PluralKit.Core/Database/Functions/functions.sql | 6 +++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index 32781447..e1ac5ac8 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -116,7 +116,7 @@ namespace PluralKit.Bot if (repliedTo != null) { var nickname = await FetchReferencedMessageAuthorNickname(trigger, repliedTo); - var embed = CreateReplyEmbed(trigger, repliedTo, nickname); + var embed = CreateReplyEmbed(match, trigger, repliedTo, nickname); if (embed != null) embeds.Add(embed); } @@ -160,7 +160,7 @@ namespace PluralKit.Bot } } - private Embed CreateReplyEmbed(Message trigger, Message repliedTo, string? nickname) + private Embed CreateReplyEmbed(ProxyMatch match, Message trigger, Message repliedTo, string? nickname) { // repliedTo doesn't have a GuildId field :/ var jumpLink = $"https://discord.com/channels/{trigger.GuildId}/{repliedTo.ChannelId}/{repliedTo.Id}"; @@ -194,11 +194,14 @@ namespace PluralKit.Bot var username = nickname ?? repliedTo.Author.Username; var avatarUrl = $"https://cdn.discordapp.com/avatars/{repliedTo.Author.Id}/{repliedTo.Author.Avatar}.png"; + Console.WriteLine($"color {match.Member.Color}"); + return new Embed { // unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation] Author = new($"{username}\u2004\u21a9\ufe0f", IconUrl: avatarUrl), - Description = content.ToString() + Description = content.ToString(), + Color = match.Member.Color?.ToDiscordColor(), }; } diff --git a/PluralKit.Core/Database/Functions/ProxyMember.cs b/PluralKit.Core/Database/Functions/ProxyMember.cs index fc18a582..681ef179 100644 --- a/PluralKit.Core/Database/Functions/ProxyMember.cs +++ b/PluralKit.Core/Database/Functions/ProxyMember.cs @@ -19,7 +19,9 @@ namespace PluralKit.Core public string? ServerAvatar { get; } public string? Avatar { get; } + public bool AllowAutoproxy { get; } + public string? Color { get; } public string ProxyName(MessageContext ctx) => ctx.SystemTag != null ? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}" diff --git a/PluralKit.Core/Database/Functions/functions.sql b/PluralKit.Core/Database/Functions/functions.sql index f959f447..55628d49 100644 --- a/PluralKit.Core/Database/Functions/functions.sql +++ b/PluralKit.Core/Database/Functions/functions.sql @@ -64,10 +64,12 @@ create function proxy_members(account_id bigint, guild_id bigint) server_name text, display_name text, name text, - + server_avatar text, avatar text, + color char(6), + allow_autoproxy bool ) as $$ @@ -86,6 +88,8 @@ as $$ member_guild.avatar_url as server_avatar, members.avatar_url as avatar, + members.color as color, + members.allow_autoproxy as allow_autoproxy from accounts inner join systems on systems.id = accounts.system From 653c7b22bd8ed6dbcc0c78329ace66e68acf94fb Mon Sep 17 00:00:00 2001 From: spiral Date: Sat, 1 May 2021 19:32:37 +0100 Subject: [PATCH 4/4] remove random console log --- PluralKit.Bot/Proxy/ProxyService.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index e1ac5ac8..bb0f6232 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -194,8 +194,6 @@ namespace PluralKit.Bot var username = nickname ?? repliedTo.Author.Username; var avatarUrl = $"https://cdn.discordapp.com/avatars/{repliedTo.Author.Id}/{repliedTo.Author.Avatar}.png"; - Console.WriteLine($"color {match.Member.Color}"); - return new Embed { // unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation] @@ -295,4 +293,4 @@ namespace PluralKit.Bot if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); } } -} \ No newline at end of file +}