Add server-specific system tag

This commit is contained in:
spiral
2021-08-02 17:22:06 -04:00
parent 28bcb35bb2
commit 9d4006b056
11 changed files with 163 additions and 7 deletions

View File

@@ -23,6 +23,8 @@ namespace PluralKit.Core
public MemberId[] LastSwitchMembers { get; } = new MemberId[0];
public Instant? LastSwitchTimestamp { get; }
public string? SystemTag { get; }
public string? SystemGuildTag { get; }
public bool TagEnabled { get; }
public string? SystemAvatar { get; }
public bool AllowAutoproxy { get; }
public int? LatchTimeout { get; }

View File

@@ -23,10 +23,18 @@ namespace PluralKit.Core
public bool AllowAutoproxy { get; }
public string? Color { get; }
public string ProxyName(MessageContext ctx) => ctx.SystemTag != null
? $"{ServerName ?? DisplayName ?? Name} {ctx.SystemTag}"
: ServerName ?? DisplayName ?? Name;
public string ProxyName(MessageContext ctx)
{
var memberName = ServerName ?? DisplayName ?? Name;
if (!ctx.TagEnabled)
return memberName;
if (ctx.SystemGuildTag != null)
return $"{memberName} {ctx.SystemGuildTag}";
else if (ctx.SystemTag != null)
return $"{memberName} {ctx.SystemTag}";
else return memberName;
}
public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? Avatar ?? ctx.SystemAvatar;
public ProxyMember() { }

View File

@@ -14,6 +14,8 @@
last_switch_members int[],
last_switch_timestamp timestamp,
system_tag text,
system_guild_tag text,
tag_enabled bool,
system_avatar text,
allow_autoproxy bool,
latch_timeout integer
@@ -21,7 +23,10 @@
as $$
-- CTEs to query "static" (accessible only through args) data
with
system as (select systems.*, allow_autoproxy as account_autoproxy from accounts inner join systems on systems.id = accounts.system where accounts.uid = account_id),
system as (select systems.*, system_guild.tag as guild_tag, system_guild.tag_enabled as tag_enabled, allow_autoproxy as account_autoproxy from accounts
left join systems on systems.id = accounts.system
left join system_guild on system_guild.system = accounts.system and system_guild.guild = guild_id
where accounts.uid = account_id),
guild as (select * from servers where id = guild_id),
last_message as (select * from messages where messages.guild = guild_id and messages.sender = account_id order by mid desc limit 1)
select
@@ -39,6 +44,8 @@ as $$
system_last_switch.members as last_switch_members,
system_last_switch.timestamp as last_switch_timestamp,
system.tag as system_tag,
system.guild_tag as system_guild_tag,
system.tag_enabled as tag_enabled,
system.avatar_url as system_avatar,
system.account_autoproxy as allow_autoproxy,
system.latch_timeout as latch_timeout

View File

@@ -0,0 +1,7 @@
-- SCHEMA VERSION 16: 2021-08-02 --
-- Add server-specific system tag --
alter table system_guild add column tag text default null;
alter table system_guild add column tag_enabled bool not null default true;
update info set schema_version = 16;

View File

@@ -12,7 +12,7 @@ namespace PluralKit.Core
internal class DatabaseMigrator
{
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
private const int TargetSchemaVersion = 15;
private const int TargetSchemaVersion = 16;
private readonly ILogger _logger;
public DatabaseMigrator(ILogger logger)