diff --git a/PluralKit.Bot/Proxy/ProxyService.cs b/PluralKit.Bot/Proxy/ProxyService.cs index fe2e5881..1971480d 100644 --- a/PluralKit.Bot/Proxy/ProxyService.cs +++ b/PluralKit.Bot/Proxy/ProxyService.cs @@ -49,7 +49,7 @@ namespace PluralKit.Bot // Permission check after proxy match so we don't get spammed when not actually proxying if (!await CheckBotPermissionsOrError(message.Channel)) return false; - if (!CheckProxyNameBoundsOrError(match)) return false; + if (!CheckProxyNameBoundsOrError(match.Member.ProxyName(ctx))) return false; // Everything's in order, we can execute the proxy! await ExecuteProxy(message, ctx, match); @@ -81,8 +81,8 @@ namespace PluralKit.Bot private async Task ExecuteProxy(DiscordMessage trigger, MessageContext ctx, ProxyMatch match) { // Send the webhook - var id = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName, - match.Member.ProxyAvatar, + var id = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName(ctx), + match.Member.ProxyAvatar(ctx), match.Content, trigger.Attachments); // Handle post-proxy actions @@ -129,9 +129,8 @@ namespace PluralKit.Bot return true; } - private bool CheckProxyNameBoundsOrError(ProxyMatch match) + private bool CheckProxyNameBoundsOrError(string proxyName) { - var proxyName = match.Member.ProxyName; if (proxyName.Length < 2) throw Errors.ProxyNameTooShort(proxyName); if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); diff --git a/PluralKit.Core/Database/Functions/MessageContext.cs b/PluralKit.Core/Database/Functions/MessageContext.cs index c9f31af0..e043cf82 100644 --- a/PluralKit.Core/Database/Functions/MessageContext.cs +++ b/PluralKit.Core/Database/Functions/MessageContext.cs @@ -23,5 +23,7 @@ namespace PluralKit.Core public int LastSwitch { get; set; } public IReadOnlyList LastSwitchMembers { get; set; } = new int[0]; public Instant LastSwitchTimestamp { get; set; } + public string? SystemTag { get; set; } + public string? SystemAvatar { get; set; } } } \ No newline at end of file diff --git a/PluralKit.Core/Database/Functions/ProxyMember.cs b/PluralKit.Core/Database/Functions/ProxyMember.cs index c6c96dfc..96d12640 100644 --- a/PluralKit.Core/Database/Functions/ProxyMember.cs +++ b/PluralKit.Core/Database/Functions/ProxyMember.cs @@ -15,16 +15,14 @@ namespace PluralKit.Core public string? ServerName { get; set; } public string? DisplayName { get; set; } public string Name { get; set; } = ""; - public string? SystemTag { get; set; } public string? ServerAvatar { get; set; } public string? Avatar { get; set; } - public string? SystemIcon { get; set; } - public string ProxyName => SystemTag != null - ? $"{ServerName ?? DisplayName ?? Name} {SystemTag}" + public string ProxyName(MessageContext ctx) => ctx.SystemTag != null + ? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}" : ServerName ?? DisplayName ?? Name; - public string? ProxyAvatar => ServerAvatar ?? Avatar ?? SystemIcon; + public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? Avatar ?? ctx.SystemAvatar; } } \ No newline at end of file diff --git a/PluralKit.Core/Database/Functions/functions.sql b/PluralKit.Core/Database/Functions/functions.sql index 2be38f5d..8d060ce5 100644 --- a/PluralKit.Core/Database/Functions/functions.sql +++ b/PluralKit.Core/Database/Functions/functions.sql @@ -12,7 +12,9 @@ last_message_member int, last_switch int, last_switch_members int[], - last_switch_timestamp timestamp + last_switch_timestamp timestamp, + system_tag text, + system_avatar text ) as $$ with @@ -32,7 +34,9 @@ as $$ last_message.member as last_message_member, system_last_switch.switch as last_switch, system_last_switch.members as last_switch_members, - system_last_switch.timestamp as last_switch_timestamp + system_last_switch.timestamp as last_switch_timestamp, + system.tag as system_tag, + system.avatar_url as system_avatar from system full join guild on true left join last_message on true @@ -53,11 +57,9 @@ create function proxy_members(account_id bigint, guild_id bigint) server_name text, display_name text, name text, - system_tag text, server_avatar text, - avatar text, - system_icon text + avatar text ) as $$ select @@ -70,12 +72,10 @@ as $$ member_guild.display_name as server_name, members.display_name as display_name, members.name as name, - systems.tag as system_tag, -- Avatar info member_guild.avatar_url as server_avatar, - members.avatar_url as avatar, - systems.avatar_url as system_icon + members.avatar_url as avatar from accounts inner join systems on systems.id = accounts.system inner join members on members.system = systems.id