koishi-plugin-aakook 0.1.0 → 0.3.0

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/lib/config.js CHANGED
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Config = exports.DEFAULT_TEXTS = void 0;
3
+ exports.corpChannelsOn = exports.Config = exports.DEFAULT_TEXTS = void 0;
4
4
  exports.parsePlatformId = parsePlatformId;
5
5
  exports.parseReportTo = parseReportTo;
6
6
  exports.normalizedRoleMap = normalizedRoleMap;
7
7
  exports.isOperator = isOperator;
8
8
  exports.validateConfig = validateConfig;
9
9
  exports.checkAaGroups = checkAaGroups;
10
+ exports.normalizedCorpTemplate = normalizedCorpTemplate;
10
11
  exports.toPolicyConfig = toPolicyConfig;
11
12
  const koishi_1 = require("koishi");
12
13
  const util_1 = require("./util");
@@ -15,6 +16,7 @@ exports.DEFAULT_TEXTS = {
15
16
  remindDeniedTemplate: '你的联盟身份已失效({reason}),身份组已收回。请在 {deadline}(北京时间)前处理,否则会被移出服务器。发送「状态」查看详情。',
16
17
  remindLastTemplate: '还剩 {hours} 小时:请在 {deadline}(北京时间)前完成验证,否则会被移出服务器。验证方法:发送「绑定」拿验证码,再用你自己的 QQ 在联盟 QQ 群里发出。发送「状态」查看原因。',
17
18
  codeTemplate: '你的验证码:{code}({minutes} 分钟内有效)。请用你在 AA 上绑定的 QQ,在联盟 QQ 群里或私聊 QQ 机器人,单独发送这一行。不要把验证码发给别人。',
19
+ cardTemplate: '**加入联盟 KOOK 服务器**\n本服务器只对联盟成员开放。\n1. 点「获取验证码」,机器人会私聊你一个验证码。\n2. 用你在 AA 绑定的 QQ,把验证码发到联盟 QQ 群,或私聊 QQ 机器人。\n也可以在任意频道发送「绑定」。还没在 AA 绑定 QQ 的,先点「去 AA 绑定 QQ」。',
18
20
  };
19
21
  const modeSchema = koishi_1.Schema.union([
20
22
  koishi_1.Schema.const('off').description('off:什么都不做'),
@@ -56,10 +58,37 @@ exports.Config = koishi_1.Schema.intersect([
56
58
  .description('「验证」频道的 ID:私聊不通的人会在这里被 @ 提醒。'),
57
59
  whitelist: koishi_1.Schema.array(koishi_1.Schema.string()).role('table').default([])
58
60
  .description('白名单(KOOK 用户 ID):永远不会被移出、不会被提醒;身份组照常按 AA 的判定发放。'),
61
+ whitelistRoles: koishi_1.Schema.array(koishi_1.Schema.string()).role('table').default([])
62
+ .description('白名单身份组(KOOK 身份组 ID):有其中任何一个身份组的人按白名单处理。谁能给这些身份组,谁就能让人免检,只放手动管理的身份组;不要放「成员」或 roleMap 里由插件管理的身份组。'),
63
+ qqWhitelist: koishi_1.Schema.array(koishi_1.Schema.string()).role('table').default([])
64
+ .description('白名单 QQ 号:已关联的 QQ 在名单里的人按白名单处理,可以照抄 aaqqbot 的白名单。对方需要先完成一次绑定;换绑到名单外的 QQ 就不再免检。'),
59
65
  nicknameSync: koishi_1.Schema.boolean().default(true)
60
66
  .description('打开后,合格的人的服务器昵称会被改成 AA 给的名片。'),
61
67
  keepUnlinkedRoles: koishi_1.Schema.boolean().default(true)
62
68
  .description('打开后,从没关联过的人在倒计时期间保留现有身份组(插件第一次上线时用,否则全服会立刻看不到频道)。'),
69
+ corpRoles: koishi_1.Schema.boolean().default(false)
70
+ .description('按 AA 名片里的军团简称自动建身份组并发放:名片 `[KR.S] 名字` 的合格成员得到 `[KR.S]` 身份组;换军团自动摘旧挂新,不合格时收回。只动插件自己建的(或认领的同名)身份组。依赖名片以 `[简称]` 开头;KOOK 身份组上限 100 个。'),
71
+ corpRoleName: koishi_1.Schema.string().default('[{ticker}]')
72
+ .description('自动建军团身份组时的名字,`{ticker}` 换成军团简称。只影响新建的身份组;服务器里已有名字恰好相同的身份组会被直接沿用。'),
73
+ corpChannels: koishi_1.Schema.boolean().default(false)
74
+ .description('给每个军团建一个只有本军团看得见的频道分组(分类 + 文字 / 语音频道)。只在 `corpRoles` 打开时生效;只在巡检里新建,每轮最多 3 个;不会删除任何分组或频道,被所有者删掉的分组不再重建。机器人需要「频道管理」和「管理角色权限」。'),
75
+ corpCategoryName: koishi_1.Schema.string().default('{ticker} 内部')
76
+ .description('分组(分类)的名字,`{ticker}` 换成军团简称。服务器里已有同名分类会被沿用,权限不动。'),
77
+ corpChannelTemplate: koishi_1.Schema.array(koishi_1.Schema.object({
78
+ type: koishi_1.Schema.union([
79
+ koishi_1.Schema.const('text').description('文字'),
80
+ koishi_1.Schema.const('voice').description('语音'),
81
+ ]).default('text').description('频道类型'),
82
+ name: koishi_1.Schema.string().required().description('频道名字,可用 `{ticker}`'),
83
+ })).role('table').max(10).default([
84
+ { type: 'text', name: '文字' },
85
+ { type: 'voice', name: '语音 1' },
86
+ { type: 'voice', name: '语音 2' },
87
+ ]).description('每个分组里建哪些频道,1 到 10 项。'),
88
+ corpChannelMinMembers: koishi_1.Schema.natural().min(1).default(1)
89
+ .description('军团里至少有这么多已关联的成员持有(或本轮应持有)军团身份组,才建分组。'),
90
+ corpChannelExclude: koishi_1.Schema.array(koishi_1.Schema.string()).role('table').default([])
91
+ .description('不建分组的军团简称(不分大小写)。'),
63
92
  }).description('KOOK 服务器'),
64
93
  koishi_1.Schema.object({
65
94
  qqBotId: koishi_1.Schema.string().default('')
@@ -84,13 +113,13 @@ exports.Config = koishi_1.Schema.intersect([
84
113
  .description('每隔几秒向 AA 拉取一次变化(解绑、退组等)。'),
85
114
  }).description('模式与时间'),
86
115
  koishi_1.Schema.object({
87
- breakerCount: koishi_1.Schema.natural().min(1).max(100).default(5)
116
+ breakerCount: koishi_1.Schema.natural().min(1).max(1000).default(5)
88
117
  .description('熔断阈值人数:冷静期时间窗口内要移出(或首次收回「成员」)的人数超过它,或超过下面的比例(取较小者,至少为 1),这一次一个都不做,只报警。'),
89
118
  breakerPercent: koishi_1.Schema.natural().min(1).max(100).default(10)
90
119
  .description('熔断阈值比例(占服务器人数的百分比)。'),
91
120
  breakerCooldownHours: koishi_1.Schema.natural().min(1).max(72).default(6)
92
121
  .description('冷静期(小时),也是统计人数的时间窗口。冷静期满后如果还是那批人,自动放行。'),
93
- kickPerHour: koishi_1.Schema.natural().min(1).max(100).default(10)
122
+ kickPerHour: koishi_1.Schema.natural().min(1).max(1000).default(10)
94
123
  .description('每小时最多移出几个人,多的留到下一小时。'),
95
124
  }).description('熔断'),
96
125
  koishi_1.Schema.object({
@@ -108,6 +137,8 @@ exports.Config = koishi_1.Schema.intersect([
108
137
  .description('到期前的最后提醒。可用 `{hours}`、`{deadline}`。'),
109
138
  codeTemplate: koishi_1.Schema.string().role('textarea').default(exports.DEFAULT_TEXTS.codeTemplate)
110
139
  .description('发验证码的私聊。可用 `{code}`、`{minutes}`。'),
140
+ cardTemplate: koishi_1.Schema.string().role('textarea').default(exports.DEFAULT_TEXTS.cardTemplate)
141
+ .description('「验证」频道里固定卡片的正文(KMarkdown,原样使用)。可用 `{bindUrl}`。运维发 `kookaa.card` 才会发出新卡片。'),
111
142
  }).description('文案'),
112
143
  ]);
113
144
  /** `platform:id` -> parts; null when malformed. */
@@ -214,6 +245,40 @@ function validateConfig(config) {
214
245
  if (!(0, util_1.normalizeKookId)(value))
215
246
  warn(`whitelist[${index}]`, `白名单第 ${index + 1} 项不是纯数字的 KOOK 用户 ID,已忽略`);
216
247
  });
248
+ (config.whitelistRoles ?? []).forEach((value, index) => {
249
+ const roleId = (0, util_1.normalizeKookId)(value);
250
+ if (!roleId)
251
+ return warn(`whitelistRoles[${index}]`, `白名单身份组第 ${index + 1} 项不是纯数字的 KOOK 身份组 ID,已忽略`);
252
+ if (roleId === '0')
253
+ return fatal(`whitelistRoles[${index}]`, `白名单身份组第 ${index + 1} 项是 0(全体成员),放进来会让人人免检。请改成手动管理的身份组`);
254
+ const managed = roleId === memberRole || (config.roleMap ?? []).some((e) => (0, util_1.normalizeKookId)(e?.roleId) === roleId);
255
+ if (managed)
256
+ fatal(`whitelistRoles[${index}]`, `白名单身份组第 ${index + 1} 项是「成员」或 roleMap 里的身份组,它们由插件发放,放进来会让人人免检。请改成手动管理的身份组`);
257
+ });
258
+ if (config.corpRoles && !String(config.corpRoleName ?? '').includes('{ticker}')) {
259
+ fatal('corpRoleName', 'corpRoleName 里要有 {ticker},否则所有军团会共用同一个身份组');
260
+ }
261
+ if (config.corpChannels) {
262
+ if (!config.corpRoles)
263
+ warn('corpChannels', 'corpChannels 只在 corpRoles 打开时生效,现在按关闭处理;请同时打开 corpRoles');
264
+ if (!String(config.corpCategoryName ?? '').includes('{ticker}')) {
265
+ fatal('corpCategoryName', 'corpCategoryName 里要有 {ticker},否则所有军团会撞同一个分组');
266
+ }
267
+ const template = config.corpChannelTemplate ?? [];
268
+ if (!template.length)
269
+ fatal('corpChannelTemplate', 'corpChannelTemplate 至少要有 1 个频道');
270
+ if (template.length > 10)
271
+ fatal('corpChannelTemplate', 'corpChannelTemplate 最多 10 个频道(一轮会建好几个分组,太多会撞 KOOK 的频道数上限)');
272
+ template.forEach((item, index) => {
273
+ if (!String(item?.name ?? '').trim())
274
+ fatal(`corpChannelTemplate[${index}].name`, `corpChannelTemplate 第 ${index + 1} 项没有名字`);
275
+ });
276
+ }
277
+ ;
278
+ (config.qqWhitelist ?? []).forEach((value, index) => {
279
+ if (!(0, util_1.normalizeId)(value))
280
+ warn(`qqWhitelist[${index}]`, `白名单 QQ 号第 ${index + 1} 项不是合法的 QQ 号,已忽略`);
281
+ });
217
282
  (config.qqAcceptGroups ?? []).forEach((value, index) => {
218
283
  if (!(0, util_1.normalizeId)(value))
219
284
  warn(`qqAcceptGroups[${index}]`, `QQ 群列表第 ${index + 1} 项不是合法的群号,已忽略`);
@@ -261,6 +326,15 @@ function checkAaGroups(config, groups) {
261
326
  }
262
327
  return result;
263
328
  }
329
+ /** Corp channel groups only work together with corp roles (a group needs the corp role to hide it from everyone else). */
330
+ const corpChannelsOn = (config) => !!config.corpRoles && !!config.corpChannels;
331
+ exports.corpChannelsOn = corpChannelsOn;
332
+ /** The channels to make in every group; items without a name are dropped (validateConfig reports them). */
333
+ function normalizedCorpTemplate(config) {
334
+ return (config.corpChannelTemplate ?? [])
335
+ .filter((item) => String(item?.name ?? '').trim())
336
+ .map((item) => ({ type: item.type === 'voice' ? 'voice' : 'text', name: item.name.trim() }));
337
+ }
264
338
  /** The numbers and ids policy.ts needs, normalised (bad entries dropped; validateConfig reports them). */
265
339
  function toPolicyConfig(config) {
266
340
  return {
@@ -270,6 +344,8 @@ function toPolicyConfig(config) {
270
344
  memberRoleId: (0, util_1.normalizeKookId)(config.memberRoleId) ?? '',
271
345
  roleMap: normalizedRoleMap(config),
272
346
  whitelist: (config.whitelist ?? []).map((v) => (0, util_1.normalizeKookId)(v)).filter((v) => !!v),
347
+ whitelistRoles: (config.whitelistRoles ?? []).map((v) => (0, util_1.normalizeKookId)(v)).filter((v) => !!v),
348
+ qqWhitelist: (config.qqWhitelist ?? []).map((v) => (0, util_1.normalizeId)(v)).filter((v) => !!v),
273
349
  nicknameSync: config.nicknameSync,
274
350
  keepUnlinkedRoles: config.keepUnlinkedRoles,
275
351
  breakerCount: config.breakerCount,
package/lib/corp.d.ts ADDED
@@ -0,0 +1,102 @@
1
+ export declare function parseTicker(card: string | null | undefined): string | null;
2
+ /** Mapping key of a ticker: `kr.s` and `KR.S` are one corp. */
3
+ export declare const tickerKey: (ticker: string) => string;
4
+ /** `[{ticker}]` + `KR.S` -> `[KR.S]`. */
5
+ export declare function renderCorpRoleName(template: string, ticker: string): string;
6
+ /** What the member judgement says about one person (the member group only; roleMap groups do not matter here). */
7
+ export interface CorpPerson {
8
+ kookId: string;
9
+ /** Role ids the person holds now, as strings. */
10
+ roles: string[];
11
+ decision: 'allow' | 'deny' | 'unknown';
12
+ /** AA name card (only meaningful for `allow`). */
13
+ card: string | null;
14
+ }
15
+ export interface CorpAction {
16
+ kookId: string;
17
+ /** The corp the person belongs to now (allow + parsable card), else null. */
18
+ ticker: string | null;
19
+ /** Ticker whose role must be given (it may not exist yet); null = nothing to give. */
20
+ grant: string | null;
21
+ /** Role ids (from the mapping) to take back. */
22
+ revoke: string[];
23
+ }
24
+ export interface CorpPlan {
25
+ /** Only people with something to do. */
26
+ actions: CorpAction[];
27
+ /** People judged `allow`, and how many of them have no readable ticker (for the "card format changed?" check). */
28
+ allowCount: number;
29
+ unparsedCount: number;
30
+ }
31
+ /**
32
+ * `mapping` is ticker -> role id of the roles the plugin made or claimed; it is the only set of roles ever given or taken.
33
+ * allow + ticker -> exactly that corp's role (others from the mapping go); deny -> every mapped corp role goes;
34
+ * unknown, or allow without a readable ticker -> nothing is touched.
35
+ */
36
+ export declare function planCorp(people: CorpPerson[], mapping: Readonly<Record<string, string>>): CorpPlan;
37
+ /** What is stored per corp in kv `corpChannels:<guildId>` (key = ticker, upper case). */
38
+ export interface CorpChannelEntry {
39
+ categoryId: string;
40
+ /** Template item (`type:name`) -> channel id. */
41
+ channelIds: Record<string, string>;
42
+ /** Channel ids (category included) whose permissions are set and read back. */
43
+ secured: string[];
44
+ createdAt: number;
45
+ /** Nothing left to make or secure. */
46
+ done: boolean;
47
+ /** Rounds spent finishing a half-made group. */
48
+ attempts?: number;
49
+ /** An existing category with the same name was taken over; its permissions were not touched. */
50
+ adopted?: boolean;
51
+ /** The category is gone from KOOK (the owner deleted it): never made again. */
52
+ deleted?: boolean;
53
+ /** Finishing failed too often: left as it is, the owner has been told. */
54
+ stopped?: boolean;
55
+ /** The corp role the permissions were set for (the role was made again under a new id -> they are set again). */
56
+ roleId?: string;
57
+ /** The category was not in the channel list in the last patrol (written off only when it is missing twice in a row). */
58
+ missing?: boolean;
59
+ /** Written before the category is asked for (`categoryId` is '' until it is known): a lost answer is found again by name. */
60
+ pending?: {
61
+ name: string;
62
+ at: number;
63
+ };
64
+ }
65
+ export interface CorpChannelInput {
66
+ /** Ticker -> number of linked members who hold (or are about to hold) the corp role. */
67
+ holders: Readonly<Record<string, number>>;
68
+ /** Ticker -> role id, only roles that are safe to use. */
69
+ mapping: Readonly<Record<string, string>>;
70
+ entries: Readonly<Record<string, CorpChannelEntry>>;
71
+ /** The channel list as read now (must be a complete, trusted list). */
72
+ channels: ReadonlyArray<{
73
+ id: string;
74
+ name: string;
75
+ isCategory: boolean;
76
+ }>;
77
+ categoryName: (ticker: string) => string;
78
+ minMembers: number;
79
+ /** Tickers (upper case) that get no group. */
80
+ exclude: ReadonlySet<string>;
81
+ /** New groups per run. */
82
+ limit: number;
83
+ }
84
+ export interface CorpChannelPlan {
85
+ /** Entries whose category is not in the list any more: marked deleted, never made again. */
86
+ deleted: string[];
87
+ /** Half-made groups to finish. */
88
+ repair: string[];
89
+ /** A category of the same name exists and no entry has it: take it over, touch nothing. */
90
+ adopt: Array<{
91
+ ticker: string;
92
+ categoryId: string;
93
+ }>;
94
+ /** Groups to make this run (at most `limit`). */
95
+ create: string[];
96
+ /** Groups that qualify but wait for the next run. */
97
+ deferred: string[];
98
+ /** Finished groups whose corp has nobody now (kept, only mentioned). */
99
+ empty: string[];
100
+ }
101
+ /** Pure: which groups to make, finish, take over or write off. Never decides to delete anything. */
102
+ export declare function planCorpChannels(input: CorpChannelInput): CorpChannelPlan;
package/lib/corp.js ADDED
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ // Corp roles (军团身份组), pure part: reading the corp ticker from an AA name card and deciding, per person, which
3
+ // corp role to give and which to take back. No clock, no database, no network (guard.ts carries the plan out).
4
+ // Rules are written out in docs/DESIGN.md ("军团身份组").
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.tickerKey = void 0;
7
+ exports.parseTicker = parseTicker;
8
+ exports.renderCorpRoleName = renderCorpRoleName;
9
+ exports.planCorp = planCorp;
10
+ exports.planCorpChannels = planCorpChannels;
11
+ /** `[KR.S] ggbomb - 小七` -> `KR.S`. The ticker is whatever sits in the first square brackets at the very start. */
12
+ const TICKER = /^\s*\[([^[\]\r\n\t]{1,16})\]/;
13
+ function parseTicker(card) {
14
+ const match = TICKER.exec(card ?? '');
15
+ const ticker = match?.[1].trim();
16
+ return ticker ? ticker : null;
17
+ }
18
+ /** Mapping key of a ticker: `kr.s` and `KR.S` are one corp. */
19
+ const tickerKey = (ticker) => ticker.toUpperCase();
20
+ exports.tickerKey = tickerKey;
21
+ /** `[{ticker}]` + `KR.S` -> `[KR.S]`. */
22
+ function renderCorpRoleName(template, ticker) {
23
+ return template.split('{ticker}').join(ticker);
24
+ }
25
+ /**
26
+ * `mapping` is ticker -> role id of the roles the plugin made or claimed; it is the only set of roles ever given or taken.
27
+ * allow + ticker -> exactly that corp's role (others from the mapping go); deny -> every mapped corp role goes;
28
+ * unknown, or allow without a readable ticker -> nothing is touched.
29
+ */
30
+ function planCorp(people, mapping) {
31
+ const mapped = new Set(Object.values(mapping));
32
+ const actions = [];
33
+ let allowCount = 0;
34
+ let unparsedCount = 0;
35
+ for (const person of people) {
36
+ const held = person.roles.filter((id) => mapped.has(id));
37
+ if (person.decision === 'deny') {
38
+ if (held.length)
39
+ actions.push({ kookId: person.kookId, ticker: null, grant: null, revoke: held });
40
+ continue;
41
+ }
42
+ if (person.decision !== 'allow')
43
+ continue;
44
+ allowCount++;
45
+ const raw = parseTicker(person.card);
46
+ const ticker = raw === null ? null : (0, exports.tickerKey)(raw);
47
+ if (!ticker) {
48
+ unparsedCount++;
49
+ continue;
50
+ }
51
+ const want = mapping[ticker];
52
+ const revoke = held.filter((id) => id !== want);
53
+ const grant = want !== undefined && person.roles.includes(want) ? null : ticker;
54
+ if (grant !== null || revoke.length)
55
+ actions.push({ kookId: person.kookId, ticker, grant, revoke });
56
+ }
57
+ return { actions, allowCount, unparsedCount };
58
+ }
59
+ /** Pure: which groups to make, finish, take over or write off. Never decides to delete anything. */
60
+ function planCorpChannels(input) {
61
+ const plan = { deleted: [], repair: [], adopt: [], create: [], deferred: [], empty: [] };
62
+ const categories = input.channels.filter((c) => c.isCategory);
63
+ const present = new Set(categories.map((c) => c.id));
64
+ const claimed = new Set(Object.values(input.entries).map((e) => e.categoryId));
65
+ for (const [ticker, entry] of Object.entries(input.entries)) {
66
+ if (entry.deleted)
67
+ continue;
68
+ if (!present.has(entry.categoryId))
69
+ plan.deleted.push(ticker);
70
+ else if (!entry.done && !entry.stopped && input.mapping[ticker])
71
+ plan.repair.push(ticker);
72
+ else if (entry.done && !entry.adopted && !(input.holders[ticker] > 0))
73
+ plan.empty.push(ticker);
74
+ }
75
+ const candidates = Object.keys(input.mapping)
76
+ .filter((t) => !(t in input.entries) && !input.exclude.has(t) && (input.holders[t] ?? 0) >= input.minMembers)
77
+ .sort((a, b) => (input.holders[b] ?? 0) - (input.holders[a] ?? 0) || a.localeCompare(b));
78
+ for (const ticker of candidates) {
79
+ const same = categories.find((c) => c.name === input.categoryName(ticker) && !claimed.has(c.id));
80
+ if (same) {
81
+ claimed.add(same.id);
82
+ plan.adopt.push({ ticker, categoryId: same.id });
83
+ }
84
+ else if (plan.create.length < input.limit)
85
+ plan.create.push(ticker);
86
+ else
87
+ plan.deferred.push(ticker);
88
+ }
89
+ return plan;
90
+ }
package/lib/guard.d.ts CHANGED
@@ -27,11 +27,22 @@ export interface ExecStats {
27
27
  problems: string[];
28
28
  /** AA "cannot tell" notes, once per (person, reason) a day: patrol summary and log only. */
29
29
  notes: string[];
30
+ /** Corp roles (军团身份组): given / taken back / newly made (in report mode: would be). */
31
+ corpGrants: number;
32
+ corpRevokes: number;
33
+ corpCreates: number;
34
+ /** Corp channel groups newly made (in report mode: would be). */
35
+ corpGroups: number;
36
+ /** Corp tickers whose role was not made this run (limit per run); they are retried next round. */
37
+ corpDeferred: Set<string>;
38
+ /** Corp tickers whose role must not be made, claimed or given this run (blocked, deferred or unsafe); asked once per run. */
39
+ corpSkip: Set<string>;
30
40
  /** New write failures (first time recorded): the only lines pushed to ops outside a patrol. */
31
41
  alerts: string[];
32
42
  /** The round was cut short (KOOK offline). */
33
43
  aborted: boolean;
34
44
  }
45
+ export declare const emptyStats: () => ExecStats;
35
46
  export declare class Guard implements GuardControl {
36
47
  private ctx;
37
48
  private config;
@@ -55,6 +66,7 @@ export declare class Guard implements GuardControl {
55
66
  private roleCache;
56
67
  private failures;
57
68
  private failuresSnapshot;
69
+ private corpGroupReset;
58
70
  private notesSeen;
59
71
  private master;
60
72
  private notesDirty;
@@ -69,6 +81,14 @@ export declare class Guard implements GuardControl {
69
81
  private deferred;
70
82
  private names;
71
83
  private lastPatrolText;
84
+ /** Corp tickers whose role is being made right now (one creation per ticker at a time). */
85
+ private corpCreating;
86
+ /** Serialises changes of the stored corp mapping. */
87
+ private corpMapChain;
88
+ /** Corp roles are made / claimed one after the other (the role count and the 95 limit stay right). */
89
+ private corpMakeChain;
90
+ /** When roles were made by a non-patrol path (last 24 hours). */
91
+ private corpEventCreates;
72
92
  constructor(ctx: Context, config: Config, options?: GuardOptions);
73
93
  private load;
74
94
  get paused(): boolean;
@@ -122,6 +142,49 @@ export declare class Guard implements GuardControl {
122
142
  /** Send one reminder privately; returns true when it was delivered. Failed `new` / `last` ones go to `pings`. */
123
143
  private remind;
124
144
  private kickOne;
145
+ private readCorpMap;
146
+ /** Change the stored mapping one change at a time (read, change, write), so two tickers never overwrite each other. */
147
+ private updateCorpMap;
148
+ /** Role ids the plugin manages in other ways (never claimed as a corp role). */
149
+ private otherManagedRoleIds;
150
+ /**
151
+ * Decide the corp role work of one `execute` call: read the mapping, drop mapped roles that are gone (patrol only: the
152
+ * role list is read again to be sure, and a big "everything vanished" is not believed), leave out mapped roles that
153
+ * became unsafe, work out per person what to give / take back, and stop everything (alert) when the AA name card
154
+ * format looks changed or too many corp roles would be taken back at once. Null = corp roles are off or could not be prepared.
155
+ * In report mode nothing is written; the counts and the lines about roles that would be made / claimed go into `stats`.
156
+ */
157
+ private prepareCorp;
158
+ /** Report mode: say what sync would do about roles (claim a same-name role, make a new one, hit the limit). */
159
+ private reportCorp;
160
+ /** Take back old corp roles, then give the right one (made first when it does not exist yet). */
161
+ private applyCorp;
162
+ /** The role id for a corp ticker: from the mapping, a same-name role claimed, or a new one. Null when it cannot be had now. */
163
+ private ensureCorpRole;
164
+ private makeCorpRole;
165
+ private readCorpChannels;
166
+ private corpGroupSummary;
167
+ /** Linked members per ticker who hold the corp role now or are about to (this run's decision). */
168
+ private corpHolders;
169
+ /** A "no" from KOOK on a channel call most likely means the bot lacks a permission: say which. */
170
+ private channelCall;
171
+ /**
172
+ * Corp channel groups: one category per corp (hidden from everyone but the corp role and the bot) with the template's
173
+ * channels in it. Patrol only. Never deletes anything. In report mode it only says what would be made.
174
+ * Nothing is written when the channel list could not be read (an unreadable list is not "the owner deleted it").
175
+ * While the bot cannot set permissions (or a group is not hidden yet) no new group is made: a new category is
176
+ * visible to everybody until its permissions are set.
177
+ */
178
+ private prepareCorpChannels;
179
+ /**
180
+ * Make (or finish) one group: the category, its permissions, then every template channel with its permissions.
181
+ * Every id is saved as soon as it exists, so a reload or a failure in the middle never leads to a second group;
182
+ * a later patrol only makes what is missing. The category is hidden before any channel is made in it.
183
+ * Before asking for a category a `pending` note is saved, and a channel is looked for by name in its category first,
184
+ * so an answer that got lost (timeout) does not lead to a duplicate or to a "same name, hands off" take-over.
185
+ * A round counts against the repair limit only when something was really sent to KOOK.
186
+ */
187
+ private fillCorpGroup;
125
188
  /** Patrol now, or after the one that is running. Resolves with the summary text. */
126
189
  requestPatrol(): Promise<string>;
127
190
  /** Same as `requestPatrol` (kept as the plain name for tests and callers). */
@@ -129,6 +192,8 @@ export declare class Guard implements GuardControl {
129
192
  /** Resolves when no patrol is running (does not start one). */
130
193
  patrolIdle(): Promise<void>;
131
194
  private patrolOnce;
195
+ /** A whitelist role that does not exist (typo, other server, deleted and recreated) protects nobody: say so. */
196
+ private checkWhitelistRoles;
132
197
  private patrolSummary;
133
198
  pollEvents(): Promise<void>;
134
199
  /** First run: only remember the newest event id, then do a full patrol. */
@@ -145,6 +210,7 @@ export declare class Guard implements GuardControl {
145
210
  private onBotRemoved;
146
211
  private onLinkChange;
147
212
  pause(actor: string, automatic?: boolean): Promise<string>;
213
+ postCard(actor: string): Promise<string>;
148
214
  resume(actor: string): Promise<string>;
149
215
  patrolNow(): Promise<string>;
150
216
  kickNow(actor: string): Promise<string>;
@@ -157,12 +223,16 @@ export declare class Guard implements GuardControl {
157
223
  kind: 'kook' | 'qq';
158
224
  id: string;
159
225
  }, actor: string): Promise<string>;
226
+ /** One line saying which whitelist the person is on (nothing when none). Roles come from a live lookup. */
227
+ private whitelistLine;
160
228
  inspect(target: {
161
229
  kind: 'kook' | 'qq';
162
230
  id: string;
163
231
  }, options?: {
164
232
  full?: boolean;
165
233
  }): Promise<string>;
234
+ /** Lines for kookaa.check: the corp ticker from the card, and the corp roles the person holds (live lookup). */
235
+ private corpInspectLines;
166
236
  configErrorsText(): string;
167
237
  statusReport(): Promise<string>;
168
238
  }