Merge pull request #323 from spiralw/patch-2

misc patches
This commit is contained in:
Astrid 2021-05-02 00:14:17 +02:00 committed by GitHub
commit 48bd0940d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 6 deletions

View File

@ -26,6 +26,7 @@ namespace PluralKit.Bot
{ {
// // Make sure there's one and only one instance of "text" in the example proxy given // // Make sure there's one and only one instance of "text" in the example proxy given
var prefixAndSuffix = exampleProxy.Split("text"); 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.ProxyMustHaveText;
if (prefixAndSuffix.Length > 2) throw Errors.ProxyMultipleText; if (prefixAndSuffix.Length > 2) throw Errors.ProxyMultipleText;
return new ProxyTag(prefixAndSuffix[0], prefixAndSuffix[1]); return new ProxyTag(prefixAndSuffix[0], prefixAndSuffix[1]);

View File

@ -103,7 +103,7 @@ namespace PluralKit.Bot
if (content == null) return false; if (content == null) return false;
// Check for command prefix // 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; return false;
// Trim leading whitespace from command without actually modifying the string // Trim leading whitespace from command without actually modifying the string

View File

@ -116,7 +116,7 @@ namespace PluralKit.Bot
if (repliedTo != null) if (repliedTo != null)
{ {
var nickname = await FetchReferencedMessageAuthorNickname(trigger, repliedTo); var nickname = await FetchReferencedMessageAuthorNickname(trigger, repliedTo);
var embed = CreateReplyEmbed(trigger, repliedTo, nickname); var embed = CreateReplyEmbed(match, trigger, repliedTo, nickname);
if (embed != null) if (embed != null)
embeds.Add(embed); 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 :/ // repliedTo doesn't have a GuildId field :/
var jumpLink = $"https://discord.com/channels/{trigger.GuildId}/{repliedTo.ChannelId}/{repliedTo.Id}"; var jumpLink = $"https://discord.com/channels/{trigger.GuildId}/{repliedTo.ChannelId}/{repliedTo.Id}";
@ -198,7 +198,8 @@ namespace PluralKit.Bot
{ {
// unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation] // unicodes: [three-per-em space] [left arrow emoji] [force emoji presentation]
Author = new($"{username}\u2004\u21a9\ufe0f", IconUrl: avatarUrl), Author = new($"{username}\u2004\u21a9\ufe0f", IconUrl: avatarUrl),
Description = content.ToString() Description = content.ToString(),
Color = match.Member.Color?.ToDiscordColor(),
}; };
} }
@ -292,4 +293,4 @@ namespace PluralKit.Bot
if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName);
} }
} }
} }

View File

@ -19,7 +19,9 @@ namespace PluralKit.Core
public string? ServerAvatar { get; } public string? ServerAvatar { get; }
public string? Avatar { get; } public string? Avatar { get; }
public bool AllowAutoproxy { get; } public bool AllowAutoproxy { get; }
public string? Color { get; }
public string ProxyName(MessageContext ctx) => ctx.SystemTag != null public string ProxyName(MessageContext ctx) => ctx.SystemTag != null
? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}" ? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}"

View File

@ -64,10 +64,12 @@ create function proxy_members(account_id bigint, guild_id bigint)
server_name text, server_name text,
display_name text, display_name text,
name text, name text,
server_avatar text, server_avatar text,
avatar text, avatar text,
color char(6),
allow_autoproxy bool allow_autoproxy bool
) )
as $$ as $$
@ -86,6 +88,8 @@ as $$
member_guild.avatar_url as server_avatar, member_guild.avatar_url as server_avatar,
members.avatar_url as avatar, members.avatar_url as avatar,
members.color as color,
members.allow_autoproxy as allow_autoproxy members.allow_autoproxy as allow_autoproxy
from accounts from accounts
inner join systems on systems.id = accounts.system inner join systems on systems.id = accounts.system