2021-08-27 11:03:47 -04:00
|
|
|
#nullable enable
|
2021-11-26 21:10:56 -05:00
|
|
|
namespace PluralKit.Core;
|
2020-06-12 23:13:21 +02:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
/// <summary>
|
|
|
|
|
/// Model for the `proxy_members` PL/pgSQL function in `functions.sql`
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class ProxyMember
|
2020-06-12 23:13:21 +02:00
|
|
|
{
|
2021-11-26 21:10:56 -05:00
|
|
|
public ProxyMember() { }
|
|
|
|
|
|
|
|
|
|
public ProxyMember(string name, params ProxyTag[] tags)
|
|
|
|
|
{
|
|
|
|
|
Name = name;
|
|
|
|
|
ProxyTags = tags;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemberId Id { get; }
|
|
|
|
|
public IReadOnlyCollection<ProxyTag> ProxyTags { get; } = new ProxyTag[0];
|
|
|
|
|
public bool KeepProxy { get; }
|
2023-08-10 18:03:37 +12:00
|
|
|
public bool Tts { get; }
|
2023-08-10 18:15:25 +12:00
|
|
|
public bool? ServerKeepProxy { get; }
|
2021-11-26 21:10:56 -05:00
|
|
|
|
|
|
|
|
public string? ServerName { get; }
|
|
|
|
|
public string? DisplayName { get; }
|
|
|
|
|
public string Name { get; } = "";
|
|
|
|
|
|
|
|
|
|
public string? ServerAvatar { get; }
|
2023-03-02 06:11:35 +13:00
|
|
|
public string? WebhookAvatar { get; }
|
2021-11-26 21:10:56 -05:00
|
|
|
public string? Avatar { get; }
|
|
|
|
|
|
|
|
|
|
public string? Color { get; }
|
|
|
|
|
|
2024-12-23 00:51:58 +00:00
|
|
|
public bool AllowAutoproxy { get; }
|
|
|
|
|
|
2024-10-22 03:05:32 -04:00
|
|
|
// If not set, this formatting will be applied to the proxy name
|
|
|
|
|
public static string DefaultFormat = "{name} {tag}";
|
|
|
|
|
|
2024-11-12 22:05:16 +13:00
|
|
|
public static string FormatTag(string template, string? tag, string name) => StringUtils.SafeFormat(template, new[] {
|
|
|
|
|
("{tag}", tag ?? ""),
|
2024-10-22 03:05:32 -04:00
|
|
|
("{name}", name)
|
2024-11-12 22:05:16 +13:00
|
|
|
}).Trim();
|
2024-10-22 03:05:32 -04:00
|
|
|
|
2021-11-26 21:10:56 -05:00
|
|
|
public string ProxyName(MessageContext ctx)
|
2020-06-12 23:13:21 +02:00
|
|
|
{
|
2021-11-26 21:10:56 -05:00
|
|
|
var memberName = ServerName ?? DisplayName ?? Name;
|
2024-10-22 03:05:32 -04:00
|
|
|
var tag = ctx.SystemGuildTag ?? ctx.SystemTag;
|
2024-11-12 22:05:16 +13:00
|
|
|
if (!ctx.TagEnabled) tag = null;
|
2021-11-26 21:10:56 -05:00
|
|
|
|
2024-11-19 17:35:09 -07:00
|
|
|
return FormatTag(ctx.GuildNameFormat ?? ctx.NameFormat ?? DefaultFormat, tag, memberName);
|
2020-06-12 23:13:21 +02:00
|
|
|
}
|
2021-11-26 21:10:56 -05:00
|
|
|
|
2023-07-19 12:48:04 +12:00
|
|
|
public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? WebhookAvatar ?? Avatar ?? ctx.SystemGuildAvatar ?? ctx.SystemAvatar;
|
2023-08-10 18:35:01 +12:00
|
|
|
}
|