@chatwarden/core 0.1.8 → 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 +184 -5
- package/dist/src/ai/case.d.ts +2 -1
- 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 +1 -1
- package/dist/src/ai/hash.js +3 -3
- package/dist/src/ai/hash.js.map +1 -1
- package/dist/src/ai/prompt.d.ts +8 -1
- package/dist/src/ai/prompt.d.ts.map +1 -1
- package/dist/src/ai/prompt.js +20 -1
- package/dist/src/ai/prompt.js.map +1 -1
- package/dist/src/ai/service.d.ts +16 -5
- package/dist/src/ai/service.d.ts.map +1 -1
- package/dist/src/ai/service.js +12 -7
- package/dist/src/ai/service.js.map +1 -1
- package/dist/src/ai/types.d.ts +17 -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 +5 -0
- package/dist/src/ai/worker.d.ts.map +1 -1
- package/dist/src/ai/worker.js +9 -2
- 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/chatwarden.d.ts +129 -9
- package/dist/src/chatwarden.d.ts.map +1 -1
- package/dist/src/chatwarden.js +94 -19
- 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 +3 -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/index.d.ts +9 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +5 -2
- package/dist/src/index.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/policy.d.ts +9 -0
- package/dist/src/policy.d.ts.map +1 -1
- package/dist/src/policy.js +20 -2
- package/dist/src/policy.js.map +1 -1
- package/dist/src/profile.d.ts +23 -1
- package/dist/src/profile.d.ts.map +1 -1
- package/dist/src/profile.js +14 -2
- package/dist/src/profile.js.map +1 -1
- package/dist/src/retention.d.ts +31 -1
- package/dist/src/retention.d.ts.map +1 -1
- package/dist/src/retention.js +41 -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/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/types.d.ts +198 -6
- 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 +4 -2
- package/src/ai/hash.ts +3 -3
- package/src/ai/prompt.ts +23 -1
- package/src/ai/service.ts +21 -12
- package/src/ai/types.ts +14 -2
- package/src/ai/worker.ts +10 -2
- package/src/appealService.ts +584 -0
- package/src/appeals.ts +256 -0
- package/src/audit.ts +18 -3
- package/src/chatwarden.ts +199 -21
- package/src/decide.ts +13 -7
- package/src/documents.ts +6 -3
- package/src/events.ts +23 -1
- package/src/index.ts +12 -1
- package/src/nameService.ts +255 -0
- package/src/names.ts +121 -0
- package/src/notices.ts +112 -14
- package/src/policy.ts +20 -3
- package/src/profile.ts +34 -2
- package/src/retention.ts +63 -3
- package/src/sanctions.ts +72 -9
- package/src/staffViews.ts +30 -0
- package/src/types.ts +210 -7
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { KitEvent } from './events.js';
|
|
2
|
+
import type { NameCheckResult, ResolvedNames } from './names.js';
|
|
3
|
+
import type { NoticeService } from './notices.js';
|
|
4
|
+
import type { CommunityRules } from './rules.js';
|
|
5
|
+
import type { SubjectIndex } from './subjects.js';
|
|
6
|
+
import type { Clock, Hasher, Logger, Matcher, ProfanityFilter, RawWho, Store, SubjectId } from './types.js';
|
|
7
|
+
export interface NameServiceDeps {
|
|
8
|
+
store: Store;
|
|
9
|
+
clock: Clock;
|
|
10
|
+
logger: Logger | undefined;
|
|
11
|
+
hasher: Hasher;
|
|
12
|
+
/** The slur filter's rule (`autoRestrictRule`): what a refusal cites. */
|
|
13
|
+
rule: number;
|
|
14
|
+
matcher: Matcher | undefined;
|
|
15
|
+
/** The settings in force now (read on every call: a policy change takes effect at once). */
|
|
16
|
+
settings: () => ResolvedNames;
|
|
17
|
+
/** The profanity filter for names, or undefined when there is none. May throw (a package that cannot build one). */
|
|
18
|
+
filter: () => ProfanityFilter | undefined;
|
|
19
|
+
/** The person behind a caller, FOUND and never created. */
|
|
20
|
+
personOf: (who: RawWho) => SubjectId | null;
|
|
21
|
+
/** Required renames are notices of kind `rename_required`. */
|
|
22
|
+
notices: NoticeService;
|
|
23
|
+
/** Who is who: a person the kit holds, and the surviving id of an alias. */
|
|
24
|
+
subjects: SubjectIndex;
|
|
25
|
+
/** The rule a rename may cite must be active here. */
|
|
26
|
+
rules: CommunityRules;
|
|
27
|
+
/** Raise an event after the write has committed. */
|
|
28
|
+
emit: (event: KitEvent) => void;
|
|
29
|
+
}
|
|
30
|
+
/** What `requireRename` answers. */
|
|
31
|
+
export type RenameResult = {
|
|
32
|
+
ok: true;
|
|
33
|
+
noticeId: string;
|
|
34
|
+
} | {
|
|
35
|
+
ok: false;
|
|
36
|
+
error: 'off' | 'not_found' | 'pending' | 'invalid';
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The longest private reason a required rename takes, in characters: the decision's limit, one constant for every private reason. (Defined here,
|
|
40
|
+
* not in `names.ts`: the profile imports that file and the decision module imports the profile, so the other way round is a cycle.)
|
|
41
|
+
*/
|
|
42
|
+
export declare const RENAME_REASON_MAX = 500;
|
|
43
|
+
export declare class NameService {
|
|
44
|
+
private readonly d;
|
|
45
|
+
private readonly limiter;
|
|
46
|
+
private readonly flaggedWarn;
|
|
47
|
+
private readonly evidenceWarn;
|
|
48
|
+
constructor(deps: NameServiceDeps);
|
|
49
|
+
check(text: string, opts?: {
|
|
50
|
+
who?: RawWho;
|
|
51
|
+
}): NameCheckResult;
|
|
52
|
+
/** The matcher's reading alone: no profanity, no store, no person. False for anything it cannot read. Never throws. */
|
|
53
|
+
flagged(text: string): boolean;
|
|
54
|
+
/** The matcher's term id for a name it refuses, or null. Throws what the matcher throws. */
|
|
55
|
+
private matched;
|
|
56
|
+
private verdict;
|
|
57
|
+
/** Keep a blocked name as evidence, when the adopter opted in and the hourly caps allow. Fenced: nothing in here reaches the caller. */
|
|
58
|
+
private keep;
|
|
59
|
+
/** The caller, as far as it is usable: an object. A getter that throws is the caller's fault and is absorbed by `keep`'s fence. */
|
|
60
|
+
private whoOf;
|
|
61
|
+
/** What the hourly cap counts a person by: the person found, else the caller's own identifiers, else the name. Never the raw values. */
|
|
62
|
+
private keyOf;
|
|
63
|
+
/**
|
|
64
|
+
* Ask a player to choose a new name: one `rename_required` notice (no name, no excerpt, no reason) and, after the write, the player's
|
|
65
|
+
* client is told and `rename.required` goes out. Answers, in this order: `off` (`names.renames` is false, or the store cannot release a
|
|
66
|
+
* rename), `invalid` (a malformed input, a reason that is not 1 to 500 characters once trimmed, a rule that is not an active integer rule),
|
|
67
|
+
* `not_found` (a person the kit does not hold), `pending` (an unreleased request exists, seen or not). A store failure is logged by class
|
|
68
|
+
* and thrown, with nothing written. The reason and the actor are validated here and kept by the staff layer's audit row, not by the notice.
|
|
69
|
+
*/
|
|
70
|
+
requireRename(input: {
|
|
71
|
+
subject: SubjectId;
|
|
72
|
+
actor: string;
|
|
73
|
+
reason: string;
|
|
74
|
+
rule?: number;
|
|
75
|
+
}): RenameResult;
|
|
76
|
+
/** Can a moderator ask for a rename now: the setting is on and the store can release one (the test `requireRename` applies first). */
|
|
77
|
+
renamesEnabled(): boolean;
|
|
78
|
+
/** A person's rename requests, newest first (at most {@link RENAMES_OF_MAX}): when, and whether one still waits. No reason, actor or rule. Staff only. */
|
|
79
|
+
renamesOf(subject: SubjectId): Array<{
|
|
80
|
+
at: number;
|
|
81
|
+
pending: boolean;
|
|
82
|
+
}>;
|
|
83
|
+
/** True while the person has a required rename they have not been released from. False for anyone the kit cannot find (never creates one). */
|
|
84
|
+
pendingRename(who: RawWho): boolean;
|
|
85
|
+
/** The game says the player has a new name: withdraws their pending rename notices. True when it withdrew one. */
|
|
86
|
+
renamed(who: RawWho): boolean;
|
|
87
|
+
private releaseOrRead;
|
|
88
|
+
private checkRename;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=nameService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nameService.d.ts","sourceRoot":"","sources":["../../src/nameService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,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rB,OAAO,CAAC,WAAW;CAYpB"}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { isValidAuditActor } from './audit.js';
|
|
2
|
+
import { randomId } from './crypto.js';
|
|
3
|
+
import { hashWho } from './hasher.js';
|
|
4
|
+
import { safeWarn, ThrottledWarn } from './log.js';
|
|
5
|
+
import { DECISION_REASON_MAX } from './decide.js';
|
|
6
|
+
import { evidenceName, NameEvidenceLimiter, profanityView } from './names.js';
|
|
7
|
+
/**
|
|
8
|
+
* The longest private reason a required rename takes, in characters: the decision's limit, one constant for every private reason. (Defined here,
|
|
9
|
+
* not in `names.ts`: the profile imports that file and the decision module imports the profile, so the other way round is a cycle.)
|
|
10
|
+
*/
|
|
11
|
+
export const RENAME_REASON_MAX = DECISION_REASON_MAX;
|
|
12
|
+
/** The most rename requests `renamesOf` lists. */
|
|
13
|
+
const RENAMES_OF_MAX = 20;
|
|
14
|
+
const errName = (err) => (err instanceof Error ? err.name : typeof err);
|
|
15
|
+
export class NameService {
|
|
16
|
+
d;
|
|
17
|
+
limiter = new NameEvidenceLimiter();
|
|
18
|
+
flaggedWarn;
|
|
19
|
+
evidenceWarn;
|
|
20
|
+
constructor(deps) {
|
|
21
|
+
this.d = deps;
|
|
22
|
+
this.flaggedWarn = new ThrottledWarn(deps.logger, deps.clock);
|
|
23
|
+
this.evidenceWarn = new ThrottledWarn(deps.logger, deps.clock);
|
|
24
|
+
}
|
|
25
|
+
check(text, opts) {
|
|
26
|
+
if (typeof text !== 'string')
|
|
27
|
+
throw new TypeError('names.check: the name must be a string');
|
|
28
|
+
const verdict = this.verdict(text);
|
|
29
|
+
if (verdict === null)
|
|
30
|
+
return { ok: true };
|
|
31
|
+
this.keep(text, verdict, opts);
|
|
32
|
+
return { ok: false, reason: verdict.reason, rule: this.d.rule };
|
|
33
|
+
}
|
|
34
|
+
/** The matcher's reading alone: no profanity, no store, no person. False for anything it cannot read. Never throws. */
|
|
35
|
+
flagged(text) {
|
|
36
|
+
if (typeof text !== 'string')
|
|
37
|
+
return false;
|
|
38
|
+
try {
|
|
39
|
+
return this.matched(text) !== null;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
this.flaggedWarn.warn('chatwarden.names_matcher_failed', { error: errName(err) });
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/** The matcher's term id for a name it refuses, or null. Throws what the matcher throws. */
|
|
47
|
+
matched(text) {
|
|
48
|
+
const m = this.d.matcher;
|
|
49
|
+
if (m === undefined)
|
|
50
|
+
return null;
|
|
51
|
+
const hit = typeof m.matchName === 'function' ? m.matchName(text) : m.match(text);
|
|
52
|
+
if (hit === null || hit === undefined)
|
|
53
|
+
return null;
|
|
54
|
+
return { termId: typeof hit.termId === 'string' ? hit.termId : null };
|
|
55
|
+
}
|
|
56
|
+
verdict(text) {
|
|
57
|
+
try {
|
|
58
|
+
const hit = this.matched(text);
|
|
59
|
+
if (hit !== null)
|
|
60
|
+
return { reason: 'name_not_allowed', termId: hit.termId };
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
safeWarn(this.d.logger, 'chatwarden.names_matcher_failed', { error: errName(err) });
|
|
64
|
+
}
|
|
65
|
+
if (!this.d.settings().profanity)
|
|
66
|
+
return null;
|
|
67
|
+
try {
|
|
68
|
+
const filter = this.d.filter();
|
|
69
|
+
if (filter === undefined)
|
|
70
|
+
return null;
|
|
71
|
+
if (filter.apply(text).hit)
|
|
72
|
+
return { reason: 'name_profane', termId: null };
|
|
73
|
+
const spaced = profanityView(text);
|
|
74
|
+
if (spaced !== text && filter.apply(spaced).hit)
|
|
75
|
+
return { reason: 'name_profane', termId: null };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
safeWarn(this.d.logger, 'chatwarden.names_filter_failed', { error: errName(err) });
|
|
79
|
+
}
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
/** Keep a blocked name as evidence, when the adopter opted in and the hourly caps allow. Fenced: nothing in here reaches the caller. */
|
|
83
|
+
keep(text, verdict, opts) {
|
|
84
|
+
try {
|
|
85
|
+
if (!this.d.settings().keepBlocked)
|
|
86
|
+
return;
|
|
87
|
+
const store = this.d.store;
|
|
88
|
+
if (typeof store.insertBlockedName !== 'function') {
|
|
89
|
+
this.evidenceWarn.warn('chatwarden.names_evidence_unavailable', {});
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const now = this.d.clock.now();
|
|
93
|
+
const name = evidenceName(text);
|
|
94
|
+
const who = this.whoOf(opts);
|
|
95
|
+
const subject = who === undefined ? null : this.d.personOf(who);
|
|
96
|
+
const key = this.keyOf(subject, who, name);
|
|
97
|
+
if (!this.limiter.allow(key, now))
|
|
98
|
+
return;
|
|
99
|
+
store.transaction(() => store.insertBlockedName?.({ id: randomId(), subject, name, termId: verdict.termId, reason: verdict.reason, at: now }));
|
|
100
|
+
this.limiter.record(key, now);
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
safeWarn(this.d.logger, 'chatwarden.names_evidence_failed', { error: errName(err) });
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/** The caller, as far as it is usable: an object. A getter that throws is the caller's fault and is absorbed by `keep`'s fence. */
|
|
107
|
+
whoOf(opts) {
|
|
108
|
+
if (typeof opts !== 'object' || opts === null)
|
|
109
|
+
return undefined;
|
|
110
|
+
const who = opts.who;
|
|
111
|
+
return typeof who === 'object' && who !== null ? who : undefined;
|
|
112
|
+
}
|
|
113
|
+
/** What the hourly cap counts a person by: the person found, else the caller's own identifiers, else the name. Never the raw values. */
|
|
114
|
+
keyOf(subject, who, name) {
|
|
115
|
+
if (subject !== null)
|
|
116
|
+
return `s:${subject}`;
|
|
117
|
+
if (who !== undefined) {
|
|
118
|
+
const ids = hashWho(this.d.hasher, who);
|
|
119
|
+
if (ids.clientKey !== null || ids.accountId !== null || ids.ipHash !== null) {
|
|
120
|
+
return `w:${ids.clientKey ?? ''}|${typeof ids.accountId === 'string' ? this.d.hasher.clientKey(`account:${ids.accountId}`) : ''}|${ids.ipHash ?? ''}`;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
return `n:${this.d.hasher.clientKey(`name:${name.toLowerCase()}`)}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Ask a player to choose a new name: one `rename_required` notice (no name, no excerpt, no reason) and, after the write, the player's
|
|
127
|
+
* client is told and `rename.required` goes out. Answers, in this order: `off` (`names.renames` is false, or the store cannot release a
|
|
128
|
+
* rename), `invalid` (a malformed input, a reason that is not 1 to 500 characters once trimmed, a rule that is not an active integer rule),
|
|
129
|
+
* `not_found` (a person the kit does not hold), `pending` (an unreleased request exists, seen or not). A store failure is logged by class
|
|
130
|
+
* and thrown, with nothing written. The reason and the actor are validated here and kept by the staff layer's audit row, not by the notice.
|
|
131
|
+
*/
|
|
132
|
+
requireRename(input) {
|
|
133
|
+
const d = this.d;
|
|
134
|
+
if (!this.renamesEnabled())
|
|
135
|
+
return { ok: false, error: 'off' };
|
|
136
|
+
const checked = this.checkRename(input);
|
|
137
|
+
if (checked === null)
|
|
138
|
+
return { ok: false, error: 'invalid' };
|
|
139
|
+
let noticeId;
|
|
140
|
+
let person;
|
|
141
|
+
let at;
|
|
142
|
+
try {
|
|
143
|
+
person = d.subjects.canonical(checked.subject);
|
|
144
|
+
if (!d.subjects.knows(person))
|
|
145
|
+
return { ok: false, error: 'not_found' };
|
|
146
|
+
if (d.notices.renamePending(person))
|
|
147
|
+
return { ok: false, error: 'pending' };
|
|
148
|
+
at = d.clock.now();
|
|
149
|
+
noticeId = d.notices.createMessage(person, 'rename_required', { rule: checked.rule, notify: false });
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
safeWarn(d.logger, 'chatwarden.rename_failed', { error: errName(err) });
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
// After the write: the client is told (fenced inside `announce`), then the event (a listener that throws is not the caller's problem).
|
|
156
|
+
d.notices.announce(person);
|
|
157
|
+
try {
|
|
158
|
+
d.emit({ type: 'rename.required', at, target: person, rule: checked.rule });
|
|
159
|
+
}
|
|
160
|
+
catch (err) {
|
|
161
|
+
safeWarn(d.logger, 'chatwarden.event_failed', { error: errName(err) });
|
|
162
|
+
}
|
|
163
|
+
return { ok: true, noticeId };
|
|
164
|
+
}
|
|
165
|
+
/** Can a moderator ask for a rename now: the setting is on and the store can release one (the test `requireRename` applies first). */
|
|
166
|
+
renamesEnabled() {
|
|
167
|
+
return this.d.settings().renames && this.d.notices.canWithdrawOne();
|
|
168
|
+
}
|
|
169
|
+
/** A person's rename requests, newest first (at most {@link RENAMES_OF_MAX}): when, and whether one still waits. No reason, actor or rule. Staff only. */
|
|
170
|
+
renamesOf(subject) {
|
|
171
|
+
if (typeof subject !== 'string' || subject === '')
|
|
172
|
+
return [];
|
|
173
|
+
try {
|
|
174
|
+
return this.d.notices
|
|
175
|
+
.renameRows(subject)
|
|
176
|
+
.slice(0, RENAMES_OF_MAX)
|
|
177
|
+
.map((r) => ({ at: r.createdAt, pending: r.withdrawnAt === null }));
|
|
178
|
+
}
|
|
179
|
+
catch (err) {
|
|
180
|
+
safeWarn(this.d.logger, 'chatwarden.rename_failed', { error: errName(err) });
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
/** True while the person has a required rename they have not been released from. False for anyone the kit cannot find (never creates one). */
|
|
185
|
+
pendingRename(who) {
|
|
186
|
+
return this.releaseOrRead(who, (subject) => this.d.notices.renamePending(subject));
|
|
187
|
+
}
|
|
188
|
+
/** The game says the player has a new name: withdraws their pending rename notices. True when it withdrew one. */
|
|
189
|
+
renamed(who) {
|
|
190
|
+
return this.releaseOrRead(who, (subject) => this.d.notices.withdrawRenames(subject) > 0);
|
|
191
|
+
}
|
|
192
|
+
releaseOrRead(who, read) {
|
|
193
|
+
if (typeof who !== 'object' || who === null)
|
|
194
|
+
return false;
|
|
195
|
+
try {
|
|
196
|
+
const subject = this.d.personOf(who);
|
|
197
|
+
return subject === null ? false : read(subject);
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
safeWarn(this.d.logger, 'chatwarden.rename_failed', { error: errName(err) });
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
checkRename(input) {
|
|
205
|
+
if (typeof input !== 'object' || input === null)
|
|
206
|
+
return null;
|
|
207
|
+
const { subject, actor, reason, rule } = input;
|
|
208
|
+
if (typeof subject !== 'string' || subject === '')
|
|
209
|
+
return null;
|
|
210
|
+
if (!isValidAuditActor(actor))
|
|
211
|
+
return null;
|
|
212
|
+
if (typeof reason !== 'string')
|
|
213
|
+
return null;
|
|
214
|
+
const why = reason.trim();
|
|
215
|
+
if (why === '' || why.length > RENAME_REASON_MAX)
|
|
216
|
+
return null;
|
|
217
|
+
if (rule === undefined)
|
|
218
|
+
return { subject, rule: this.d.rule };
|
|
219
|
+
if (typeof rule !== 'number' || !Number.isSafeInteger(rule) || !this.d.rules.isCitable(rule))
|
|
220
|
+
return null;
|
|
221
|
+
return { subject, rule };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
//# sourceMappingURL=nameService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nameService.js","sourceRoot":"","sources":["../../src/nameService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AA2C9E;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG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,IAAI,CAAC;QAC9D,IAAI,IAAI,KAAK,SAAS;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC;YAAE,OAAO,IAAI,CAAC;QAC1G,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/** Why a name was refused. `name_profane` needs `names.profanity`. @experimental */
|
|
2
|
+
export type NameReason = 'name_not_allowed' | 'name_profane';
|
|
3
|
+
/** The answer of `cw.names.check`: allowed, or a reason id and the Community Rule it cites; never the text. @experimental */
|
|
4
|
+
export type NameCheckResult = {
|
|
5
|
+
ok: true;
|
|
6
|
+
} | {
|
|
7
|
+
ok: false;
|
|
8
|
+
reason: NameReason;
|
|
9
|
+
rule: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How names are checked and shown. Every field is optional.
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export interface NameSettings {
|
|
16
|
+
/** Also refuse a name the profanity filter flags. Default false (a swear word is not a slur; this is for a family game). */
|
|
17
|
+
profanity?: boolean;
|
|
18
|
+
/** Keep a blocked name, with the term it hit, as evidence. Default false: a name check stores nothing. */
|
|
19
|
+
keepBlocked?: boolean;
|
|
20
|
+
/** May a moderator require a rename from the Person page? Default false. */
|
|
21
|
+
renames?: boolean;
|
|
22
|
+
/** Mask a name the matcher flags in the hub until a moderator shows it. Default true. */
|
|
23
|
+
maskInHub?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* What the kit reads: every field filled in.
|
|
27
|
+
* @experimental
|
|
28
|
+
*/
|
|
29
|
+
export interface ResolvedNames {
|
|
30
|
+
profanity: boolean;
|
|
31
|
+
keepBlocked: boolean;
|
|
32
|
+
renames: boolean;
|
|
33
|
+
maskInHub: boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validate and fill. Throws ProfileError naming the field (`names.keepBlocked`), never echoing the value. `path` names the settings in
|
|
37
|
+
* the error (default `names`). The result is a new object that shares nothing with the input; each value is read from `input` once.
|
|
38
|
+
* @experimental
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveNames(input: NameSettings | undefined, path?: string): ResolvedNames;
|
|
41
|
+
/** Most kept blocked names per person in an hour. */
|
|
42
|
+
export declare const NAME_EVIDENCE_PER_PERSON_HOUR = 5;
|
|
43
|
+
/** Most kept blocked names an hour, over everyone, in this process. */
|
|
44
|
+
export declare const NAME_EVIDENCE_PER_HOUR = 200;
|
|
45
|
+
/** The window both caps count over: a row leaves it exactly an hour after it was kept. */
|
|
46
|
+
export declare const NAME_EVIDENCE_WINDOW_MS = 3600000;
|
|
47
|
+
/** Most characters of a blocked name that are kept (a name is short; this bounds what a hostile caller can make the table hold). */
|
|
48
|
+
export declare const NAME_EVIDENCE_MAX_LENGTH = 200;
|
|
49
|
+
/** The name with underscores and digits turned into spaces: the second view the profanity filter reads (`big_snerp_99` is `big snerp `). */
|
|
50
|
+
export declare function profanityView(name: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* The copy of a blocked name that is kept: NUL removed, a lone surrogate (which a database would not round-trip) replaced by U+FFFD, cut to
|
|
53
|
+
* {@link NAME_EVIDENCE_MAX_LENGTH} characters without leaving half an emoji. Only the first `2 * MAX` characters are even looked at.
|
|
54
|
+
*/
|
|
55
|
+
export declare function evidenceName(name: string): string;
|
|
56
|
+
/**
|
|
57
|
+
* The hourly caps on kept blocked names: {@link NAME_EVIDENCE_PER_PERSON_HOUR} per key and {@link NAME_EVIDENCE_PER_HOUR} overall, in memory,
|
|
58
|
+
* over a sliding window. A key is whatever the caller counts a person by. `allow` only asks; `record` counts a row that really was kept, so a
|
|
59
|
+
* failed write never uses the cap. Holds at most 200 timestamps, however many names are probed. A time in the future (the clock moved back)
|
|
60
|
+
* no longer counts.
|
|
61
|
+
*/
|
|
62
|
+
export declare class NameEvidenceLimiter {
|
|
63
|
+
private all;
|
|
64
|
+
private readonly by;
|
|
65
|
+
allow(key: string, now: number): boolean;
|
|
66
|
+
record(key: string, now: number): void;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.d.ts","sourceRoot":"","sources":["../../src/names.ts"],"names":[],"mappings":"AAKA,oFAAoF;AACpF,MAAM,MAAM,UAAU,GAAG,kBAAkB,GAAG,cAAc,CAAC;AAE7D,6HAA6H;AAC7H,MAAM,MAAM,eAAe,GAAG;IAAE,EAAE,EAAE,IAAI,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI7F;;;GAGG;AACH,MAAM,WAAW,YAAY;IAC3B,4HAA4H;IAC5H,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,0GAA0G;IAC1G,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,yFAAyF;IACzF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,OAAO,CAAC;IACnB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;CACpB;AAQD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,GAAG,SAAS,EAAE,IAAI,SAAU,GAAG,aAAa,CAY3F;AAED,qDAAqD;AACrD,eAAO,MAAM,6BAA6B,IAAI,CAAC;AAC/C,uEAAuE;AACvE,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,0FAA0F;AAC1F,eAAO,MAAM,uBAAuB,UAAY,CAAC;AACjD,oIAAoI;AACpI,eAAO,MAAM,wBAAwB,MAAM,CAAC;AAE5C,6IAA6I;AAC7I,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAElD;AAID;;;GAGG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAMjD;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,EAAE,CAA+B;IAElD,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO;IAOxC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,IAAI;CASvC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ProfileError } from './profileError.js';
|
|
2
|
+
const KEYS = ['profanity', 'keepBlocked', 'renames', 'maskInHub'];
|
|
3
|
+
function isPlain(v) {
|
|
4
|
+
if (typeof v !== 'object' || v === null || Array.isArray(v))
|
|
5
|
+
return false;
|
|
6
|
+
const proto = Object.getPrototypeOf(v);
|
|
7
|
+
return proto === Object.prototype || proto === null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Validate and fill. Throws ProfileError naming the field (`names.keepBlocked`), never echoing the value. `path` names the settings in
|
|
11
|
+
* the error (default `names`). The result is a new object that shares nothing with the input; each value is read from `input` once.
|
|
12
|
+
* @experimental
|
|
13
|
+
*/
|
|
14
|
+
export function resolveNames(input, path = 'names') {
|
|
15
|
+
const out = { profanity: false, keepBlocked: false, renames: false, maskInHub: true };
|
|
16
|
+
if (input === undefined)
|
|
17
|
+
return out;
|
|
18
|
+
if (!isPlain(input))
|
|
19
|
+
throw new ProfileError(path, 'must be an object');
|
|
20
|
+
for (const k of Object.keys(input))
|
|
21
|
+
if (!KEYS.includes(k))
|
|
22
|
+
throw new ProfileError(`${path}.${k}`, 'is not a known setting');
|
|
23
|
+
for (const k of KEYS) {
|
|
24
|
+
const v = Object.hasOwn(input, k) ? input[k] : undefined;
|
|
25
|
+
if (v === undefined)
|
|
26
|
+
continue;
|
|
27
|
+
if (typeof v !== 'boolean')
|
|
28
|
+
throw new ProfileError(`${path}.${k}`, 'must be true or false');
|
|
29
|
+
out[k] = v;
|
|
30
|
+
}
|
|
31
|
+
return out;
|
|
32
|
+
}
|
|
33
|
+
/** Most kept blocked names per person in an hour. */
|
|
34
|
+
export const NAME_EVIDENCE_PER_PERSON_HOUR = 5;
|
|
35
|
+
/** Most kept blocked names an hour, over everyone, in this process. */
|
|
36
|
+
export const NAME_EVIDENCE_PER_HOUR = 200;
|
|
37
|
+
/** The window both caps count over: a row leaves it exactly an hour after it was kept. */
|
|
38
|
+
export const NAME_EVIDENCE_WINDOW_MS = 3_600_000;
|
|
39
|
+
/** Most characters of a blocked name that are kept (a name is short; this bounds what a hostile caller can make the table hold). */
|
|
40
|
+
export const NAME_EVIDENCE_MAX_LENGTH = 200;
|
|
41
|
+
/** The name with underscores and digits turned into spaces: the second view the profanity filter reads (`big_snerp_99` is `big snerp `). */
|
|
42
|
+
export function profanityView(name) {
|
|
43
|
+
return name.replace(/[_\p{Nd}]/gu, ' ');
|
|
44
|
+
}
|
|
45
|
+
const LONE_SURROGATE = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/g;
|
|
46
|
+
/**
|
|
47
|
+
* The copy of a blocked name that is kept: NUL removed, a lone surrogate (which a database would not round-trip) replaced by U+FFFD, cut to
|
|
48
|
+
* {@link NAME_EVIDENCE_MAX_LENGTH} characters without leaving half an emoji. Only the first `2 * MAX` characters are even looked at.
|
|
49
|
+
*/
|
|
50
|
+
export function evidenceName(name) {
|
|
51
|
+
const head = name.slice(0, NAME_EVIDENCE_MAX_LENGTH * 2).replaceAll('\u0000', '').replace(LONE_SURROGATE, '\uFFFD');
|
|
52
|
+
if (head.length <= NAME_EVIDENCE_MAX_LENGTH)
|
|
53
|
+
return head;
|
|
54
|
+
const cut = head.slice(0, NAME_EVIDENCE_MAX_LENGTH);
|
|
55
|
+
const last = cut.charCodeAt(cut.length - 1);
|
|
56
|
+
return last >= 0xd800 && last <= 0xdbff ? cut.slice(0, -1) : cut;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The hourly caps on kept blocked names: {@link NAME_EVIDENCE_PER_PERSON_HOUR} per key and {@link NAME_EVIDENCE_PER_HOUR} overall, in memory,
|
|
60
|
+
* over a sliding window. A key is whatever the caller counts a person by. `allow` only asks; `record` counts a row that really was kept, so a
|
|
61
|
+
* failed write never uses the cap. Holds at most 200 timestamps, however many names are probed. A time in the future (the clock moved back)
|
|
62
|
+
* no longer counts.
|
|
63
|
+
*/
|
|
64
|
+
export class NameEvidenceLimiter {
|
|
65
|
+
all = [];
|
|
66
|
+
by = new Map();
|
|
67
|
+
allow(key, now) {
|
|
68
|
+
this.all = this.all.filter((t) => live(t, now));
|
|
69
|
+
if (this.all.length >= NAME_EVIDENCE_PER_HOUR)
|
|
70
|
+
return false;
|
|
71
|
+
const mine = (this.by.get(key) ?? []).filter((t) => live(t, now));
|
|
72
|
+
return mine.length < NAME_EVIDENCE_PER_PERSON_HOUR;
|
|
73
|
+
}
|
|
74
|
+
record(key, now) {
|
|
75
|
+
this.all.push(now);
|
|
76
|
+
for (const [k, stamps] of this.by) {
|
|
77
|
+
const kept = stamps.filter((t) => live(t, now));
|
|
78
|
+
if (kept.length === 0)
|
|
79
|
+
this.by.delete(k);
|
|
80
|
+
else
|
|
81
|
+
this.by.set(k, kept);
|
|
82
|
+
}
|
|
83
|
+
this.by.set(key, [...(this.by.get(key) ?? []), now]);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
const live = (t, now) => t <= now && now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AI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;;gBACpC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;IACvD,CAAC;CACF;AAED,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,GAAW,EAAW,EAAE,CAAC,CAAC,IAAI,GAAG,IAAI,GAAG,GAAG,CAAC,GAAG,uBAAuB,CAAC"}
|
package/dist/src/notices.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CommunityRules, RuleRef } from './rules.js';
|
|
2
2
|
import type { SubjectIndex } from './subjects.js';
|
|
3
|
-
import type { Clock, Logger, Matcher, NoticeKind, ReportExcerptLine, Store, StoredReport, SubjectId } from './types.js';
|
|
3
|
+
import type { Clock, Logger, Matcher, NoticeKind, NoticeRow, ReportExcerptLine, Store, StoredReport, SubjectId } from './types.js';
|
|
4
4
|
export type { NoticeKind } from './types.js';
|
|
5
5
|
/** The most lines a notice excerpt may carry. */
|
|
6
6
|
export declare const NOTICE_EXCERPT_MAX = 5;
|
|
@@ -8,6 +8,20 @@ export declare const NOTICE_EXCERPT_MAX = 5;
|
|
|
8
8
|
export declare const NOTICE_RECORD_WINDOW_MS: number;
|
|
9
9
|
/** How many sanction groups the notice-id lookup remembers. The oldest entry is dropped past this. */
|
|
10
10
|
export declare const NOTICE_LOOKUP_CACHE_MAX = 10000;
|
|
11
|
+
/**
|
|
12
|
+
* The four notices that are messages, not sanctions: a rename is required, an appeal was upheld, reduced or revoked. They have no
|
|
13
|
+
* group, no end and no excerpt, show in `pending` and `announce` and never on "My record", and never need an acknowledgement. Made by
|
|
14
|
+
* {@link NoticeService.createMessage}. A seen one is purged like a seen report outcome; an unseen one is kept until seen or withdrawn.
|
|
15
|
+
* @experimental
|
|
16
|
+
*/
|
|
17
|
+
export declare const MESSAGE_NOTICE_KINDS: readonly ["rename_required", "appeal_upheld", "appeal_reduced", "appeal_revoked"];
|
|
18
|
+
export type MessageNoticeKind = (typeof MESSAGE_NOTICE_KINDS)[number];
|
|
19
|
+
/** Every kind this build can show. A stored row of any other kind (written by a newer kit) is skipped, never thrown on. */
|
|
20
|
+
/**
|
|
21
|
+
* Whether a notice row is on "My record" now: not withdrawn, one of the four sanction kinds, and either made within 90 days or (not a
|
|
22
|
+
* warning) permanent or still running. The one definition `record` uses and an appeal is filed against.
|
|
23
|
+
*/
|
|
24
|
+
export declare function appliesInRecord(r: Pick<NoticeRow, 'withdrawnAt' | 'kind' | 'createdAt' | 'until'>, now: number): boolean;
|
|
11
25
|
/**
|
|
12
26
|
* What a player is shown about a sanction taken against them, or about a report they filed. The ONLY shape that
|
|
13
27
|
* leaves the kit for a player. It carries no subject, key, hash, room, seat or handle, no moderator reason or
|
|
@@ -17,13 +31,13 @@ export interface PlayerNotice {
|
|
|
17
31
|
/** Random; the handle for `ack`. */
|
|
18
32
|
id: string;
|
|
19
33
|
kind: NoticeKind;
|
|
20
|
-
/** The Community Rule cited; null for a report outcome. */
|
|
34
|
+
/** The Community Rule cited; null for a report outcome (and for a message that cites none). */
|
|
21
35
|
rule: RuleRef | null;
|
|
22
36
|
/** The player-facing name of the rule. */
|
|
23
37
|
ruleLabel: string | null;
|
|
24
|
-
/** Epoch ms the sanction ends; null = no end (permanent, a warning,
|
|
38
|
+
/** Epoch ms the sanction ends; null = no end (permanent, a warning, a report outcome or a message). */
|
|
25
39
|
until: number | null;
|
|
26
|
-
/** The reference code to quote to a moderator; null for a report outcome. */
|
|
40
|
+
/** The reference code to quote to a moderator; null for a report outcome (a message carries the original sanction's, or none). */
|
|
27
41
|
refCode: string | null;
|
|
28
42
|
/** At most five of the player's own lines. `day` is UTC `YYYY-MM-DD`. A blocked line has its matched terms masked. */
|
|
29
43
|
excerpt: Array<{
|
|
@@ -61,6 +75,13 @@ export interface NoticeCreateOptions {
|
|
|
61
75
|
/** Default true. False skips the push; call `announce` after the surrounding transaction commits. */
|
|
62
76
|
notify?: boolean;
|
|
63
77
|
}
|
|
78
|
+
/** What a message notice may cite: the rule and the reference code of the decision it is about. Never a name, a reason or an excerpt. */
|
|
79
|
+
export interface MessageNoticeOptions extends NoticeCreateOptions {
|
|
80
|
+
/** The Community Rule the original decision cited. Default null. */
|
|
81
|
+
rule?: RuleRef | null;
|
|
82
|
+
/** The reference code of the original sanction, to quote to a moderator. Default null. */
|
|
83
|
+
refCode?: string | null;
|
|
84
|
+
}
|
|
64
85
|
/** What a notice is told about a sanction. `excerptLines` come through {@link ownLines}. */
|
|
65
86
|
export interface SanctionNoticeInput {
|
|
66
87
|
groupId: string;
|
|
@@ -116,6 +137,14 @@ export declare class NoticeService {
|
|
|
116
137
|
* {@link announce} once that transaction has committed.
|
|
117
138
|
*/
|
|
118
139
|
createForSanction(group: SanctionNoticeInput, excerptLines?: readonly ReportExcerptLine[], opts?: NoticeCreateOptions): string;
|
|
140
|
+
/**
|
|
141
|
+
* Write a message notice (a rename is required, an appeal was upheld, reduced or revoked) for a person and tell their client.
|
|
142
|
+
* Returns the notice id. It carries the kind, an optional rule and reference code and the time, and nothing else: no excerpt, no name,
|
|
143
|
+
* no reason. It has no sanction group, so `withdrawGroup` never touches it. Throws for any other kind, a malformed rule or code, or a
|
|
144
|
+
* bad subject (nothing is written). Pass `{ notify: false }` inside a larger transaction, then call {@link announce} after the commit.
|
|
145
|
+
* @experimental
|
|
146
|
+
*/
|
|
147
|
+
createMessage(subject: SubjectId, kind: MessageNoticeKind, opts?: MessageNoticeOptions): string;
|
|
119
148
|
/** Tell a reporter that their report led to action. No rule, code, end or excerpt: nothing about the other player. */
|
|
120
149
|
createReportOutcome(reporter: SubjectId, opts?: NoticeCreateOptions): string;
|
|
121
150
|
/** Notices not yet seen or withdrawn, oldest first, across the person's merged subjects. */
|
|
@@ -133,10 +162,29 @@ export declare class NoticeService {
|
|
|
133
162
|
/**
|
|
134
163
|
* "My record": the person's sanction notices (seen or not) that are not withdrawn and still apply. A warning
|
|
135
164
|
* applies for 90 days from when it was made (the ladder lookback). Any other kind applies while it is permanent
|
|
136
|
-
* (until it is withdrawn), still running, or made within 90 days. Report outcomes are never included. Decided from
|
|
165
|
+
* (until it is withdrawn), still running, or made within 90 days. Report outcomes and the four message kinds are never included. Decided from
|
|
137
166
|
* the notice row alone; `purgeNotices` agrees with this, so a row that applies is never purged.
|
|
138
167
|
*/
|
|
139
168
|
record(subject: SubjectId): PlayerNotice[];
|
|
169
|
+
/**
|
|
170
|
+
* The stored notice `id` when it belongs to this person (across their merged aliases), whatever its kind or state; null otherwise.
|
|
171
|
+
* Staff-side: the row names its sanction group. For the appeals service, which decides from the row whether it can be appealed.
|
|
172
|
+
*/
|
|
173
|
+
ownRow(subject: SubjectId, id: string): NoticeRow | null;
|
|
174
|
+
/**
|
|
175
|
+
* Does the person have a required rename they have not been released from: a `rename_required` notice not withdrawn, seen or not, on any of
|
|
176
|
+
* their merged subjects. Staff-side; the game reads it through `names.pendingRename`.
|
|
177
|
+
*/
|
|
178
|
+
renamePending(subject: SubjectId): boolean;
|
|
179
|
+
/** A person's `rename_required` notices, newest first, withdrawn ones included, across their merged subjects. Staff-side. */
|
|
180
|
+
renameRows(subject: SubjectId): NoticeRow[];
|
|
181
|
+
/** Can this build's store withdraw one notice by id? Without it a rename could never be released. */
|
|
182
|
+
canWithdrawOne(): boolean;
|
|
183
|
+
/**
|
|
184
|
+
* Withdraw every pending `rename_required` notice of the person, in one transaction, and tell their client the new count when any was.
|
|
185
|
+
* Returns how many it withdrew (0 when none was pending, or the store cannot withdraw one). Other kinds are never touched.
|
|
186
|
+
*/
|
|
187
|
+
withdrawRenames(subject: SubjectId): number;
|
|
140
188
|
/** Withdraw the notices of a sanction group (it was revoked). Returns how many were withdrawn. */
|
|
141
189
|
withdrawGroup(groupId: string): number;
|
|
142
190
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../src/notices.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,
|
|
1
|
+
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../src/notices.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,EAAE,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnI,YAAY,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAI7C,iDAAiD;AACjD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAEpC,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,QAAc,CAAC;AAEnD,sGAAsG;AACtG,eAAO,MAAM,uBAAuB,QAAS,CAAC;AAK9C;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,mFAAoF,CAAC;AACtH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,2HAA2H;AAC3H;;;GAGG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,aAAa,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAMxH;AAKD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