mirror of
https://github.com/PluralKit/PluralKit.git
synced 2026-02-04 04:56:49 +00:00
feat: guild-specific name format
This commit is contained in:
parent
da4c05d4ed
commit
ec6cbb2a64
11 changed files with 75 additions and 5 deletions
|
|
@ -27,6 +27,7 @@ public class MessageContext
|
|||
public string? SystemGuildTag { get; }
|
||||
public bool TagEnabled { get; }
|
||||
public string? NameFormat { get; }
|
||||
public string? GuildNameFormat { get; }
|
||||
public string? SystemAvatar { get; }
|
||||
public string? SystemGuildAvatar { get; }
|
||||
public bool AllowAutoproxy { get; }
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ public static class MessageContextExt
|
|||
if (!ctx.TagEnabled || tag == null)
|
||||
return false;
|
||||
|
||||
var format = ctx.NameFormat ?? ProxyMember.DefaultFormat;
|
||||
var format = ctx.GuildNameFormat ?? ctx.NameFormat ?? ProxyMember.DefaultFormat;
|
||||
if (!format.Contains("{tag}"))
|
||||
return false;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ public class ProxyMember
|
|||
var tag = ctx.SystemGuildTag ?? ctx.SystemTag;
|
||||
if (!ctx.TagEnabled) tag = null;
|
||||
|
||||
return FormatTag(ctx.NameFormat ?? DefaultFormat, tag, memberName);
|
||||
return FormatTag(ctx.GuildNameFormat ?? ctx.NameFormat ?? DefaultFormat, tag, memberName);
|
||||
}
|
||||
|
||||
public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? WebhookAvatar ?? Avatar ?? ctx.SystemGuildAvatar ?? ctx.SystemAvatar;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ create function message_context(account_id bigint, guild_id bigint, channel_id b
|
|||
proxy_enabled bool,
|
||||
system_guild_tag text,
|
||||
system_guild_avatar text,
|
||||
guild_name_format text,
|
||||
|
||||
last_switch int,
|
||||
last_switch_members int[],
|
||||
|
|
@ -51,6 +52,7 @@ as $$
|
|||
coalesce(system_guild.proxy_enabled, true) as proxy_enabled,
|
||||
system_guild.tag as system_guild_tag,
|
||||
system_guild.avatar_url as system_guild_avatar,
|
||||
system_guild.name_format as guild_name_format,
|
||||
|
||||
-- system_last_switch view
|
||||
system_last_switch.switch as last_switch,
|
||||
|
|
|
|||
6
PluralKit.Core/Database/Migrations/49.sql
Normal file
6
PluralKit.Core/Database/Migrations/49.sql
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-- database version 49
|
||||
-- add guild name format
|
||||
|
||||
alter table system_guild add column name_format text;
|
||||
|
||||
update info set schema_version = 49;
|
||||
|
|
@ -9,7 +9,7 @@ namespace PluralKit.Core;
|
|||
internal class DatabaseMigrator
|
||||
{
|
||||
private const string RootPath = "PluralKit.Core.Database"; // "resource path" root for SQL files
|
||||
private const int TargetSchemaVersion = 48;
|
||||
private const int TargetSchemaVersion = 49;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ public class SystemGuildPatch: PatchObject
|
|||
public Partial<bool?> TagEnabled { get; set; }
|
||||
public Partial<string?> AvatarUrl { get; set; }
|
||||
public Partial<string?> DisplayName { get; set; }
|
||||
public Partial<string?> NameFormat { get; set; }
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
.With("proxy_enabled", ProxyEnabled)
|
||||
|
|
@ -20,6 +21,7 @@ public class SystemGuildPatch: PatchObject
|
|||
.With("tag_enabled", TagEnabled)
|
||||
.With("avatar_url", AvatarUrl)
|
||||
.With("display_name", DisplayName)
|
||||
.With("name_format", NameFormat)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
|
|
@ -53,6 +55,9 @@ public class SystemGuildPatch: PatchObject
|
|||
if (o.ContainsKey("display_name"))
|
||||
patch.DisplayName = o.Value<string>("display_name").NullIfEmpty();
|
||||
|
||||
if (o.ContainsKey("name_format"))
|
||||
patch.NameFormat = o.Value<string>("name_format").NullIfEmpty();
|
||||
|
||||
return patch;
|
||||
}
|
||||
|
||||
|
|
@ -77,6 +82,9 @@ public class SystemGuildPatch: PatchObject
|
|||
if (DisplayName.IsPresent)
|
||||
o.Add("display_name", DisplayName.Value);
|
||||
|
||||
if (NameFormat.IsPresent)
|
||||
o.Add("name_format", NameFormat.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ public class SystemGuildSettings
|
|||
public bool TagEnabled { get; }
|
||||
public string? AvatarUrl { get; }
|
||||
public string? DisplayName { get; }
|
||||
public string? NameFormat { get; }
|
||||
}
|
||||
|
||||
public static class SystemGuildExt
|
||||
|
|
@ -24,6 +25,7 @@ public static class SystemGuildExt
|
|||
o.Add("tag_enabled", settings.TagEnabled);
|
||||
o.Add("avatar_url", settings.AvatarUrl);
|
||||
o.Add("display_name", settings.DisplayName);
|
||||
o.Add("name_format", settings.NameFormat);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue