feat(bot): Case insensitive proxy tags matching (#490)
This commit is contained in:
@@ -28,4 +28,5 @@ public class MessageContext
|
||||
public string? SystemAvatar { get; }
|
||||
public bool AllowAutoproxy { get; }
|
||||
public int? LatchTimeout { get; }
|
||||
public bool CaseSensitiveProxyTags { get; }
|
||||
}
|
||||
@@ -14,12 +14,14 @@
|
||||
tag_enabled bool,
|
||||
system_avatar text,
|
||||
allow_autoproxy bool,
|
||||
latch_timeout integer
|
||||
latch_timeout integer,
|
||||
case_sensitive_proxy_tags 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 from accounts
|
||||
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
|
||||
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
|
||||
@@ -40,7 +42,8 @@ as $$
|
||||
coalesce(system.tag_enabled, true) as tag_enabled,
|
||||
system.avatar_url as system_avatar,
|
||||
system.account_autoproxy as allow_autoproxy,
|
||||
system.latch_timeout as latch_timeout
|
||||
system.latch_timeout as latch_timeout,
|
||||
system.case_sensitive_proxy_tags as case_sensitive_proxy_tags
|
||||
-- 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
|
||||
|
||||
5
PluralKit.Core/Database/Migrations/31.sql
Normal file
5
PluralKit.Core/Database/Migrations/31.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- schema version 31
|
||||
|
||||
alter table system_config add column case_sensitive_proxy_tags boolean not null default true;
|
||||
|
||||
update info set schema_version = 31;
|
||||
@@ -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 = 30;
|
||||
private const int TargetSchemaVersion = 31;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public DatabaseMigrator(ILogger logger)
|
||||
|
||||
@@ -17,6 +17,7 @@ public class SystemConfigPatch: PatchObject
|
||||
public Partial<int?> MemberLimitOverride { get; set; }
|
||||
public Partial<int?> GroupLimitOverride { get; set; }
|
||||
public Partial<string[]> DescriptionTemplates { get; set; }
|
||||
public Partial<bool> CaseSensitiveProxyTags { get; set; }
|
||||
|
||||
|
||||
public override Query Apply(Query q) => q.ApplyPatch(wrapper => wrapper
|
||||
@@ -29,6 +30,7 @@ public class SystemConfigPatch: PatchObject
|
||||
.With("member_limit_override", MemberLimitOverride)
|
||||
.With("group_limit_override", GroupLimitOverride)
|
||||
.With("description_templates", DescriptionTemplates)
|
||||
.With("case_sensitive_proxy_tags", CaseSensitiveProxyTags)
|
||||
);
|
||||
|
||||
public new void AssertIsValid()
|
||||
@@ -78,6 +80,9 @@ public class SystemConfigPatch: PatchObject
|
||||
if (DescriptionTemplates.IsPresent)
|
||||
o.Add("description_templates", JArray.FromObject(DescriptionTemplates.Value));
|
||||
|
||||
if (CaseSensitiveProxyTags.IsPresent)
|
||||
o.Add("case_sensitive_proxy_tags", CaseSensitiveProxyTags.Value);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -103,6 +108,9 @@ public class SystemConfigPatch: PatchObject
|
||||
if (o.ContainsKey("description_templates"))
|
||||
patch.DescriptionTemplates = o.Value<JArray>("description_templates").Select(x => x.Value<string>()).ToArray();
|
||||
|
||||
if (o.ContainsKey("case_sensitive_proxy_tags"))
|
||||
patch.CaseSensitiveProxyTags = o.Value<bool>("case_sensitive_proxy_tags");
|
||||
|
||||
return patch;
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,8 @@ public class SystemConfig
|
||||
public ICollection<string> DescriptionTemplates { get; }
|
||||
|
||||
public DateTimeZone Zone => DateTimeZoneProviders.Tzdb.GetZoneOrNull(UiTz);
|
||||
|
||||
public bool CaseSensitiveProxyTags { get; set; }
|
||||
}
|
||||
|
||||
public static class SystemConfigExt
|
||||
@@ -34,6 +36,7 @@ public static class SystemConfigExt
|
||||
o.Add("show_private_info", cfg.ShowPrivateInfo);
|
||||
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("description_templates", JArray.FromObject(cfg.DescriptionTemplates));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user