@chatwarden/core 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +306 -7
- package/dist/src/ai/case.d.ts +4 -3
- package/dist/src/ai/case.d.ts.map +1 -1
- package/dist/src/ai/case.js +1 -1
- package/dist/src/ai/case.js.map +1 -1
- package/dist/src/ai/hash.d.ts +3 -1
- package/dist/src/ai/hash.d.ts.map +1 -1
- package/dist/src/ai/hash.js +5 -2
- package/dist/src/ai/hash.js.map +1 -1
- package/dist/src/ai/prompt.d.ts +13 -2
- package/dist/src/ai/prompt.d.ts.map +1 -1
- package/dist/src/ai/prompt.js +31 -1
- package/dist/src/ai/prompt.js.map +1 -1
- package/dist/src/ai/service.d.ts +21 -6
- package/dist/src/ai/service.d.ts.map +1 -1
- package/dist/src/ai/service.js +14 -7
- package/dist/src/ai/service.js.map +1 -1
- package/dist/src/ai/types.d.ts +33 -2
- package/dist/src/ai/types.d.ts.map +1 -1
- package/dist/src/ai/types.js +3 -2
- package/dist/src/ai/types.js.map +1 -1
- package/dist/src/ai/worker.d.ts +8 -1
- package/dist/src/ai/worker.d.ts.map +1 -1
- package/dist/src/ai/worker.js +17 -3
- package/dist/src/ai/worker.js.map +1 -1
- package/dist/src/appealService.d.ts +105 -0
- package/dist/src/appealService.d.ts.map +1 -0
- package/dist/src/appealService.js +548 -0
- package/dist/src/appealService.js.map +1 -0
- package/dist/src/appeals.d.ts +194 -0
- package/dist/src/appeals.d.ts.map +1 -0
- package/dist/src/appeals.js +107 -0
- package/dist/src/appeals.js.map +1 -0
- package/dist/src/audit.d.ts +7 -3
- package/dist/src/audit.d.ts.map +1 -1
- package/dist/src/audit.js +18 -3
- package/dist/src/audit.js.map +1 -1
- package/dist/src/chat.d.ts +39 -1
- package/dist/src/chat.d.ts.map +1 -1
- package/dist/src/chat.js +85 -6
- package/dist/src/chat.js.map +1 -1
- package/dist/src/chatwarden.d.ts +197 -10
- package/dist/src/chatwarden.d.ts.map +1 -1
- package/dist/src/chatwarden.js +212 -23
- package/dist/src/chatwarden.js.map +1 -1
- package/dist/src/decide.d.ts +2 -0
- package/dist/src/decide.d.ts.map +1 -1
- package/dist/src/decide.js +12 -7
- package/dist/src/decide.js.map +1 -1
- package/dist/src/documents.d.ts +1 -1
- package/dist/src/documents.d.ts.map +1 -1
- package/dist/src/documents.js +5 -1
- package/dist/src/documents.js.map +1 -1
- package/dist/src/events.d.ts +38 -0
- package/dist/src/events.d.ts.map +1 -1
- package/dist/src/events.js +3 -0
- package/dist/src/events.js.map +1 -1
- package/dist/src/freeze.d.ts +3 -0
- package/dist/src/freeze.d.ts.map +1 -0
- package/dist/src/freeze.js +10 -0
- package/dist/src/freeze.js.map +1 -0
- package/dist/src/index.d.ts +20 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +11 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/ladder.d.ts +28 -0
- package/dist/src/ladder.d.ts.map +1 -1
- package/dist/src/ladder.js +37 -1
- package/dist/src/ladder.js.map +1 -1
- package/dist/src/nameService.d.ts +90 -0
- package/dist/src/nameService.d.ts.map +1 -0
- package/dist/src/nameService.js +224 -0
- package/dist/src/nameService.js.map +1 -0
- package/dist/src/names.d.ts +68 -0
- package/dist/src/names.d.ts.map +1 -0
- package/dist/src/names.js +87 -0
- package/dist/src/names.js.map +1 -0
- package/dist/src/notices.d.ts +53 -5
- package/dist/src/notices.d.ts.map +1 -1
- package/dist/src/notices.js +93 -8
- package/dist/src/notices.js.map +1 -1
- package/dist/src/pace.d.ts +66 -0
- package/dist/src/pace.d.ts.map +1 -0
- package/dist/src/pace.js +111 -0
- package/dist/src/pace.js.map +1 -0
- package/dist/src/pacing.d.ts +63 -0
- package/dist/src/pacing.d.ts.map +1 -0
- package/dist/src/pacing.js +198 -0
- package/dist/src/pacing.js.map +1 -0
- package/dist/src/policy.d.ts +66 -1
- package/dist/src/policy.d.ts.map +1 -1
- package/dist/src/policy.js +86 -5
- package/dist/src/policy.js.map +1 -1
- package/dist/src/profile.d.ts +57 -8
- package/dist/src/profile.d.ts.map +1 -1
- package/dist/src/profile.js +69 -25
- package/dist/src/profile.js.map +1 -1
- package/dist/src/profileError.d.ts +10 -0
- package/dist/src/profileError.d.ts.map +1 -0
- package/dist/src/profileError.js +17 -0
- package/dist/src/profileError.js.map +1 -0
- package/dist/src/retention.d.ts +40 -1
- package/dist/src/retention.d.ts.map +1 -1
- package/dist/src/retention.js +50 -3
- package/dist/src/retention.js.map +1 -1
- package/dist/src/sanctions.d.ts +29 -1
- package/dist/src/sanctions.d.ts.map +1 -1
- package/dist/src/sanctions.js +52 -9
- package/dist/src/sanctions.js.map +1 -1
- package/dist/src/signalCounts.d.ts +37 -0
- package/dist/src/signalCounts.d.ts.map +1 -0
- package/dist/src/signalCounts.js +117 -0
- package/dist/src/signalCounts.js.map +1 -0
- package/dist/src/signalInert.d.ts +10 -0
- package/dist/src/signalInert.d.ts.map +1 -0
- package/dist/src/signalInert.js +28 -0
- package/dist/src/signalInert.js.map +1 -0
- package/dist/src/signalService.d.ts +101 -0
- package/dist/src/signalService.d.ts.map +1 -0
- package/dist/src/signalService.js +383 -0
- package/dist/src/signalService.js.map +1 -0
- package/dist/src/signals.d.ts +186 -0
- package/dist/src/signals.d.ts.map +1 -0
- package/dist/src/signals.js +361 -0
- package/dist/src/signals.js.map +1 -0
- package/dist/src/staffViews.d.ts +18 -0
- package/dist/src/staffViews.d.ts.map +1 -1
- package/dist/src/staffViews.js +14 -0
- package/dist/src/staffViews.js.map +1 -1
- package/dist/src/subjects.d.ts +2 -0
- package/dist/src/subjects.d.ts.map +1 -1
- package/dist/src/subjects.js +4 -0
- package/dist/src/subjects.js.map +1 -1
- package/dist/src/team.d.ts +27 -0
- package/dist/src/team.d.ts.map +1 -1
- package/dist/src/team.js +92 -4
- package/dist/src/team.js.map +1 -1
- package/dist/src/types.d.ts +254 -7
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js.map +1 -1
- package/package.json +2 -2
- package/src/ai/case.ts +6 -4
- package/src/ai/hash.ts +5 -2
- package/src/ai/prompt.ts +39 -2
- package/src/ai/service.ts +29 -14
- package/src/ai/types.ts +31 -2
- package/src/ai/worker.ts +20 -4
- package/src/appealService.ts +584 -0
- package/src/appeals.ts +256 -0
- package/src/audit.ts +18 -3
- package/src/chat.ts +109 -8
- package/src/chatwarden.ts +382 -27
- package/src/decide.ts +13 -7
- package/src/documents.ts +8 -3
- package/src/events.ts +23 -1
- package/src/freeze.ts +8 -0
- package/src/index.ts +52 -3
- package/src/ladder.ts +59 -1
- package/src/nameService.ts +255 -0
- package/src/names.ts +121 -0
- package/src/notices.ts +112 -14
- package/src/pace.ts +139 -0
- package/src/pacing.ts +242 -0
- package/src/policy.ts +125 -8
- package/src/profile.ts +115 -25
- package/src/profileError.ts +17 -0
- package/src/retention.ts +79 -3
- package/src/sanctions.ts +72 -9
- package/src/signalCounts.ts +133 -0
- package/src/signalInert.ts +31 -0
- package/src/signalService.ts +406 -0
- package/src/signals.ts +489 -0
- package/src/staffViews.ts +30 -0
- package/src/subjects.ts +5 -0
- package/src/team.ts +93 -5
- package/src/types.ts +275 -8
package/src/chatwarden.ts
CHANGED
|
@@ -23,7 +23,17 @@ import { dismissMany } from './dismissMany.js';
|
|
|
23
23
|
import type { DismissManyInput, DismissManyResult } from './dismissMany.js';
|
|
24
24
|
import { PolicyService } from './policy.js';
|
|
25
25
|
import type { PolicyPreview, PolicySaveContext, PolicySaveResult, PolicyState } from './policy.js';
|
|
26
|
-
import {
|
|
26
|
+
import { checkPace, mergePace } from './pace.js';
|
|
27
|
+
import { AppealService, hasAppealMethods } from './appealService.js';
|
|
28
|
+
import { NameService } from './nameService.js';
|
|
29
|
+
import type { NameCheckResult } from './names.js';
|
|
30
|
+
import type { AppealDecideResult, AppealDecision, AppealDetail, AppealFileResult, AppealPage, AppealStats, AppealSummary, PlayerAppeal } from './appeals.js';
|
|
31
|
+
import { createInertSignals } from './signalInert.js';
|
|
32
|
+
import type { SignalRuntime } from './signalService.js';
|
|
33
|
+
import { BUILTIN_SIGNAL_KINDS, checkSignalFeeds } from './signals.js';
|
|
34
|
+
import type { SignalCount, SignalInput, SignalKindView } from './signals.js';
|
|
35
|
+
import type { PaceSettings, ResolvedPace } from './pace.js';
|
|
36
|
+
import { ProfileError, resolveProfile } from './profile.js';
|
|
27
37
|
import type { ModerationProfile, PolicyLayer, PolicySection, PresetName, ProfanityConfig, ProfileOverrides, ResolvedProfile } from './profile.js';
|
|
28
38
|
import { MuteService } from './mutes.js';
|
|
29
39
|
import { NoticeService } from './notices.js';
|
|
@@ -40,6 +50,7 @@ import { StrikeService } from './strikes.js';
|
|
|
40
50
|
import {
|
|
41
51
|
blockedCountsByTerm,
|
|
42
52
|
blockedItems,
|
|
53
|
+
blockedNameItems,
|
|
43
54
|
listSanctionGroups,
|
|
44
55
|
reporterRecord,
|
|
45
56
|
sanctionsOfPerson,
|
|
@@ -49,6 +60,7 @@ import type { ReporterAccuracy } from './reporterAccuracy.js';
|
|
|
49
60
|
import type {
|
|
50
61
|
BlockedDays,
|
|
51
62
|
BlockedItem,
|
|
63
|
+
BlockedNameItem,
|
|
52
64
|
ReporterRecord,
|
|
53
65
|
SanctionGroupView,
|
|
54
66
|
SanctionListInput,
|
|
@@ -153,7 +165,8 @@ export interface ChatwardenOptions {
|
|
|
153
165
|
*
|
|
154
166
|
* Floors, checked at creation (and on every `purge(policy)`), each a `ProfileError` naming the field:
|
|
155
167
|
* `sanctionAfterEndMs` and `noticesMs` at least 90 days (the ladder and "My record" reach back that far),
|
|
156
|
-
* `auditMs` at least 90 days (default 365), `
|
|
168
|
+
* `auditMs` at least 90 days (default 365), `appealsMs` at least 90 days (default 365), `badFaithMs` at least
|
|
169
|
+
* `limits.reports.suspendWindowMs`. `appealStatementsMs` (default 90 days) and `blockedNamesMs` (default 30 days) may be 0. Every field
|
|
157
170
|
* must be a finite number (Infinity and NaN are refused). Not enforced, but `strikesMs` should be at least
|
|
158
171
|
* `limits.strikes.windowMs`, or strikes are deleted before the window that counts them closes. When you leave
|
|
159
172
|
* `badFaithMs` out it follows a longer suspension window.
|
|
@@ -204,6 +217,22 @@ export interface ChatwardenOptions {
|
|
|
204
217
|
* @experimental
|
|
205
218
|
*/
|
|
206
219
|
ai?: AiOptions;
|
|
220
|
+
/**
|
|
221
|
+
* Signals: what the game records about a player. The kinds, the guards and the feeds are in the profile (`profile.signals`); this
|
|
222
|
+
* holds the one hook the profile cannot. Signals need a store with the three signal methods (SQLite has them; the in-memory store has them
|
|
223
|
+
* through `withMemorySignals`): declaring kinds or feeds over a store without them is refused at creation, and the kit loads its signal
|
|
224
|
+
* service only for a store that has them.
|
|
225
|
+
* @experimental
|
|
226
|
+
*/
|
|
227
|
+
signals?: {
|
|
228
|
+
/**
|
|
229
|
+
* How old is this player's account, in days, from the account ids the kit has for them (the strings your game gave it as
|
|
230
|
+
* `RawWho.accountId`)? Return null or undefined when unknown. Called synchronously at record time for `by`, and only for a player with
|
|
231
|
+
* at least one account id; a throw reads as unknown (logged by error class). Without this hook the new-account guard is not used,
|
|
232
|
+
* whatever the profile says.
|
|
233
|
+
*/
|
|
234
|
+
accountAgeDays?: (accountIds: readonly string[]) => number | null | undefined;
|
|
235
|
+
};
|
|
207
236
|
}
|
|
208
237
|
|
|
209
238
|
/** The moderation kit as an adopter uses it. Nothing here returns an identifier meant for a player. */
|
|
@@ -226,6 +255,17 @@ export interface Chatwarden {
|
|
|
226
255
|
* Carries subject ids: staff channels only, never send to a player.
|
|
227
256
|
*/
|
|
228
257
|
subjectAt(roomId: string, seatId: string): SubjectId | null;
|
|
258
|
+
/**
|
|
259
|
+
* Pace this room differently from the defaults until it closes. Per field: absent inherits, `null` turns that check off, a value sets
|
|
260
|
+
* it. `null` instead of an object removes the override (`{}` is the same: nothing to override). A second call replaces the room's earlier
|
|
261
|
+
* override whole; it is not merged into it. The object is read once, so changing it afterwards changes nothing. Throws `ProfileError` for an invalid
|
|
262
|
+
* value (a setup mistake, not a hot-path call), and changes nothing when it does. In memory, this process only: `rooms.close(roomId)`
|
|
263
|
+
* drops it, and a game that runs several processes calls it in each process that serves the room. The override sits on top of the
|
|
264
|
+
* stored layer, which sits on top of the profile in code. @experimental
|
|
265
|
+
*/
|
|
266
|
+
setPace(roomId: string, pace: PaceSettings | null): void;
|
|
267
|
+
/** The pace in force for the room: the profile's (code, then the stored layer) with the room's override applied. Every field filled, `null` is off. @experimental */
|
|
268
|
+
pace(roomId: string): ResolvedPace;
|
|
229
269
|
};
|
|
230
270
|
chat: {
|
|
231
271
|
accept(roomId: string, seatId: string, text: string, opts?: { audience?: string[] }): ChatResult;
|
|
@@ -339,6 +379,13 @@ export interface Chatwarden {
|
|
|
339
379
|
list(q: { days: BlockedDays }): BlockedItem[];
|
|
340
380
|
/** Strikes per term id over the same window; a term with none is absent. */
|
|
341
381
|
countsByTerm(q: { days: BlockedDays }): Record<string, number>;
|
|
382
|
+
/**
|
|
383
|
+
* The blocked NAMES kept as evidence (`names.keepBlocked`) over the last `days` days (1, 7 or 30, else `RangeError`), newest first, at most
|
|
384
|
+
* 200: `{ id, at, person, name, termId, reason }`, the person a staff ref or null. Empty when none was kept, or the store keeps none. A name
|
|
385
|
+
* is a player's text and `person` a subject id: staff channels only, never send either to a player.
|
|
386
|
+
* @experimental
|
|
387
|
+
*/
|
|
388
|
+
names(q: { days: BlockedDays }): BlockedNameItem[];
|
|
342
389
|
};
|
|
343
390
|
/**
|
|
344
391
|
* The team workbench: soft claims on a person's case, take next, and who has a case open. Staff only; every `person` is
|
|
@@ -382,9 +429,14 @@ export interface Chatwarden {
|
|
|
382
429
|
* (see `cw.reports.reporterAccuracy`) and none of which has waited 24 hours (`REPORTER_RANK_LAPSE_MS`) is served after the ordinary
|
|
383
430
|
* ones, oldest first; it is never skipped, so a queue holding only such cases still serves them. One ordinary reporter, or no
|
|
384
431
|
* accuracy data (a store without `reporterOutcomes`), keeps a case normal. A non-boolean value is a `RangeError`.
|
|
385
|
-
*
|
|
432
|
+
*
|
|
433
|
+
* With `signalBoost` (default false: behaviour unchanged; use it when the queue signal feed, `feeds.queue`, is on), the scan stays oldest
|
|
434
|
+
* first but a case is claimed only when it is overdue (its oldest open report has waited 24 hours) or boosted (the person meets the
|
|
435
|
+
* feed's threshold); the first such case wins. If the queue, or the first 200 people, hold neither, the oldest free case is claimed as
|
|
436
|
+
* usual, so nothing is ever left out. A boosted case is never ranked down. A non-boolean value is a `RangeError`.
|
|
437
|
+
* @experimental (the `rankDownHabitual` and `signalBoost` filters)
|
|
386
438
|
*/
|
|
387
|
-
next(actor: string, filter?: { category?: ReportCategory; reason?: string | null; rankDownHabitual?: boolean }): NextCase | null;
|
|
439
|
+
next(actor: string, filter?: { category?: ReportCategory; reason?: string | null; rankDownHabitual?: boolean; signalBoost?: boolean }): NextCase | null;
|
|
388
440
|
/**
|
|
389
441
|
* `actor` has the person's case open now. A hint for 30 seconds (`VIEWING_TTL_MS`), in this process's memory only.
|
|
390
442
|
* Only a person with an open report is tracked (false otherwise, nothing recorded); one actor keeps at most 20 cases
|
|
@@ -463,12 +515,45 @@ export interface Chatwarden {
|
|
|
463
515
|
on: Subscribe;
|
|
464
516
|
names: {
|
|
465
517
|
/**
|
|
466
|
-
* May a player use this as a name (a handle, a table or deck name)?
|
|
467
|
-
* (`Zorbak_99` is caught, not only `zorbak`)
|
|
468
|
-
*
|
|
469
|
-
*
|
|
518
|
+
* May a player use this as a name (a handle, a table or deck name)? Synchronous, never echoes the name, never throws for a string (a
|
|
519
|
+
* non-string is still a TypeError). Reads it with the matcher's name rules (`Zorbak_99` is caught, not only `zorbak`); with
|
|
520
|
+
* `names.profanity` it also runs the profanity filter on the name and on the name with underscores and digits turned into spaces, and a
|
|
521
|
+
* hit is `name_profane` (a matcher hit wins). `rule` is the Community Rule the slur filter cites (`autoRestrictRule`) for both. No
|
|
522
|
+
* matcher, a matcher that fails (logged, class only) and a filter that fails (`chatwarden.names_filter_failed`) all let the name through.
|
|
523
|
+
*
|
|
524
|
+
* `opts.who` is the caller, as the doors take it. It is used ONLY to tie kept evidence to a person (found, never created); it never
|
|
525
|
+
* changes the answer. A blocked name is kept (`kit_blocked_names`) only when `names.keepBlocked` is on: at most 5 an hour per person
|
|
526
|
+
* (per `who`, or per name when there is none) and 200 an hour overall, in memory per process; past that the check still answers and
|
|
527
|
+
* nothing more is stored. An allowed name is never stored, and a name is never logged.
|
|
528
|
+
*/
|
|
529
|
+
check(text: string, opts?: { who?: RawWho }): NameCheckResult;
|
|
530
|
+
/**
|
|
531
|
+
* Would the matcher refuse this as a name? The evidence-free read for staff screens and routes (a list of handles): the matcher only,
|
|
532
|
+
* no profanity pass, nothing stored whatever `names.keepBlocked` says, no person looked up. False for no matcher, for a non-string and
|
|
533
|
+
* when the matcher throws (logged once a minute, class only). Never throws.
|
|
470
534
|
*/
|
|
471
|
-
|
|
535
|
+
flagged(text: string): boolean;
|
|
536
|
+
/**
|
|
537
|
+
* Ask a player to choose a new name. Writes one notice of kind `rename_required` (it names no name, no excerpt, no reason) and, after
|
|
538
|
+
* the write, tells the player's client and emits `rename.required`. Staff only. `{ ok: false, error: 'off' }` while `names.renames` is
|
|
539
|
+
* false (or the store cannot release a rename); `invalid` for a reason that is not 1 to 500 characters or a rule that is not an active
|
|
540
|
+
* integer rule; `not_found` for a person the kit does not hold; `pending` while a request is already waiting. `rule` defaults to the
|
|
541
|
+
* slur filter's (`autoRestrictRule`) and is shown to the player as a rule label. A store failure is logged (class only) and thrown.
|
|
542
|
+
* @experimental
|
|
543
|
+
*/
|
|
544
|
+
requireRename(input: { subject: SubjectId; actor: string; reason: string; rule?: number }): { ok: true; noticeId: string } | { ok: false; error: 'off' | 'not_found' | 'pending' | 'invalid' };
|
|
545
|
+
/** True while the person has a rename request they have not been released from. For the game, to hold a player at a rename screen. Never creates a person. @experimental */
|
|
546
|
+
pendingRename(who: RawWho): boolean;
|
|
547
|
+
/** The game calls this once the player has a new name. Withdraws their pending rename notices. True when it withdrew one. The kit never learns the name. @experimental */
|
|
548
|
+
renamed(who: RawWho): boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Whether `requireRename` can work right now: `names.renames` is on AND the store can release a rename (the test `requireRename` applies
|
|
551
|
+
* first). A live read. For a staff screen, so it never offers a rename that always answers `off`.
|
|
552
|
+
* @experimental
|
|
553
|
+
*/
|
|
554
|
+
renamesEnabled(): boolean;
|
|
555
|
+
/** A person's rename requests, newest first, at most 20: `{ at, pending }` each. No reason, actor, rule or name. Staff only: never send to a player. @experimental */
|
|
556
|
+
renamesOf(subject: SubjectId): Array<{ at: number; pending: boolean }>;
|
|
472
557
|
};
|
|
473
558
|
/**
|
|
474
559
|
* The AI read and recommend service. Always present: without an `ai` option (or at level 0) it answers as if there were no AI. A
|
|
@@ -477,6 +562,35 @@ export interface Chatwarden {
|
|
|
477
562
|
* @experimental
|
|
478
563
|
*/
|
|
479
564
|
ai: AiFacade;
|
|
565
|
+
/**
|
|
566
|
+
* Signals: what the game records about a player (muted by others, kicked, left mid-game), counted by distinct source. A signal never
|
|
567
|
+
* acts: it is read only where a profile rule says so (the Person page record, the ladder suggestion, the AI read, the queue order).
|
|
568
|
+
* Staff-side data: never send any of this to a player.
|
|
569
|
+
* @experimental
|
|
570
|
+
*/
|
|
571
|
+
signals: {
|
|
572
|
+
/**
|
|
573
|
+
* Record one signal. Synchronous, fenced, never throws: it returns false (and logs `chatwarden.signal_refused` with a reason code,
|
|
574
|
+
* at most once a minute) for an undeclared or malformed kind, a party it cannot resolve (an unknown subject id, or a `RawWho` the kit
|
|
575
|
+
* has never seen: nobody is created), `subject` equal to `by` (also across a merge), a time out of range, the per-source cap, a
|
|
576
|
+
* store without signals, or a store failure. True means a row was written. One small write: record events, not every chat line.
|
|
577
|
+
*/
|
|
578
|
+
record(input: SignalInput): boolean;
|
|
579
|
+
/**
|
|
580
|
+
* The counts for a person now: one entry per declared kind that has at least one source in the window (default 30 days, held to
|
|
581
|
+
* the retention and to 90), aliases folded. Never throws; a store failure reads []. Never send to a player.
|
|
582
|
+
*/
|
|
583
|
+
counts(subject: SubjectId, opts?: { windowDays?: number; kinds?: readonly string[] }): SignalCount[];
|
|
584
|
+
/** The declared kinds, built-ins included, for building a form. */
|
|
585
|
+
kinds(): SignalKindView[];
|
|
586
|
+
/**
|
|
587
|
+
* Which of these people meet the queue feed (`feeds.queue`), as canonical ids, from one grouped read. Empty, with no store read,
|
|
588
|
+
* when the feed is off. Never throws.
|
|
589
|
+
*/
|
|
590
|
+
boosted(people: readonly SubjectId[]): Set<SubjectId>;
|
|
591
|
+
/** The lines the Person page record shows (`feeds.record`: its kinds and window). `[]` when the feed is off. Never throws. */
|
|
592
|
+
forRecord(subject: SubjectId): SignalCount[];
|
|
593
|
+
};
|
|
480
594
|
/** The registry in use (the one given, or the starter rules for the profile). Retired rules stay listed. */
|
|
481
595
|
rules: CommunityRules;
|
|
482
596
|
/**
|
|
@@ -538,6 +652,55 @@ export interface Chatwarden {
|
|
|
538
652
|
/** True while the person has a warning they have not acknowledged. */
|
|
539
653
|
pendingWarning(who: RawWho): boolean;
|
|
540
654
|
};
|
|
655
|
+
/**
|
|
656
|
+
* Appeals (0.1.9, `profile.appeals`, off until turned on). The player side takes the same `RawWho` as `notices` and FINDS the person
|
|
657
|
+
* (never creates one); every answer is a reason or a rule number, never an identifier, a staff ref or a reason a moderator gave.
|
|
658
|
+
* @experimental
|
|
659
|
+
*/
|
|
660
|
+
appeals: {
|
|
661
|
+
/** Whether appeals are on right now: the profile in force says so (a live read) and the store can keep them. */
|
|
662
|
+
enabled(): boolean;
|
|
663
|
+
/**
|
|
664
|
+
* File an appeal from one of the caller's own sanction notices, with a statement of at most `APPEAL_STATEMENT_MAX` (1000) characters.
|
|
665
|
+
* Checks in this order: off, not_found, not_appealable, statement_invalid, already_appealed, rate. One store transaction; a refusal
|
|
666
|
+
* writes nothing. The statement is cleaned first (`normalizeStatement`) and refused, not cut, over the cap. Never throws for a bad
|
|
667
|
+
* input; a store failure is logged (`chatwarden.appeal_failed`, the error class only) and answers `not_found`. `appeal.created` is
|
|
668
|
+
* emitted after the commit.
|
|
669
|
+
*/
|
|
670
|
+
file(who: RawWho, input: { noticeId: string; statement: string }): AppealFileResult;
|
|
671
|
+
/** The caller's own appeals, newest first, at most 50, without any that was made moot. Empty for an unknown person or with appeals off. */
|
|
672
|
+
mine(who: RawWho): PlayerAppeal[];
|
|
673
|
+
/**
|
|
674
|
+
* Decide an open appeal: `uphold` (the sanction stands), `reduce` (to a lighter kind, or the same kind and shorter, keeping the original
|
|
675
|
+
* start so the ladder does not restart, never ending later than the original) or `revoke`. A moderator may not decide an appeal of
|
|
676
|
+
* their own decision unless `appeals.allowSelfReview` is on (`same_decider`); an automatic sanction has no such decider. `reason` is
|
|
677
|
+
* private (1 to 500 characters). One transaction; the player is told through a notice; `appeal.decided` is emitted after the commit.
|
|
678
|
+
* Staff-side: the permission and the audit row belong to the route. A store failure rejects and writes nothing.
|
|
679
|
+
*/
|
|
680
|
+
decide(input: AppealDecision): Promise<AppealDecideResult>;
|
|
681
|
+
/**
|
|
682
|
+
* The inbox, oldest first: `open` (default), `decided` or `all`; `limit` 1 to 200 (default 50); an opaque `cursor`. A summary carries a
|
|
683
|
+
* staff ref and never the statement (`statementFlagged` says whether it trips the term filter). `RangeError` for a bad query. Empty with
|
|
684
|
+
* appeals off. Carries subject ids: staff channels only, never send to a player.
|
|
685
|
+
*/
|
|
686
|
+
list(q: { status?: 'open' | 'decided' | 'all'; limit?: number; cursor?: string | null }): AppealPage;
|
|
687
|
+
/** One appeal in full, the statement included (null once purged), or null for an unknown id. The route audits this read. Staff only. */
|
|
688
|
+
get(id: string): AppealDetail | null;
|
|
689
|
+
/** How many appeals are waiting. */
|
|
690
|
+
openCount(): number;
|
|
691
|
+
/**
|
|
692
|
+
* The per-rule counts over the last 30, 90 (default) or 365 days. The rate is revoked appeals over sanctions given, null below 10
|
|
693
|
+
* sanctions; a reduction is `lightened`, shown beside the rate and never in it. `RangeError` for another window.
|
|
694
|
+
*/
|
|
695
|
+
stats(q?: { days?: 30 | 90 | 365 }): AppealStats;
|
|
696
|
+
/**
|
|
697
|
+
* One person's appeals (across their merged subjects) as summaries, newest first, at most 50; a moot appeal is left out. For the person's
|
|
698
|
+
* page. Still listed after appeals are switched off (what was filed stays visible until retention removes it); empty for a store that cannot keep
|
|
699
|
+
* appeals or a person the kit does not hold. Carries a staff ref and never the statement: staff channels only.
|
|
700
|
+
* @experimental
|
|
701
|
+
*/
|
|
702
|
+
forPerson(subject: SubjectId): AppealSummary[];
|
|
703
|
+
};
|
|
541
704
|
/**
|
|
542
705
|
* Decide a report: close it, write each sanction and its notice, and tell the people involved, in one
|
|
543
706
|
* transaction. Idempotent (the same decision again is a replay). A malformed or disallowed decision resolves
|
|
@@ -612,6 +775,13 @@ export interface Chatwarden {
|
|
|
612
775
|
people: {
|
|
613
776
|
canonical(subject: SubjectId): SubjectId;
|
|
614
777
|
aliases(subject: SubjectId): SubjectId[];
|
|
778
|
+
/**
|
|
779
|
+
* The account ids the kit holds for this person across their merged aliases, sorted: exactly the strings the game passed as
|
|
780
|
+
* `RawWho.accountId` (no client key, no IP, no hash). A guest has none; so does an unknown id. For the game to find the player to rename
|
|
781
|
+
* after `rename.required`. Server side only: never send to a player.
|
|
782
|
+
* @experimental
|
|
783
|
+
*/
|
|
784
|
+
accountIds(subject: SubjectId): string[];
|
|
615
785
|
};
|
|
616
786
|
/**
|
|
617
787
|
* The Discord feed's thread map (`@chatwarden/discord`): the forum thread kept per person (`kit_discord_threads`). A
|
|
@@ -642,11 +812,19 @@ export interface Chatwarden {
|
|
|
642
812
|
* The profanity filter for the profile, or undefined. Mode `allow` builds nothing; a ready filter wins over the
|
|
643
813
|
* package; a package that throws fails creation and one that returns a non-filter is a TypeError.
|
|
644
814
|
*/
|
|
815
|
+
/** Does the store keep signals (all three optional methods)? */
|
|
816
|
+
const storeKeepsSignals = (s: Store): boolean => typeof s.insertSignal === 'function' && typeof s.listSignalSources === 'function' && typeof s.purgeSignals === 'function';
|
|
817
|
+
|
|
645
818
|
function buildProfanityFilter(opts: ChatwardenOptions, config: ProfanityConfig): ProfanityFilter | undefined {
|
|
646
819
|
if (config.mode === 'allow') return undefined;
|
|
647
820
|
if (opts.profanity !== undefined) return opts.profanity;
|
|
648
821
|
if (opts.profanityPackage === undefined) return undefined;
|
|
649
|
-
|
|
822
|
+
return buildPackageFilter(opts.profanityPackage, config);
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
/** The filter a profanity package builds from the resolved config; a non-filter is a TypeError. */
|
|
826
|
+
function buildPackageFilter(pkg: NonNullable<ChatwardenOptions['profanityPackage']>, config: ProfanityConfig): ProfanityFilter {
|
|
827
|
+
const built = pkg.createProfanityFilter(config);
|
|
650
828
|
if (typeof built !== 'object' || built === null || typeof built.apply !== 'function') {
|
|
651
829
|
throw new TypeError('profanityPackage.createProfanityFilter must return a filter with an apply(text) method');
|
|
652
830
|
}
|
|
@@ -682,6 +860,28 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
682
860
|
badFaithMs: givenRetention.badFaithMs ?? Math.max(RETENTION_DEFAULTS.badFaithMs, limits.reports.suspendWindowMs),
|
|
683
861
|
};
|
|
684
862
|
checkRetentionFloors(retentionPolicy, limits.reports.suspendWindowMs);
|
|
863
|
+
// A feed window longer than the signal retention could never be met (rows older than that are deleted): refuse it in code too.
|
|
864
|
+
checkSignalFeeds(baseProfile.signals.feeds, baseProfile.signals.kinds, { signalsMs: retentionPolicy.signalsMs ?? RETENTION_DEFAULTS.signalsMs }, 'profile.signals.feeds');
|
|
865
|
+
// Declaring kinds or feeds is an explicit opt-in that a store without the signal methods would silently turn into nothing: refuse it.
|
|
866
|
+
// (Only the built-in `flood_triggered` and pacing: nothing declared, so the kit starts and skips that record, logged once.)
|
|
867
|
+
const declaresSignals =
|
|
868
|
+
Object.keys(baseProfile.signals.feeds).length > 0 ||
|
|
869
|
+
Object.keys(baseProfile.signals.kinds).some((id) => {
|
|
870
|
+
const k = baseProfile.signals.kinds[id]!;
|
|
871
|
+
const builtin = Object.hasOwn(BUILTIN_SIGNAL_KINDS, id) ? BUILTIN_SIGNAL_KINDS[id as 'flood_triggered'] : undefined;
|
|
872
|
+
return builtin === undefined || builtin.label !== k.label || k.weight !== 1;
|
|
873
|
+
});
|
|
874
|
+
if (declaresSignals && !storeKeepsSignals(opts.store)) {
|
|
875
|
+
throw new Error(
|
|
876
|
+
'createChatwarden: the profile declares signal kinds or feeds, but the store has no signal methods (insertSignal, listSignalSources, purgeSignals); use the memory or SQLite store, or leave "signals" out of the profile',
|
|
877
|
+
);
|
|
878
|
+
}
|
|
879
|
+
if (opts.signals?.accountAgeDays !== undefined && typeof opts.signals.accountAgeDays !== 'function') {
|
|
880
|
+
throw new TypeError('createChatwarden: signals.accountAgeDays must be a function');
|
|
881
|
+
}
|
|
882
|
+
// The signal service (and the counting under it) is loaded only for a store that can keep signals, so a bundler can leave it out of a build
|
|
883
|
+
// that never has one (the in-memory store has the methods only through `withMemorySignals`). Without it `cw.signals` is inert.
|
|
884
|
+
const signalModule = storeKeepsSignals(opts.store) ? await import('./signalService.js') : undefined;
|
|
685
885
|
const purgeEveryMs = everyMs ?? DEFAULT_PURGE_EVERY_MS;
|
|
686
886
|
if (opts.retention !== false && (!Number.isFinite(purgeEveryMs) || purgeEveryMs <= 0)) {
|
|
687
887
|
throw new Error('createChatwarden: retention.everyMs must be a positive finite number');
|
|
@@ -718,7 +918,7 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
718
918
|
await mutes.load();
|
|
719
919
|
await strikes.load();
|
|
720
920
|
// The stored edits to the profile. Read last, so a store that fails here has not left anything half built.
|
|
721
|
-
const policy = new PolicyService({ store, clock, logger, base: baseProfile });
|
|
921
|
+
const policy = new PolicyService({ store, clock, logger, base: baseProfile, signalsMs: () => retentionPolicy.signalsMs ?? RETENTION_DEFAULTS.signalsMs, chatRate: limits.chatRate, appealsKept: hasAppealMethods(store) });
|
|
722
922
|
policy.load();
|
|
723
923
|
|
|
724
924
|
// ONE notice service for the whole kit: chat (the automatic timeout), the doors (the refusal's pointer) and
|
|
@@ -734,6 +934,30 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
734
934
|
notify: typeof platformNotify === 'function' ? (who, event) => platformNotify.call(platform, who, event) : undefined,
|
|
735
935
|
});
|
|
736
936
|
|
|
937
|
+
/** The signal service, set once `personOf` exists (the chat path above it only calls it later, never during creation). */
|
|
938
|
+
const signalRef: { service?: SignalRuntime } = {};
|
|
939
|
+
|
|
940
|
+
// Room overrides of the pace: this process only, dropped by `rooms.close`. Each is the validated sparse override as given (a field
|
|
941
|
+
// left out inherits), kept as a frozen copy so the caller's object cannot change it later.
|
|
942
|
+
const paceOverrides = new Map<string, Readonly<PaceSettings>>();
|
|
943
|
+
/** The merged pace of a room with an override, with the profile pace it was merged onto: valid while that object is the one in force. */
|
|
944
|
+
const paceMerged = new Map<string, { base: ResolvedPace; merged: ResolvedPace }>();
|
|
945
|
+
/**
|
|
946
|
+
* The pace in force for a room: the override over the profile's (the layer over the code). A room without an override gets the
|
|
947
|
+
* profile's own object; one with an override is merged once per change of the profile's pace (it is a new object on every layer
|
|
948
|
+
* change), not once per line.
|
|
949
|
+
*/
|
|
950
|
+
const paceOf = (roomId: string): ResolvedPace => {
|
|
951
|
+
const base = policy.profileNow().pace;
|
|
952
|
+
const over = paceOverrides.get(roomId);
|
|
953
|
+
if (over === undefined) return base;
|
|
954
|
+
const cached = paceMerged.get(roomId);
|
|
955
|
+
if (cached !== undefined && cached.base === base) return cached.merged;
|
|
956
|
+
const merged = mergePace(base, over);
|
|
957
|
+
paceMerged.set(roomId, { base, merged });
|
|
958
|
+
return merged;
|
|
959
|
+
};
|
|
960
|
+
|
|
737
961
|
const chat = new ChatService({
|
|
738
962
|
roster,
|
|
739
963
|
buffer,
|
|
@@ -755,6 +979,21 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
755
979
|
notices,
|
|
756
980
|
autoRestrictRule,
|
|
757
981
|
limits: { maxLength: limits.chatMaxLength, rate: limits.chatRate },
|
|
982
|
+
pace: {
|
|
983
|
+
settings: paceOf,
|
|
984
|
+
canonical: (subject) => subjects.canonical(subject),
|
|
985
|
+
// A flood trip records the built-in kind, deferred so the verdict is returned first. `flood` never throws and logs its own
|
|
986
|
+
// refusals; a room id the signal rules do not accept is left out (the trip is then a day source, not dropped).
|
|
987
|
+
onFlood: ({ roomId, subject }) => {
|
|
988
|
+
queueMicrotask(() => {
|
|
989
|
+
try {
|
|
990
|
+
signalRef.service?.flood(subject, roomId);
|
|
991
|
+
} catch (err) {
|
|
992
|
+
safeWarn(logger, 'chatwarden.pace_failed', { error: err instanceof Error ? err.name : typeof err });
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
},
|
|
996
|
+
},
|
|
758
997
|
});
|
|
759
998
|
const reports = new ReportService({
|
|
760
999
|
roster,
|
|
@@ -788,6 +1027,24 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
788
1027
|
const ids = hashWho(hasher, who);
|
|
789
1028
|
return subjects.lookup({ clientKey: ids.clientKey, accountId: ids.accountId, ipHash: null });
|
|
790
1029
|
};
|
|
1030
|
+
// Appeals. Turning them on in code (the profile or its overrides) over a store that cannot keep them is a plain mistake, refused here
|
|
1031
|
+
// before anything is started. A stored layer that does it is data, not code: the policy keeps appeals off and warns (see PolicyService).
|
|
1032
|
+
if (baseProfile.appeals.enabled && !hasAppealMethods(store)) {
|
|
1033
|
+
throw new Error('createChatwarden: appeals are enabled, but this store has no appeal methods (SqliteStore has them from schema 22; the in-memory store needs its opt-in appeals wrapper)');
|
|
1034
|
+
}
|
|
1035
|
+
/** The one answer to "does a moot or a decision clear the statement at once": the retention the kit was created with. */
|
|
1036
|
+
const clearAppealStatements = (): boolean => (retentionPolicy.appealStatementsMs ?? RETENTION_DEFAULTS.appealStatementsMs) === 0;
|
|
1037
|
+
signalRef.service = signalModule === undefined ? createInertSignals(logger, () => policy.profileNow().signals) : new signalModule.SignalService({
|
|
1038
|
+
store,
|
|
1039
|
+
clock,
|
|
1040
|
+
logger,
|
|
1041
|
+
subjects,
|
|
1042
|
+
personOf,
|
|
1043
|
+
settings: () => policy.profileNow().signals,
|
|
1044
|
+
signalsMs: () => retentionPolicy.signalsMs ?? RETENTION_DEFAULTS.signalsMs,
|
|
1045
|
+
...(opts.signals?.accountAgeDays === undefined ? {} : { accountAgeDays: opts.signals.accountAgeDays }),
|
|
1046
|
+
});
|
|
1047
|
+
const signals = signalRef.service;
|
|
791
1048
|
/** A player-facing read: a store failure is logged (class only) and reads as `fallback`. */
|
|
792
1049
|
const forPlayer = <T>(who: RawWho, fallback: T, read: (subject: SubjectId) => T): T => {
|
|
793
1050
|
try {
|
|
@@ -892,6 +1149,7 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
892
1149
|
clock,
|
|
893
1150
|
reasons: () => policy.profileNow().reporting.reasons,
|
|
894
1151
|
accuracy: (people) => reporterAccuracyFor(store, subjects, people, clock.now()),
|
|
1152
|
+
boosted: (people) => signals.boosted(people),
|
|
895
1153
|
});
|
|
896
1154
|
const reasonBook = new ReasonBook(store);
|
|
897
1155
|
|
|
@@ -910,12 +1168,71 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
910
1168
|
subscribe: bus.on,
|
|
911
1169
|
audit: (input) => audit.record(input),
|
|
912
1170
|
exampleRetentionMs: () => retentionPolicy.aiExamplesMs ?? RETENTION_DEFAULTS.aiExamplesMs,
|
|
1171
|
+
// The counts about the reported person the feed allows (`feeds.ai`), as label, polarity, distinct and window: nothing else leaves.
|
|
1172
|
+
// The rules cautioned for by the appeals the moderators lost (revokes only), as bands and rule numbers: never a rate, a count or a person.
|
|
1173
|
+
cautions: () => appealService.cautions(),
|
|
1174
|
+
signals: (subject) => signals.forAi(subject).map((c) => ({ label: c.label, polarity: c.polarity, distinct: c.distinct, windowDays: c.windowDays })),
|
|
913
1175
|
});
|
|
914
1176
|
aiRef.service = aiService;
|
|
915
1177
|
const ai: AiFacade = aiService ?? createInertAi();
|
|
1178
|
+
const appealService = new AppealService({
|
|
1179
|
+
store,
|
|
1180
|
+
subjects,
|
|
1181
|
+
notices,
|
|
1182
|
+
clock,
|
|
1183
|
+
logger,
|
|
1184
|
+
settings: () => policy.profileNow().appeals,
|
|
1185
|
+
personOf,
|
|
1186
|
+
emit: (event) => bus.emit(event),
|
|
1187
|
+
matcher: opts.matcher,
|
|
1188
|
+
index: sanctions,
|
|
1189
|
+
clearStatements: clearAppealStatements,
|
|
1190
|
+
// A granted appeal marks the original decision reversed in the casebook; with no AI this is the inert facade and does nothing.
|
|
1191
|
+
// A REVOKE teaches the opposite sign and counts as a false positive; a REDUCE only keeps the decision from teaching (the rule applied).
|
|
1192
|
+
onGranted: (appeal, outcome) => void (outcome === 'revoke' ? ai.markReversed(appeal.reportId as string, { corrective: true }) : ai.markReversed(appeal.reportId as string)),
|
|
1193
|
+
});
|
|
1194
|
+
|
|
1195
|
+
// Names. The profanity filter for a name is the kit's own when the profile has one; otherwise (a profile that allows swearing in chat) it is
|
|
1196
|
+
// built from the package on first use, so `names.profanity` works whatever the chat profile does with swearing. A package that cannot build
|
|
1197
|
+
// one fails once and is remembered: the name check lets names through and logs the class.
|
|
1198
|
+
let nameFilter: { filter: ProfanityFilter | undefined } | { error: unknown } | undefined;
|
|
1199
|
+
const filterForNames = (): ProfanityFilter | undefined => {
|
|
1200
|
+
if (profanity !== undefined) return profanity;
|
|
1201
|
+
if (nameFilter === undefined) {
|
|
1202
|
+
try {
|
|
1203
|
+
nameFilter = { filter: opts.profanity ?? (opts.profanityPackage === undefined ? undefined : buildPackageFilter(opts.profanityPackage, baseProfile.profanity)) };
|
|
1204
|
+
} catch (error) {
|
|
1205
|
+
nameFilter = { error };
|
|
1206
|
+
}
|
|
1207
|
+
}
|
|
1208
|
+
if ('error' in nameFilter) throw nameFilter.error;
|
|
1209
|
+
return nameFilter.filter;
|
|
1210
|
+
};
|
|
1211
|
+
const nameService = new NameService({
|
|
1212
|
+
store,
|
|
1213
|
+
clock,
|
|
1214
|
+
logger,
|
|
1215
|
+
hasher,
|
|
1216
|
+
rule: autoRestrictRule,
|
|
1217
|
+
matcher: opts.matcher,
|
|
1218
|
+
settings: () => policy.profileNow().names,
|
|
1219
|
+
filter: filterForNames,
|
|
1220
|
+
personOf,
|
|
1221
|
+
notices,
|
|
1222
|
+
subjects,
|
|
1223
|
+
rules,
|
|
1224
|
+
emit: (event) => bus.emit(event),
|
|
1225
|
+
});
|
|
916
1226
|
|
|
917
1227
|
return {
|
|
918
1228
|
ai,
|
|
1229
|
+
signals: {
|
|
1230
|
+
record: (input) => signals.record(input),
|
|
1231
|
+
counts: (subject, o) => signals.counts(subject, o),
|
|
1232
|
+
kinds: () => signals.kinds(),
|
|
1233
|
+
boosted: (people) => signals.boosted(people),
|
|
1234
|
+
forRecord: (subject) => signals.forRecord(subject),
|
|
1235
|
+
},
|
|
919
1236
|
rooms: {
|
|
920
1237
|
seat,
|
|
921
1238
|
seatConnection: (roomId, seatId, ctx, handle, tags) => {
|
|
@@ -927,11 +1244,29 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
927
1244
|
close: (roomId) => {
|
|
928
1245
|
roster.close(roomId);
|
|
929
1246
|
buffer.drop(roomId);
|
|
1247
|
+
paceOverrides.delete(roomId);
|
|
1248
|
+
paceMerged.delete(roomId);
|
|
1249
|
+
chat.dropPaceRoom(roomId);
|
|
930
1250
|
},
|
|
931
1251
|
subjectAt: (roomId, seatId) => {
|
|
932
1252
|
const subject = roster.occupant(roomId, seatId)?.subject ?? null;
|
|
933
1253
|
return subject === null ? null : subjects.canonical(subject);
|
|
934
1254
|
},
|
|
1255
|
+
setPace: (roomId, pace) => {
|
|
1256
|
+
if (typeof roomId !== 'string' || roomId === '') throw new ProfileError('roomId', 'must be a non-empty string');
|
|
1257
|
+
paceMerged.delete(roomId);
|
|
1258
|
+
if (pace === null) {
|
|
1259
|
+
paceOverrides.delete(roomId);
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
// The caller's object is read once, into a validated snapshot of the fields it gave (a field left out inherits); that
|
|
1263
|
+
// snapshot is what is kept, so nothing about it can change after the check.
|
|
1264
|
+
const kept = checkPace(pace);
|
|
1265
|
+
if (kept.burst !== undefined && kept.burst !== null) Object.freeze(kept.burst);
|
|
1266
|
+
if (Object.keys(kept).length === 0) paceOverrides.delete(roomId);
|
|
1267
|
+
else paceOverrides.set(roomId, Object.freeze(kept));
|
|
1268
|
+
},
|
|
1269
|
+
pace: (roomId) => paceOf(roomId),
|
|
935
1270
|
},
|
|
936
1271
|
chat: {
|
|
937
1272
|
accept: (roomId, seatId, text, o) => chat.accept(roomId, seatId, text, o),
|
|
@@ -987,6 +1322,7 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
987
1322
|
blocked: {
|
|
988
1323
|
list: (q) => blockedItems(store, subjects, q?.days, clock.now()),
|
|
989
1324
|
countsByTerm: (q) => blockedCountsByTerm(store, q?.days, clock.now()),
|
|
1325
|
+
names: (q) => blockedNameItems(store, subjects, q?.days, clock.now()),
|
|
990
1326
|
},
|
|
991
1327
|
cases: {
|
|
992
1328
|
holder: (person) => desk.holder(person),
|
|
@@ -1037,7 +1373,12 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
1037
1373
|
revoke: async (groupId, actor, reason) => {
|
|
1038
1374
|
// One instant for the stored revokedAt and the event, so a consumer correlating the two sees the same time.
|
|
1039
1375
|
const at = clock.now();
|
|
1040
|
-
const { revoked } = await revokeAndWithdraw(store, groupId, actor, reason, {
|
|
1376
|
+
const { revoked } = await revokeAndWithdraw(store, groupId, actor, reason, {
|
|
1377
|
+
notices,
|
|
1378
|
+
clock: { now: () => at },
|
|
1379
|
+
index: sanctions,
|
|
1380
|
+
clearAppealStatements,
|
|
1381
|
+
});
|
|
1041
1382
|
if (revoked) {
|
|
1042
1383
|
try {
|
|
1043
1384
|
const code = store.sanctionRefCode(groupId);
|
|
@@ -1070,18 +1411,13 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
1070
1411
|
},
|
|
1071
1412
|
on: bus.on,
|
|
1072
1413
|
names: {
|
|
1073
|
-
check: (text) =>
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
} catch (err) {
|
|
1081
|
-
safeWarn(logger, 'chatwarden.names_matcher_failed', { error: err instanceof Error ? err.name : typeof err });
|
|
1082
|
-
return { ok: true };
|
|
1083
|
-
}
|
|
1084
|
-
},
|
|
1414
|
+
check: (text, o) => nameService.check(text, o),
|
|
1415
|
+
flagged: (text) => nameService.flagged(text),
|
|
1416
|
+
requireRename: (input) => nameService.requireRename(input),
|
|
1417
|
+
pendingRename: (who) => nameService.pendingRename(who),
|
|
1418
|
+
renamed: (who) => nameService.renamed(who),
|
|
1419
|
+
renamesEnabled: () => nameService.renamesEnabled(),
|
|
1420
|
+
renamesOf: (subject) => nameService.renamesOf(subject),
|
|
1085
1421
|
},
|
|
1086
1422
|
rules,
|
|
1087
1423
|
get profile() {
|
|
@@ -1110,11 +1446,26 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
1110
1446
|
record: (who) => forPlayer<PlayerNotice[]>(who, [], (s) => notices.record(s)),
|
|
1111
1447
|
pendingWarning: (who) => forPlayer(who, false, (s) => notices.pendingWarning(s)),
|
|
1112
1448
|
},
|
|
1449
|
+
appeals: {
|
|
1450
|
+
enabled: () => appealService.enabled(),
|
|
1451
|
+
file: (who, input) => appealService.file(who, input),
|
|
1452
|
+
mine: (who) => appealService.mine(who),
|
|
1453
|
+
decide: (input) => appealService.decide(input),
|
|
1454
|
+
list: (q) => appealService.list(q),
|
|
1455
|
+
get: (id) => appealService.get(id),
|
|
1456
|
+
openCount: () => appealService.openCount(),
|
|
1457
|
+
stats: (q) => appealService.stats(q),
|
|
1458
|
+
forPerson: (subject) => appealService.forPerson(subject),
|
|
1459
|
+
},
|
|
1113
1460
|
decide: (input) => decideAnnounced(input),
|
|
1114
1461
|
history: (subject) => historyOf(store, subjects, subject, clock.now()),
|
|
1115
1462
|
suggest: (subject, level, rule, context) => {
|
|
1116
1463
|
const now = clock.now();
|
|
1117
|
-
|
|
1464
|
+
// The signal hits are the kit's to compute: a list the caller passes is dropped, the real one set when a ladder rule is met.
|
|
1465
|
+
const { signals: _ignored, ...given } = (context ?? {}) as SuggestContext;
|
|
1466
|
+
void _ignored;
|
|
1467
|
+
const hits = signals.ladderHits(subject);
|
|
1468
|
+
return suggest(policy.profileNow(), historyOf(store, subjects, subject, now), level, rule, now, hits.length === 0 ? given : { ...given, signals: hits });
|
|
1118
1469
|
},
|
|
1119
1470
|
gaps: {
|
|
1120
1471
|
list: () =>
|
|
@@ -1146,15 +1497,19 @@ export async function createChatwarden(opts: ChatwardenOptions): Promise<Chatwar
|
|
|
1146
1497
|
people: {
|
|
1147
1498
|
canonical: (subject) => subjects.canonical(subject),
|
|
1148
1499
|
aliases: (subject) => subjects.aliasesOf(subject),
|
|
1500
|
+
accountIds: (subject) => (typeof subject === 'string' ? subjects.identifiersOf(subject).accounts : []),
|
|
1149
1501
|
},
|
|
1150
1502
|
discordThreads: {
|
|
1151
1503
|
get: (subject) => store.transaction(() => store.getDiscordThread(subject)),
|
|
1152
1504
|
put: (row) => store.transaction(() => store.putDiscordThread(row)),
|
|
1153
1505
|
},
|
|
1154
|
-
purge: async (
|
|
1506
|
+
purge: async (override) => {
|
|
1155
1507
|
const merged: Partial<RetentionPolicy> = { ...retentionPolicy };
|
|
1156
|
-
for (const [k, v] of Object.entries(
|
|
1508
|
+
for (const [k, v] of Object.entries(override ?? {})) if (v !== undefined) (merged as Record<string, unknown>)[k] = v;
|
|
1157
1509
|
checkRetentionFloors(merged, limits.reports.suspendWindowMs);
|
|
1510
|
+
// A feed window longer than the signal retention could never be met: refuse the purge that would make it so, deleting nothing.
|
|
1511
|
+
const { kinds, feeds } = policy.profileNow().signals;
|
|
1512
|
+
checkSignalFeeds(feeds, kinds, { signalsMs: merged.signalsMs ?? RETENTION_DEFAULTS.signalsMs }, 'profile.signals.feeds');
|
|
1158
1513
|
return await purge(store, clock.now(), merged);
|
|
1159
1514
|
},
|
|
1160
1515
|
ready: () => {
|