koishi-plugin-rocom 1.0.1

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.
Files changed (157) hide show
  1. package/lib/client.d.ts +53 -0
  2. package/lib/client.js +473 -0
  3. package/lib/commands/account.d.ts +5 -0
  4. package/lib/commands/account.js +205 -0
  5. package/lib/commands/admin.d.ts +2 -0
  6. package/lib/commands/admin.js +117 -0
  7. package/lib/commands/egg.d.ts +2 -0
  8. package/lib/commands/egg.js +196 -0
  9. package/lib/commands/merchant.d.ts +2 -0
  10. package/lib/commands/merchant.js +242 -0
  11. package/lib/commands/query.d.ts +2 -0
  12. package/lib/commands/query.js +1264 -0
  13. package/lib/commands/wiki.d.ts +2 -0
  14. package/lib/commands/wiki.js +11 -0
  15. package/lib/egg-service.d.ts +229 -0
  16. package/lib/egg-service.js +705 -0
  17. package/lib/index.d.ts +24 -0
  18. package/lib/index.js +3746 -0
  19. package/lib/render-templates/bind-list/index.html +51 -0
  20. package/lib/render-templates/bind-list/style.css +178 -0
  21. package/lib/render-templates/exchange-hall/css/_@astro-renderers.0KDkAyVb.css +1 -0
  22. package/lib/render-templates/exchange-hall/css/index.B3tv56V6.css +1 -0
  23. package/lib/render-templates/exchange-hall/css/index.D2LGPudy.css +1 -0
  24. package/lib/render-templates/exchange-hall/extracted.css +393 -0
  25. package/lib/render-templates/exchange-hall/index.html +99 -0
  26. package/lib/render-templates/exchange-hall/style.css +267 -0
  27. package/lib/render-templates/friendship/index.html +58 -0
  28. package/lib/render-templates/friendship/style.css +182 -0
  29. package/lib/render-templates/home/data/home_item_list.json +122 -0
  30. package/lib/render-templates/home/img/home_icon/100604.png +0 -0
  31. package/lib/render-templates/home/img/home_icon/100604_1.png +0 -0
  32. package/lib/render-templates/home/img/home_icon/100604_2.png +0 -0
  33. package/lib/render-templates/home/img/home_icon/100605.png +0 -0
  34. package/lib/render-templates/home/img/home_icon/100605_1.png +0 -0
  35. package/lib/render-templates/home/img/home_icon/100605_2.png +0 -0
  36. package/lib/render-templates/home/img/home_icon/100606.png +0 -0
  37. package/lib/render-templates/home/img/home_icon/100606_1.png +0 -0
  38. package/lib/render-templates/home/img/home_icon/100606_2.png +0 -0
  39. package/lib/render-templates/home/img/home_icon/100607.png +0 -0
  40. package/lib/render-templates/home/img/home_icon/100607_1.png +0 -0
  41. package/lib/render-templates/home/img/home_icon/100607_2.png +0 -0
  42. package/lib/render-templates/home/img/home_icon/100608.png +0 -0
  43. package/lib/render-templates/home/img/home_icon/100608_1.png +0 -0
  44. package/lib/render-templates/home/img/home_icon/100608_2.png +0 -0
  45. package/lib/render-templates/home/img/home_icon/100622.png +0 -0
  46. package/lib/render-templates/home/img/home_icon/100622_1.png +0 -0
  47. package/lib/render-templates/home/img/home_icon/100622_2.png +0 -0
  48. package/lib/render-templates/home/img/home_icon/100623.png +0 -0
  49. package/lib/render-templates/home/img/home_icon/100623_1.png +0 -0
  50. package/lib/render-templates/home/img/home_icon/100623_2.png +0 -0
  51. package/lib/render-templates/home/img/home_icon/100624.png +0 -0
  52. package/lib/render-templates/home/img/home_icon/100624_1.png +0 -0
  53. package/lib/render-templates/home/img/home_icon/100624_2.png +0 -0
  54. package/lib/render-templates/home/img/home_icon/100627.png +0 -0
  55. package/lib/render-templates/home/img/home_icon/100627_1.png +0 -0
  56. package/lib/render-templates/home/img/home_icon/100627_2.png +0 -0
  57. package/lib/render-templates/home/img/home_icon/100684.png +0 -0
  58. package/lib/render-templates/home/img/home_icon/100684_1.png +0 -0
  59. package/lib/render-templates/home/img/home_icon/100684_2.png +0 -0
  60. package/lib/render-templates/home/img/home_icon/100686.png +0 -0
  61. package/lib/render-templates/home/img/home_icon/100686_1.png +0 -0
  62. package/lib/render-templates/home/img/home_icon/100686_2.png +0 -0
  63. package/lib/render-templates/home/img/home_icon/100687.png +0 -0
  64. package/lib/render-templates/home/img/home_icon/100687_1.png +0 -0
  65. package/lib/render-templates/home/img/home_icon/100687_2.png +0 -0
  66. package/lib/render-templates/home/img/home_icon/100689.png +0 -0
  67. package/lib/render-templates/home/img/home_icon/100689_1.png +0 -0
  68. package/lib/render-templates/home/img/home_icon/100689_2.png +0 -0
  69. package/lib/render-templates/home/img/home_icon/100690.png +0 -0
  70. package/lib/render-templates/home/img/home_icon/100690_1.png +0 -0
  71. package/lib/render-templates/home/img/home_icon/100690_2.png +0 -0
  72. package/lib/render-templates/home/img/home_icon/100691.png +0 -0
  73. package/lib/render-templates/home/img/home_icon/100691_1.png +0 -0
  74. package/lib/render-templates/home/img/home_icon/100691_2.png +0 -0
  75. package/lib/render-templates/home/img/home_icon/100692.png +0 -0
  76. package/lib/render-templates/home/img/home_icon/100692_1.png +0 -0
  77. package/lib/render-templates/home/img/home_icon/100692_2.png +0 -0
  78. package/lib/render-templates/home/img/home_icon/100693.png +0 -0
  79. package/lib/render-templates/home/img/home_icon/100693_1.png +0 -0
  80. package/lib/render-templates/home/img/home_icon/100693_2.png +0 -0
  81. package/lib/render-templates/home/img/home_icon/100694.png +0 -0
  82. package/lib/render-templates/home/img/home_icon/100694_1.png +0 -0
  83. package/lib/render-templates/home/img/home_icon/100694_2.png +0 -0
  84. package/lib/render-templates/home/img/home_icon/100706.png +0 -0
  85. package/lib/render-templates/home/img/home_icon/100706_1.png +0 -0
  86. package/lib/render-templates/home/img/home_icon/100706_2.png +0 -0
  87. package/lib/render-templates/home/img/home_icon/100751.png +0 -0
  88. package/lib/render-templates/home/img/home_icon/100751_1.png +0 -0
  89. package/lib/render-templates/home/img/home_icon/100751_2.png +0 -0
  90. package/lib/render-templates/home/img/home_icon/100755.png +0 -0
  91. package/lib/render-templates/home/img/home_icon/100755_1.png +0 -0
  92. package/lib/render-templates/home/img/home_icon/100755_2.png +0 -0
  93. package/lib/render-templates/home/img/home_icon/100762.png +0 -0
  94. package/lib/render-templates/home/img/home_icon/100762_1.png +0 -0
  95. package/lib/render-templates/home/img/home_icon/100762_2.png +0 -0
  96. package/lib/render-templates/home/img/home_icon/100764.png +0 -0
  97. package/lib/render-templates/home/img/home_icon/100764_1.png +0 -0
  98. package/lib/render-templates/home/img/home_icon/100764_2.png +0 -0
  99. package/lib/render-templates/home/img/home_icon/100869.png +0 -0
  100. package/lib/render-templates/home/img/home_icon/100869_1.png +0 -0
  101. package/lib/render-templates/home/img/home_icon/100869_2.png +0 -0
  102. package/lib/render-templates/home/img/img_HomeVisit_Icon1.png +0 -0
  103. package/lib/render-templates/home/img/img_LevelReward_Bg2.png +0 -0
  104. package/lib/render-templates/home/index.html +139 -0
  105. package/lib/render-templates/home/style.css +537 -0
  106. package/lib/render-templates/ingame-shop/index.html +87 -0
  107. package/lib/render-templates/ingame-shop/style.css +220 -0
  108. package/lib/render-templates/inspect/index.html +47 -0
  109. package/lib/render-templates/inspect/style.css +149 -0
  110. package/lib/render-templates/lineup/index.html +77 -0
  111. package/lib/render-templates/lineup/style.css +255 -0
  112. package/lib/render-templates/lineup-detail/index.html +63 -0
  113. package/lib/render-templates/lineup-detail/style.css +218 -0
  114. package/lib/render-templates/menu/index.html +36 -0
  115. package/lib/render-templates/menu/style.css +126 -0
  116. package/lib/render-templates/package/index.html +115 -0
  117. package/lib/render-templates/package/style.css +352 -0
  118. package/lib/render-templates/personal-card/index.html +292 -0
  119. package/lib/render-templates/personal-card/style.css +2114 -0
  120. package/lib/render-templates/pet-wiki/index.html +118 -0
  121. package/lib/render-templates/pet-wiki/style.css +382 -0
  122. package/lib/render-templates/player-search/index.html +60 -0
  123. package/lib/render-templates/player-search/style.css +192 -0
  124. package/lib/render-templates/record/index.html +86 -0
  125. package/lib/render-templates/record/style.css +322 -0
  126. package/lib/render-templates/searcheggs/Pets.json +104328 -0
  127. package/lib/render-templates/searcheggs/candidates.html +52 -0
  128. package/lib/render-templates/searcheggs/eggs.py +599 -0
  129. package/lib/render-templates/searcheggs/index.html +198 -0
  130. package/lib/render-templates/searcheggs/pair.html +81 -0
  131. package/lib/render-templates/searcheggs/size.html +82 -0
  132. package/lib/render-templates/searcheggs/style.css +586 -0
  133. package/lib/render-templates/searcheggs/want.html +63 -0
  134. package/lib/render-templates/skill-wiki/index.html +68 -0
  135. package/lib/render-templates/skill-wiki/style.css +182 -0
  136. package/lib/render-templates/student/index.html +95 -0
  137. package/lib/render-templates/student/style.css +255 -0
  138. package/lib/render-templates/student-perks/index.html +78 -0
  139. package/lib/render-templates/student-perks/style.css +238 -0
  140. package/lib/render-templates/student-state/index.html +52 -0
  141. package/lib/render-templates/student-state/style.css +157 -0
  142. package/lib/render-templates/yuanxing-shangren/index.html +371 -0
  143. package/lib/render-templates/yuanxing-shangren/style.css +371 -0
  144. package/lib/render.d.ts +11 -0
  145. package/lib/render.js +226 -0
  146. package/lib/role-token.d.ts +27 -0
  147. package/lib/role-token.js +137 -0
  148. package/lib/send-image.d.ts +3 -0
  149. package/lib/send-image.js +135 -0
  150. package/lib/subscription-send.d.ts +8 -0
  151. package/lib/subscription-send.js +48 -0
  152. package/lib/types.d.ts +32 -0
  153. package/lib/types.js +2 -0
  154. package/lib/user.d.ts +67 -0
  155. package/lib/user.js +176 -0
  156. package/package.json +58 -0
  157. package/readme.md +575 -0
package/lib/user.d.ts ADDED
@@ -0,0 +1,67 @@
1
+ export interface Binding {
2
+ binding_id: string;
3
+ login_type: string;
4
+ role_id: string;
5
+ nickname: string;
6
+ bind_time: number;
7
+ is_primary: boolean;
8
+ }
9
+ export interface MerchantSubscription {
10
+ group_id: string;
11
+ channel_id?: string;
12
+ platform?: string;
13
+ user_id?: string;
14
+ type?: string;
15
+ mention_all: boolean;
16
+ items: string[];
17
+ last_push_round: string | null;
18
+ last_matched_items: string[];
19
+ updated_by: string;
20
+ }
21
+ export interface HomeSubscription {
22
+ key: string;
23
+ kind: 'garden' | 'inspiration';
24
+ uid: string;
25
+ channel_id?: string;
26
+ platform?: string;
27
+ guild_id?: string;
28
+ user_id?: string;
29
+ updated_by: string;
30
+ notify_state: {
31
+ first?: boolean;
32
+ all?: boolean;
33
+ };
34
+ updated_at: number;
35
+ last_push_time?: number;
36
+ }
37
+ export declare class UserManager {
38
+ private store;
39
+ constructor(dataDir: string);
40
+ getUserBindings(userId: string): Binding[];
41
+ getPrimaryBinding(userId: string): Binding | null;
42
+ saveUserBindings(userId: string, bindings: Binding[]): void;
43
+ addBinding(userId: string, binding: Binding): void;
44
+ deleteUserBinding(userId: string, index: number): Binding | null;
45
+ switchPrimary(userId: string, index: number): boolean;
46
+ removeBindingById(userId: string, bindingId: string): boolean;
47
+ getAllUsersBindings(): Record<string, Binding[]>;
48
+ }
49
+ export declare class MerchantSubscriptionManager {
50
+ private store;
51
+ constructor(dataDir: string);
52
+ upsert(key: string, sub: MerchantSubscription): void;
53
+ get(key: string): MerchantSubscription | null;
54
+ delete(key: string): boolean;
55
+ getAll(): Record<string, MerchantSubscription>;
56
+ }
57
+ export declare class HomeSubscriptionManager {
58
+ private store;
59
+ constructor(dataDir: string);
60
+ upsert(key: string, sub: HomeSubscription): void;
61
+ deleteMatching(target: {
62
+ platform?: string;
63
+ channelId?: string;
64
+ userId?: string;
65
+ }, kind?: string, uid?: string): number;
66
+ getAll(): Record<string, HomeSubscription>;
67
+ }
package/lib/user.js ADDED
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.HomeSubscriptionManager = exports.MerchantSubscriptionManager = exports.UserManager = void 0;
7
+ const koishi_1 = require("koishi");
8
+ const node_fs_1 = __importDefault(require("node:fs"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const logger = new koishi_1.Logger('rocom-user');
11
+ class JsonStore {
12
+ filePath;
13
+ data;
14
+ constructor(dataDir, filename, defaultData) {
15
+ if (!node_fs_1.default.existsSync(dataDir))
16
+ node_fs_1.default.mkdirSync(dataDir, { recursive: true });
17
+ this.filePath = node_path_1.default.join(dataDir, filename);
18
+ this.data = this.load(defaultData);
19
+ }
20
+ load(defaultData) {
21
+ if (node_fs_1.default.existsSync(this.filePath)) {
22
+ try {
23
+ return JSON.parse(node_fs_1.default.readFileSync(this.filePath, 'utf-8'));
24
+ }
25
+ catch (e) {
26
+ logger.error(`加载 ${this.filePath} 失败: ${e}`);
27
+ }
28
+ }
29
+ return JSON.parse(JSON.stringify(defaultData));
30
+ }
31
+ save() {
32
+ try {
33
+ const tmp = this.filePath + '.tmp';
34
+ node_fs_1.default.writeFileSync(tmp, JSON.stringify(this.data, null, 2), 'utf-8');
35
+ node_fs_1.default.renameSync(tmp, this.filePath);
36
+ }
37
+ catch (e) {
38
+ logger.error(`保存 ${this.filePath} 失败: ${e}`);
39
+ }
40
+ }
41
+ get() { return this.data; }
42
+ set(data) { this.data = data; this.save(); }
43
+ }
44
+ class UserManager {
45
+ store;
46
+ constructor(dataDir) {
47
+ this.store = new JsonStore(dataDir, 'rocom_bindings.json', {});
48
+ }
49
+ getUserBindings(userId) {
50
+ return [...(this.store.get()[userId] || [])];
51
+ }
52
+ getPrimaryBinding(userId) {
53
+ const bindings = this.getUserBindings(userId);
54
+ return bindings.find(b => b.is_primary) || bindings[0] || null;
55
+ }
56
+ saveUserBindings(userId, bindings) {
57
+ const seen = new Set();
58
+ const cleaned = bindings
59
+ .map((binding) => {
60
+ const { framework_token: _frameworkToken, ...rest } = binding;
61
+ return rest;
62
+ })
63
+ .filter((binding) => {
64
+ const id = binding.binding_id || binding.role_id;
65
+ if (seen.has(id))
66
+ return false;
67
+ seen.add(id);
68
+ return true;
69
+ });
70
+ if (cleaned.length > 0 && !cleaned.some(b => b.is_primary)) {
71
+ cleaned[0].is_primary = true;
72
+ }
73
+ const data = this.store.get();
74
+ data[userId] = cleaned;
75
+ this.store.set(data);
76
+ }
77
+ addBinding(userId, binding) {
78
+ const existing = this.getUserBindings(userId);
79
+ existing.forEach(b => b.is_primary = false);
80
+ binding.is_primary = true;
81
+ existing.push(binding);
82
+ this.saveUserBindings(userId, existing);
83
+ }
84
+ deleteUserBinding(userId, index) {
85
+ const bindings = this.getUserBindings(userId);
86
+ if (index < 1 || index > bindings.length)
87
+ return null;
88
+ const removed = bindings.splice(index - 1, 1)[0];
89
+ this.saveUserBindings(userId, bindings);
90
+ return removed;
91
+ }
92
+ switchPrimary(userId, index) {
93
+ const bindings = this.getUserBindings(userId);
94
+ if (index < 1 || index > bindings.length)
95
+ return false;
96
+ bindings.forEach((b, i) => b.is_primary = (i + 1 === index));
97
+ this.saveUserBindings(userId, bindings);
98
+ return true;
99
+ }
100
+ removeBindingById(userId, bindingId) {
101
+ const data = this.store.get();
102
+ const bindings = data[userId] || [];
103
+ const filtered = bindings.filter(b => b.binding_id !== bindingId);
104
+ if (filtered.length < bindings.length) {
105
+ data[userId] = filtered;
106
+ this.store.set(data);
107
+ return true;
108
+ }
109
+ return false;
110
+ }
111
+ getAllUsersBindings() {
112
+ return JSON.parse(JSON.stringify(this.store.get()));
113
+ }
114
+ }
115
+ exports.UserManager = UserManager;
116
+ class MerchantSubscriptionManager {
117
+ store;
118
+ constructor(dataDir) {
119
+ this.store = new JsonStore(dataDir, 'rocom_merchant_subscriptions.json', {});
120
+ }
121
+ upsert(key, sub) {
122
+ const data = this.store.get();
123
+ data[key] = { ...sub };
124
+ this.store.set(data);
125
+ }
126
+ get(key) {
127
+ return this.store.get()[key] || null;
128
+ }
129
+ delete(key) {
130
+ const data = this.store.get();
131
+ if (!(key in data))
132
+ return false;
133
+ delete data[key];
134
+ this.store.set(data);
135
+ return true;
136
+ }
137
+ getAll() {
138
+ return JSON.parse(JSON.stringify(this.store.get()));
139
+ }
140
+ }
141
+ exports.MerchantSubscriptionManager = MerchantSubscriptionManager;
142
+ class HomeSubscriptionManager {
143
+ store;
144
+ constructor(dataDir) {
145
+ this.store = new JsonStore(dataDir, 'rocom_home_subscriptions.json', {});
146
+ }
147
+ upsert(key, sub) {
148
+ const data = this.store.get();
149
+ data[key] = { ...sub };
150
+ this.store.set(data);
151
+ }
152
+ deleteMatching(target, kind = '', uid = '') {
153
+ const data = this.store.get();
154
+ let deleted = 0;
155
+ for (const [key, sub] of Object.entries(data)) {
156
+ const sameTarget = sub.platform === target.platform
157
+ && (sub.channel_id || '') === (target.channelId || '')
158
+ && (sub.user_id || '') === (target.userId || '');
159
+ if (!sameTarget)
160
+ continue;
161
+ if (kind && sub.kind !== kind)
162
+ continue;
163
+ if (uid && sub.uid !== uid)
164
+ continue;
165
+ delete data[key];
166
+ deleted++;
167
+ }
168
+ if (deleted)
169
+ this.store.set(data);
170
+ return deleted;
171
+ }
172
+ getAll() {
173
+ return JSON.parse(JSON.stringify(this.store.get()));
174
+ }
175
+ }
176
+ exports.HomeSubscriptionManager = HomeSubscriptionManager;
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "koishi-plugin-rocom",
3
+ "description": "洛克王国查询与订阅插件",
4
+ "version": "1.0.1",
5
+ "main": "lib/index.js",
6
+ "typings": "lib/index.d.ts",
7
+ "homepage": "https://github.com/staytomorrow/koishi-plugin-rocom",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/staytomorrow/koishi-plugin-rocom.git"
11
+ },
12
+ "files": [
13
+ "lib",
14
+ "dist",
15
+ "readme.md"
16
+ ],
17
+ "license": "MIT",
18
+ "scripts": {
19
+ "build": "tsc -p tsconfig.json --emitDeclarationOnly false --module commonjs --moduleResolution node",
20
+ "postbuild": "node -e \"const fs=require('fs');fs.rmSync('lib/render-templates',{recursive:true,force:true});fs.cpSync('src/render-templates','lib/render-templates',{recursive:true});\"",
21
+ "check": "tsc -p tsconfig.json --noEmit --pretty false",
22
+ "pack:dry": "npm pack --dry-run",
23
+ "prepack": "npm run build"
24
+ },
25
+ "keywords": [
26
+ "chatbot",
27
+ "koishi",
28
+ "plugin",
29
+ "rocom",
30
+ "洛克王国",
31
+ "洛克",
32
+ "订阅",
33
+ "查询"
34
+ ],
35
+ "dependencies": {
36
+ "art-template": "^4.13.4"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.0.0",
40
+ "typescript": "^5.0.0"
41
+ },
42
+ "peerDependencies": {
43
+ "koishi": "^4.18.7",
44
+ "koishi-plugin-puppeteer": "^3.5.3"
45
+ },
46
+ "koishi": {
47
+ "description": {
48
+ "zh": "洛克王国查询与订阅插件,支持精灵、蛋尺寸、背包、家园、远行商人等功能。"
49
+ },
50
+ "service": {
51
+ "required": [
52
+ "puppeteer",
53
+ "database"
54
+ ]
55
+ },
56
+ "preview": true
57
+ }
58
+ }