Move system tag/icon from ProxyMember to MessageContent

This commit is contained in:
Ske 2020-06-12 23:30:10 +02:00
parent 2a39489c4d
commit 729930a562
4 changed files with 17 additions and 18 deletions

View File

@ -49,7 +49,7 @@ namespace PluralKit.Bot
// Permission check after proxy match so we don't get spammed when not actually proxying // Permission check after proxy match so we don't get spammed when not actually proxying
if (!await CheckBotPermissionsOrError(message.Channel)) return false; 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! // Everything's in order, we can execute the proxy!
await ExecuteProxy(message, ctx, match); await ExecuteProxy(message, ctx, match);
@ -81,8 +81,8 @@ namespace PluralKit.Bot
private async Task ExecuteProxy(DiscordMessage trigger, MessageContext ctx, ProxyMatch match) private async Task ExecuteProxy(DiscordMessage trigger, MessageContext ctx, ProxyMatch match)
{ {
// Send the webhook // Send the webhook
var id = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName, var id = await _webhookExecutor.ExecuteWebhook(trigger.Channel, match.Member.ProxyName(ctx),
match.Member.ProxyAvatar, match.Member.ProxyAvatar(ctx),
match.Content, trigger.Attachments); match.Content, trigger.Attachments);
// Handle post-proxy actions // Handle post-proxy actions
@ -129,9 +129,8 @@ namespace PluralKit.Bot
return true; 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 < 2) throw Errors.ProxyNameTooShort(proxyName);
if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName); if (proxyName.Length > Limits.MaxProxyNameLength) throw Errors.ProxyNameTooLong(proxyName);

View File

@ -23,5 +23,7 @@ namespace PluralKit.Core
public int LastSwitch { get; set; } public int LastSwitch { get; set; }
public IReadOnlyList<int> LastSwitchMembers { get; set; } = new int[0]; public IReadOnlyList<int> LastSwitchMembers { get; set; } = new int[0];
public Instant LastSwitchTimestamp { get; set; } public Instant LastSwitchTimestamp { get; set; }
public string? SystemTag { get; set; }
public string? SystemAvatar { get; set; }
} }
} }

View File

@ -15,16 +15,14 @@ namespace PluralKit.Core
public string? ServerName { get; set; } public string? ServerName { get; set; }
public string? DisplayName { get; set; } public string? DisplayName { get; set; }
public string Name { get; set; } = ""; public string Name { get; set; } = "";
public string? SystemTag { get; set; }
public string? ServerAvatar { get; set; } public string? ServerAvatar { get; set; }
public string? Avatar { get; set; } public string? Avatar { get; set; }
public string? SystemIcon { get; set; }
public string ProxyName => SystemTag != null public string ProxyName(MessageContext ctx) => ctx.SystemTag != null
? $"{ServerName ?? DisplayName ?? Name} {SystemTag}" ? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}"
: ServerName ?? DisplayName ?? Name; : ServerName ?? DisplayName ?? Name;
public string? ProxyAvatar => ServerAvatar ?? Avatar ?? SystemIcon; public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? Avatar ?? ctx.SystemAvatar;
} }
} }

View File

@ -12,7 +12,9 @@
last_message_member int, last_message_member int,
last_switch int, last_switch int,
last_switch_members int[], last_switch_members int[],
last_switch_timestamp timestamp last_switch_timestamp timestamp,
system_tag text,
system_avatar text
) )
as $$ as $$
with with
@ -32,7 +34,9 @@ as $$
last_message.member as last_message_member, last_message.member as last_message_member,
system_last_switch.switch as last_switch, system_last_switch.switch as last_switch,
system_last_switch.members as last_switch_members, 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 from system
full join guild on true full join guild on true
left join last_message 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, server_name text,
display_name text, display_name text,
name text, name text,
system_tag text,
server_avatar text, server_avatar text,
avatar text, avatar text
system_icon text
) )
as $$ as $$
select select
@ -70,12 +72,10 @@ as $$
member_guild.display_name as server_name, member_guild.display_name as server_name,
members.display_name as display_name, members.display_name as display_name,
members.name as name, members.name as name,
systems.tag as system_tag,
-- Avatar info -- Avatar info
member_guild.avatar_url as server_avatar, member_guild.avatar_url as server_avatar,
members.avatar_url as avatar, members.avatar_url as avatar
systems.avatar_url as system_icon
from accounts from accounts
inner join systems on systems.id = accounts.system inner join systems on systems.id = accounts.system
inner join members on members.system = systems.id inner join members on members.system = systems.id