Merge branch 'main' into proxyswitch-add

This commit is contained in:
Petal Ladenson 2024-12-05 18:18:04 -07:00 committed by GitHub
commit fbebe38afe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
59 changed files with 1000 additions and 423 deletions

View file

@ -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; }

View file

@ -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;

View file

@ -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;

View file

@ -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,

View 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;

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -2,6 +2,8 @@ using System.Globalization;
using Autofac;
using AppFact.SerilogOpenSearchSink;
using Microsoft.Extensions.Logging;
using NodaTime;
@ -9,7 +11,6 @@ using NodaTime;
using Serilog;
using Serilog.Events;
using Serilog.Formatting.Compact;
using Serilog.Sinks.Elasticsearch;
using Serilog.Sinks.Seq;
using Serilog.Sinks.SystemConsole.Themes;
@ -104,16 +105,12 @@ public class LoggingModule: Module
if (config.ElasticUrl != null)
{
var elasticConfig = new ElasticsearchSinkOptions(new Uri(config.ElasticUrl))
{
AutoRegisterTemplate = true,
AutoRegisterTemplateVersion = AutoRegisterTemplateVersion.ESv7,
MinimumLogEventLevel = config.ElasticLogLevel,
IndexFormat = "pluralkit-logs-{0:yyyy.MM.dd}",
CustomFormatter = new ScalarFormatting.Elasticsearch()
};
logCfg.WriteTo.Elasticsearch(elasticConfig);
logCfg.WriteTo.OpenSearch(
uri: config.ElasticUrl,
index: "dotnet-logs",
basicAuthUser: "unused",
basicAuthPassword: "unused"
);
}
if (config.SeqLogUrl != null)

View file

@ -18,6 +18,7 @@
<ItemGroup>
<PackageReference Include="App.Metrics" Version="4.1.0" />
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.1.0" />
<PackageReference Include="AppFact.SerilogOpenSearchSink" Version="0.0.8" />
<PackageReference Include="Autofac" Version="6.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Dapper" Version="2.0.35" />

View file

@ -22,6 +22,16 @@
"App.Metrics.Formatters.InfluxDB": "4.1.0"
}
},
"AppFact.SerilogOpenSearchSink": {
"type": "Direct",
"requested": "[0.0.8, )",
"resolved": "0.0.8",
"contentHash": "RI3lfmvAwhqrYwy5KPqsBT/tB/opSzeoVH2WUfvGKNBpl6ILCw/5wE8+19L+XMzBFVqgZ5QmkQ2PqTzG9I/ckA==",
"dependencies": {
"OpenSearch.Client": "1.4.0",
"Serilog": "2.12.0"
}
},
"Autofac": {
"type": "Direct",
"requested": "[6.0.0, )",
@ -551,6 +561,24 @@
"System.Xml.XDocument": "4.3.0"
}
},
"OpenSearch.Client": {
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "91TXm+I8PzxT0yxkf0q5Quee5stVcIFys56pU8+M3+Kiakx+aiaTAlZJHfA3Oy6dMJndNkVm37IPKYCqN3dS4g==",
"dependencies": {
"OpenSearch.Net": "1.4.0"
}
},
"OpenSearch.Net": {
"type": "Transitive",
"resolved": "1.4.0",
"contentHash": "xCM6m3aArN9gXIl2DvWXaDlbpjOBbgMeRPsAM7s1eDbWhu8wKNyfPNKSfep4JlYXkZ7N6Oi/+lmi+G3/SpcqlQ==",
"dependencies": {
"Microsoft.CSharp": "4.7.0",
"System.Buffers": "4.5.1",
"System.Diagnostics.DiagnosticSource": "6.0.1"
}
},
"Pipelines.Sockets.Unofficial": {
"type": "Transitive",
"resolved": "2.2.8",
@ -692,8 +720,8 @@
},
"System.Buffers": {
"type": "Transitive",
"resolved": "4.5.0",
"contentHash": "pL2ChpaRRWI/p4LXyy4RgeWlYF2sgfj/pnVMvBqwNFr5cXg7CXNnWZWxrOONLg8VGdFB8oB+EG2Qw4MLgTOe+A=="
"resolved": "4.5.1",
"contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg=="
},
"System.Collections": {
"type": "Transitive",
@ -746,8 +774,11 @@
},
"System.Diagnostics.DiagnosticSource": {
"type": "Transitive",
"resolved": "4.7.1",
"contentHash": "j81Lovt90PDAq8kLpaJfJKV/rWdWuEk6jfV+MBkee33vzYLEUsy4gXK8laa9V2nZlLM9VM9yA/OOQxxPEJKAMw=="
"resolved": "6.0.1",
"contentHash": "KiLYDu2k2J82Q9BJpWiuQqCkFjRBWVq4jDzKKWawVi9KWzyD0XG3cmfX0vqTQlL14Wi9EufJrbL0+KCLTbqWiQ==",
"dependencies": {
"System.Runtime.CompilerServices.Unsafe": "6.0.0"
}
},
"System.Diagnostics.Tools": {
"type": "Transitive",
@ -1081,8 +1112,8 @@
},
"System.Runtime.CompilerServices.Unsafe": {
"type": "Transitive",
"resolved": "4.7.1",
"contentHash": "zOHkQmzPCn5zm/BH+cxC1XbUS3P4Yoi3xzW7eRgVpDR2tPGSzyMZ17Ig1iRkfJuY0nhxkQQde8pgePNiA7z7TQ=="
"resolved": "6.0.0",
"contentHash": "/iUeP3tq1S0XdNNoMz5C9twLSrM/TH+qElHkXWaPvuNOt+99G75NrV0OS2EqHx5wMN7popYjpc8oTjC1y16DLg=="
},
"System.Runtime.Extensions": {
"type": "Transitive",