RynthChat: server default tab planning and Global room discovery
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
626cc9dfc3
commit
620e6b1507
3 changed files with 179 additions and 0 deletions
|
|
@ -36,6 +36,9 @@
|
|||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\SharedFileWatch.cs" Link="Engine\SharedFileWatch.cs" />
|
||||
<!-- 2026-11-05: a plugin's own colour for a line it writes (RynthAi's Info text colour). -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatOwnColors.cs" Link="Engine\ChatOwnColors.cs" />
|
||||
<!-- 2026-11-15: server default tabs (a plugin manifest chatTabs) and Global room discovery. -->
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Sections\SectionManifest.cs" Link="Engine\SectionManifest.cs" />
|
||||
<Compile Include="..\..\src\RynthCore.Engine\UI\Data\ChatServerTabs.cs" Link="Engine\ChatServerTabs.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using RynthCore.Engine.UI.Data;
|
||||
using RynthCore.Engine.UI.Sections;
|
||||
|
||||
namespace ChatFilterTests;
|
||||
|
||||
|
|
@ -54,6 +55,8 @@ internal static class Program
|
|||
RetailSetting();
|
||||
TabsAcrossSetting();
|
||||
ServerTabSettingsRoundTrip();
|
||||
ServerTabDiscovery();
|
||||
ServerTabPlans();
|
||||
SharedFileReload();
|
||||
LineColorTags();
|
||||
LineColorKinds();
|
||||
|
|
@ -1143,6 +1146,83 @@ internal static class Program
|
|||
Check(old.Filters!.All(f => f.Server == null && f.Owner == null && f.GlobalRoom == null), "an old file's rules have none of the rule fields");
|
||||
}
|
||||
|
||||
// ── Server default tabs (2026-11-15) ──
|
||||
|
||||
private static SectionChatTabDecl NetworkDecl() => new(
|
||||
"dreamweave", "dereth-network", "Network", true, "Roleplay",
|
||||
new[]
|
||||
{
|
||||
new SectionChatRuleDecl("copy", "type:3", "", "^[^\"]+@[a-z0-9-]+( \\(discord\\))? tells you, \"", false),
|
||||
new SectionChatRuleDecl("copy", "type:4", "", "^You tell [^\"]+@[a-z0-9-]+( \\(discord\\))?, \"", false),
|
||||
new SectionChatRuleDecl("copy", "", "startswith", "", true),
|
||||
});
|
||||
|
||||
private static ChatServerTabs.SeedState State(string[]? seeded = null, string[]? tabs = null, RynthChatFilterDto[]? owned = null)
|
||||
=> new(seeded ?? Array.Empty<string>(), tabs ?? new[] { "All", "Chat" }, owned ?? Array.Empty<RynthChatFilterDto>());
|
||||
|
||||
private static void ServerTabDiscovery()
|
||||
{
|
||||
Case("Discover_FindsRemoteSpeaker");
|
||||
Check(ChatServerTabs.DiscoverRoom("[Roleplay] Bob@coldeve says, \"hi\"") == "Roleplay", "Roleplay, remote speaker");
|
||||
Check(ChatServerTabs.DiscoverRoom("[trade] Ann Smith@leaf-tide (Discord) says, \"x\"") == "Trade", "lower-case tag, Discord speaker, canonical Trade");
|
||||
Check(ChatServerTabs.DiscoverRoom("[LFG] Zed@dw says, \"x\"") == "LFG" && ChatServerTabs.DiscoverRoom("[general] Zed@dw says, \"x\"") == "General", "LFG and General");
|
||||
Case("Discover_IgnoresLocalSpeaker");
|
||||
Check(ChatServerTabs.DiscoverRoom("[Roleplay] Ann says, \"hi\"") == null, "a local speaker");
|
||||
Check(ChatServerTabs.DiscoverRoom("[Roleplay] Ann (Discord) says, \"hi\"") == null, "a Discord speaker with no @world");
|
||||
Case("Discover_IgnoresQuotedRoomText");
|
||||
Check(ChatServerTabs.DiscoverRoom("Bob says, \"[Trade] Ann@coldeve says, \\\"x\\\"\"") == null, "a say quoting a room line");
|
||||
Check(ChatServerTabs.DiscoverRoom("Bob@coldeve tells you, \"[Trade] Ann@coldeve says, \\\"x\\\"\"") == null, "a tell carrying a room line");
|
||||
Check(ChatServerTabs.DiscoverRoom("") == null && ChatServerTabs.DiscoverRoom("[Sports] Bob@coldeve says, \"x\"") == null, "empty and an unknown room");
|
||||
}
|
||||
|
||||
private static void ServerTabPlans()
|
||||
{
|
||||
SectionChatTabDecl d = NetworkDecl();
|
||||
string key = ChatServerTabs.OwnerKey(d);
|
||||
Case("Plan_SeedsFresh");
|
||||
Check(key == "dreamweave/dereth-network", "owner key");
|
||||
ChatServerTabs.SeedPlan p = ChatServerTabs.Plan(d, State(), null);
|
||||
Check(p.CreateTab && p.TabName == "Network" && p.Pin && p.MarkSeeded, "creates, names, pins and marks the tab");
|
||||
Check(p.Rules.Length == 3 && p.Rules.All(r => r.Owner == key && r.Server == "dreamweave" && r.Tab == "Network" && r.Enabled), "3 owned rules for the tab");
|
||||
RynthChatFilterDto g = p.Rules[2];
|
||||
Check(g.GlobalRoom == true && g.Mode == "startswith" && g.Pattern == "[Roleplay] ", "the Global rule uses the fallback room");
|
||||
Check(p.Rules[0].GlobalRoom == null && p.Rules[0].Pattern == d.Rules[0].Pattern && p.Rules[0].When == "type:3", "other rules copy the declaration");
|
||||
|
||||
Case("Plan_UsesDiscoveredRoom");
|
||||
Check(ChatServerTabs.Plan(d, State(), "General").Rules[2].Pattern == "[General] ", "the discovered room wins over the fallback");
|
||||
|
||||
Case("Plan_AdoptsExistingTabByName");
|
||||
p = ChatServerTabs.Plan(d, State(tabs: new[] { "All", "Chat", "Network" }), null);
|
||||
Check(!p.CreateTab && !p.Pin && p.MarkSeeded && p.TabName == "Network", "an existing Network tab is adopted, not duplicated or re-pinned");
|
||||
p = ChatServerTabs.Plan(d, State(tabs: new[] { "network" }), null);
|
||||
Check(!p.CreateTab, "the name match ignores case");
|
||||
var strayRule = new RynthChatFilterDto { Owner = key, Tab = "DN" };
|
||||
p = ChatServerTabs.Plan(d, State(owned: new[] { strayRule }), null);
|
||||
Check(!p.CreateTab && !p.Pin && p.MarkSeeded && p.TabName == "DN", "owned rules without a seed mark (older engine) are adopted too");
|
||||
|
||||
Case("Refresh_FollowsRenamedTab");
|
||||
RynthChatFilterDto[] owned = ChatServerTabs.Plan(d, State(), null).Rules;
|
||||
foreach (RynthChatFilterDto r in owned) r.Tab = "DN";
|
||||
p = ChatServerTabs.Plan(d, State(seeded: new[] { key }, tabs: new[] { "All", "Chat", "DN" }, owned: owned), "Trade");
|
||||
Check(p.TabName == "DN" && !p.CreateTab && !p.Pin && !p.MarkSeeded, "seeded: no create, no pin, no new mark");
|
||||
Check(p.Rules.All(r => r.Tab == "DN"), "every rule follows the rename");
|
||||
Check(p.Rules[2].Pattern == "[Trade] ", "a refresh rewrites the Global pattern");
|
||||
|
||||
Case("Refresh_KeepsDeletedTabDeleted");
|
||||
owned = ChatServerTabs.Plan(d, State(), null).Rules;
|
||||
foreach (RynthChatFilterDto r in owned) r.Enabled = false;
|
||||
p = ChatServerTabs.Plan(d, State(seeded: new[] { key }, owned: owned), null);
|
||||
Check(!p.CreateTab && !p.Pin, "a seeded tab that is gone is not re-created");
|
||||
Check(p.Rules.All(r => !r.Enabled), "its rules stay disabled");
|
||||
|
||||
Case("Plan rules compile");
|
||||
foreach (RynthChatFilterDto r in ChatServerTabs.Plan(d, State(), "LFG").Rules)
|
||||
{
|
||||
System.Text.RegularExpressions.Regex? rx = ChatRuleMatching.Compile(ChatRuleMatching.Parse(r.Mode), r.Pattern, 5000, out string? err);
|
||||
Check(err == null && rx != null, $"rule '{r.Pattern}' compiles: {err}");
|
||||
}
|
||||
}
|
||||
|
||||
private static void TabsAcrossSetting()
|
||||
{
|
||||
Case("tabs across the top: off (the drawer) unless a file says true");
|
||||
|
|
|
|||
Loading…
Reference in a new issue