feat(bot): add proxy error config (#544)

This commit is contained in:
Jake Fulmine
2023-03-25 23:42:47 +01:00
committed by GitHub
parent 020a6f99fe
commit 8187aa05b7
10 changed files with 93 additions and 7 deletions

View File

@@ -29,4 +29,5 @@ public class MessageContext
public bool AllowAutoproxy { get; }
public int? LatchTimeout { get; }
public bool CaseSensitiveProxyTags { get; }
public bool ProxyErrorMessageEnabled { get; }
}

View File

@@ -15,13 +15,14 @@ create function message_context(account_id bigint, guild_id bigint, channel_id b
system_avatar text,
allow_autoproxy bool,
latch_timeout integer,
case_sensitive_proxy_tags bool
case_sensitive_proxy_tags bool,
proxy_error_message_enabled bool
)
as $$
-- CTEs to query "static" (accessible only through args) data
with
system as (select systems.*, system_config.latch_timeout, system_guild.tag as guild_tag, system_guild.tag_enabled as tag_enabled,
allow_autoproxy as account_autoproxy, system_config.case_sensitive_proxy_tags from accounts
allow_autoproxy as account_autoproxy, system_config.case_sensitive_proxy_tags, system_config.proxy_error_message_enabled from accounts
left join systems on systems.id = accounts.system
left join system_config on system_config.system = accounts.system
left join system_guild on system_guild.system = accounts.system and system_guild.guild = guild_id
@@ -43,7 +44,8 @@ as $$
system.avatar_url as system_avatar,
system.account_autoproxy as allow_autoproxy,
system.latch_timeout as latch_timeout,
system.case_sensitive_proxy_tags as case_sensitive_proxy_tags
system.case_sensitive_proxy_tags as case_sensitive_proxy_tags,
system.proxy_error_message_enabled as proxy_error_message_enabled
-- We need a "from" clause, so we just use some bogus data that's always present
-- This ensure we always have exactly one row going forward, so we can left join afterwards and still get data
from (select 1) as _placeholder

View File

@@ -0,0 +1,6 @@
-- database version 34
-- add proxy_error_message_enabled to system config
alter table system_config add column proxy_error_message_enabled bool default true;
update info set schema_version = 34;

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

View File

@@ -18,6 +18,7 @@ public class SystemConfigPatch: PatchObject
public Partial<int?> GroupLimitOverride { get; set; }
public Partial<string[]> DescriptionTemplates { get; set; }
public Partial<bool> CaseSensitiveProxyTags { get; set; }
public Partial<bool> ProxyErrorMessageEnabled { get; set; }
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
@@ -31,6 +32,7 @@ public class SystemConfigPatch: PatchObject
.With("group_limit_override", GroupLimitOverride)
.With("description_templates", DescriptionTemplates)
.With("case_sensitive_proxy_tags", CaseSensitiveProxyTags)
.With("proxy_error_message_enabled", ProxyErrorMessageEnabled)
);
public new void AssertIsValid()
@@ -83,6 +85,9 @@ public class SystemConfigPatch: PatchObject
if (CaseSensitiveProxyTags.IsPresent)
o.Add("case_sensitive_proxy_tags", CaseSensitiveProxyTags.Value);
if (ProxyErrorMessageEnabled.IsPresent)
o.Add("proxy_error_message_enabled", ProxyErrorMessageEnabled.Value);
return o;
}
@@ -111,6 +116,9 @@ public class SystemConfigPatch: PatchObject
if (o.ContainsKey("case_sensitive_proxy_tags"))
patch.CaseSensitiveProxyTags = o.Value<bool>("case_sensitive_proxy_tags");
if (o.ContainsKey("proxy_error_message_enabled"))
patch.ProxyErrorMessageEnabled = o.Value<bool>("proxy_error_message_enabled");
return patch;
}
}

View File

@@ -20,6 +20,7 @@ public class SystemConfig
public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
public bool CaseSensitiveProxyTags { get; set; }
public bool ProxyErrorMessageEnabled { get; }
}
public static class SystemConfigExt
@@ -37,6 +38,7 @@ public static class SystemConfigExt
o.Add("member_limit", cfg.MemberLimitOverride ?? Limits.MaxMemberCount);
o.Add("group_limit", cfg.GroupLimitOverride ?? Limits.MaxGroupCount);
o.Add("case_sensitive_proxy_tags", cfg.CaseSensitiveProxyTags);
o.Add("proxy_error_message_enabled", cfg.ProxyErrorMessageEnabled);
o.Add("description_templates", JArray.FromObject(cfg.DescriptionTemplates));