feat: per-server keepproxy toggling (#574)

Merges PluralKit/PluralKit#574
This commit is contained in:
Jake Fulmine 2023-08-10 18:15:25 +12:00 committed by Iris System
parent 8a59ef5f50
commit 22ce250b56
11 changed files with 131 additions and 15 deletions

View file

@ -18,6 +18,7 @@ public class ProxyMember
public IReadOnlyCollection<ProxyTag> ProxyTags { get; } = new ProxyTag[0];
public bool KeepProxy { get; }
public bool Tts { get; }
public bool? ServerKeepProxy { get; }
public string? ServerName { get; }
public string? DisplayName { get; }
@ -44,4 +45,4 @@ public class ProxyMember
}
public string? ProxyAvatar(MessageContext ctx) => ServerAvatar ?? WebhookAvatar ?? Avatar ?? ctx.SystemGuildAvatar ?? ctx.SystemAvatar;
}
}

View file

@ -69,6 +69,7 @@ create function proxy_members(account_id bigint, guild_id bigint)
proxy_tags proxy_tag[],
keep_proxy bool,
tts bool,
server_keep_proxy bool,
server_name text,
display_name text,
@ -89,6 +90,7 @@ as $$
members.proxy_tags as proxy_tags,
members.keep_proxy as keep_proxy,
members.tts as tts,
member_guild.keep_proxy as server_keep_proxy,
-- Name info
member_guild.display_name as server_name,
@ -154,4 +156,4 @@ begin
if not exists (select 1 from groups where hid = new_hid) then return new_hid; end if;
end loop;
end
$$ language plpgsql volatile;
$$ language plpgsql volatile;

View file

@ -0,0 +1,6 @@
-- database version 40
-- add per-server keepproxy toggle
alter table member_guild add column keep_proxy bool default null;
update info set schema_version = 40;

View file

@ -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 = 39;
private const int TargetSchemaVersion = 40;
private readonly ILogger _logger;
public DatabaseMigrator(ILogger logger)

View file

@ -9,6 +9,7 @@ public class MemberGuildSettings
public ulong Guild { get; }
public string? DisplayName { get; }
public string? AvatarUrl { get; }
public bool? KeepProxy { get; }
}
public static class MemberGuildExt
@ -19,6 +20,7 @@ public static class MemberGuildExt
o.Add("display_name", settings.DisplayName);
o.Add("avatar_url", settings.AvatarUrl);
o.Add("keep_proxy", settings.KeepProxy);
return o;
}

View file

@ -10,10 +10,12 @@ public class MemberGuildPatch: PatchObject
{
public Partial<string?> DisplayName { get; set; }
public Partial<string?> AvatarUrl { get; set; }
public Partial<bool?> KeepProxy { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
.With("display_name", DisplayName)
.With("avatar_url", AvatarUrl)
.With("keep_proxy", KeepProxy)
);
public new void AssertIsValid()
@ -36,6 +38,9 @@ public class MemberGuildPatch: PatchObject
if (o.ContainsKey("avatar_url"))
patch.AvatarUrl = o.Value<string>("avatar_url").NullIfEmpty();
if (o.ContainsKey("keep_proxy"))
patch.KeepProxy = o.Value<bool>("keep_proxy");
return patch;
}
@ -51,6 +56,9 @@ public class MemberGuildPatch: PatchObject
if (AvatarUrl.IsPresent)
o.Add("avatar_url", AvatarUrl.Value);
if (KeepProxy.IsPresent)
o.Add("keep_proxy", KeepProxy.Value);
return o;
}
}