koishi-plugin-chat-patch 5.5.1 → 5.6.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.
Files changed (43) hide show
  1. package/client/vue/index.vue +8 -1
  2. package/client/web/dist/assets/{Chat-DTEsebnY.css → Chat-BXVWj5Bd.css} +1 -1
  3. package/client/web/dist/assets/{Chat-B5Jdrz_2.js → Chat-m4-U5uHa.js} +4 -4
  4. package/client/web/dist/assets/{MsgBody-tPnKSZOs.js → MsgBody-CzrxyiFO.js} +1 -1
  5. package/client/web/dist/assets/MsgBody.vue_vue_type_script_setup_true_lang-BBF1uxm6.js +67 -0
  6. package/client/web/dist/assets/{index-CSGfOsfr.js → index-EJ2CcODr.js} +70 -76
  7. package/client/web/dist/assets/index-X9hFOAza.css +1 -0
  8. package/client/web/dist/index.html +2 -2
  9. package/client/web/src/App.vue +7 -0
  10. package/client/web/src/assets/css/chat.css +6 -4
  11. package/client/web/src/assets/l10n/zh-CN.po +0 -6
  12. package/client/web/src/components/History.vue +27 -0
  13. package/client/web/src/components/MsgBody.vue +18 -9
  14. package/client/web/src/function/connect.ts +208 -46
  15. package/client/web/src/function/msg.ts +7 -5
  16. package/client/web/src/function/option.ts +1 -1
  17. package/client/web/src/function/satori.ts +64 -0
  18. package/client/web/src/pages/Chat.vue +0 -4
  19. package/client/web/src/pages/Friends.vue +7 -9
  20. package/client/web/src/pages/Messages.vue +2 -2
  21. package/client/web/src/pages/options/OptDev.vue +1 -25
  22. package/client/web/src/pages/options/OptFunction.vue +23 -0
  23. package/client/web/tsconfig.tsbuildinfo +1 -1
  24. package/dist/index.js +1 -1
  25. package/dist/style.css +1 -1
  26. package/lib/bootstrap.d.ts +6 -0
  27. package/lib/database.d.ts +5 -2
  28. package/lib/gateway.d.ts +46 -0
  29. package/lib/index.js +1468 -131
  30. package/lib/recorder.d.ts +3 -5
  31. package/lib/satori.d.ts +3 -0
  32. package/lib/types.d.ts +17 -0
  33. package/package.json +4 -1
  34. package/src/bootstrap.ts +5 -10
  35. package/src/database.ts +745 -662
  36. package/src/gateway.ts +259 -0
  37. package/src/index.ts +63 -53
  38. package/src/recorder.ts +97 -77
  39. package/src/satori.ts +19 -0
  40. package/src/server.d.ts +26 -26
  41. package/src/types.ts +19 -0
  42. package/client/web/dist/assets/MsgBody.vue_vue_type_script_setup_true_lang-ClDybRo_.js +0 -67
  43. package/client/web/dist/assets/index-B71pPwae.css +0 -1
package/lib/recorder.d.ts CHANGED
@@ -1,20 +1,18 @@
1
- import { Context } from 'koishi';
2
1
  import { Config } from './config';
3
2
  import { ContactCacheService } from './cache';
4
3
  import { ChatDatabase } from './database';
5
4
  import { MediaManager } from './media';
6
5
  import { PluginLogger } from './logger';
7
6
  export declare class Recorder {
8
- private ctx;
9
7
  private config;
10
8
  private database;
11
9
  private media;
12
10
  private contactCache;
13
11
  private logger;
14
- constructor(ctx: Context, config: Config, database: ChatDatabase, media: MediaManager, contactCache: ContactCacheService, logger: PluginLogger);
15
- start(): void;
12
+ constructor(config: Config, database: ChatDatabase, media: MediaManager, contactCache: ContactCacheService, logger: PluginLogger);
13
+ handleEvent(body: Record<string, unknown>): Promise<boolean>;
16
14
  private isBlocked;
17
- private handleSession;
15
+ private handleMessageCreated;
18
16
  private handleMessageDeleted;
19
17
  private cacheMessageContacts;
20
18
  private cacheMessageMedia;
@@ -0,0 +1,3 @@
1
+ import { Context } from 'koishi';
2
+ export declare function resolveSatoriEndpoint(ctx: Context): string;
3
+ export declare function toSatoriEventUrl(endpoint: string): string;
package/lib/types.d.ts CHANGED
@@ -3,11 +3,28 @@ export interface SatoriBootstrap {
3
3
  endpoint: string;
4
4
  token: string;
5
5
  basePath: string;
6
+ logins: SatoriLoginInfo[];
6
7
  blockedPlatforms: Array<{
7
8
  platformName: string;
8
9
  exactMatch: boolean;
9
10
  }>;
10
11
  }
12
+ export interface SatoriLoginInfo {
13
+ platform: string;
14
+ selfId: string;
15
+ name: string;
16
+ avatar?: string;
17
+ status: number;
18
+ features?: string[];
19
+ }
20
+ export interface SatoriEventPayload {
21
+ type: string;
22
+ platform: string;
23
+ selfId: string;
24
+ timestamp: number;
25
+ sn: number;
26
+ body: Record<string, unknown>;
27
+ }
11
28
  export interface MessageRecord {
12
29
  id?: string;
13
30
  sequence?: number;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-chat-patch",
3
3
  "description": "[<ruby>chat-patch<rp>(</rp><rt>点我预览效果</rt><rp>)</rp></ruby>](https://i0.hdslb.com/bfs/openplatform/71074dfc9e5256fc3333d8bd8478bec1af874046.png) 视奸小插件((bushi( (低性能警告)。手机端适配。灵感来自 chat 插件。",
4
- "version": "5.5.1",
4
+ "version": "5.6.0",
5
5
  "scripts": {
6
6
  "build:web": "npm --prefix client/web run build",
7
7
  "prepack": "npm run build:web",
@@ -49,8 +49,11 @@
49
49
  "devDependencies": {
50
50
  "@element-plus/icons-vue": "^2.3.2",
51
51
  "@koishijs/client": "^5.11.0",
52
+ "@satorijs/element": "^3.1.8",
53
+ "@satorijs/protocol": "^1.6.1",
52
54
  "@types/mime-types": "^3.0.1",
53
55
  "autoprefixer": "^10.4.23",
56
+ "cosmokit": "^1.0.0",
54
57
  "element-plus": "^2.13.0",
55
58
  "koishi": "^4.16.0",
56
59
  "postcss": "^8.5.6",
package/src/bootstrap.ts CHANGED
@@ -6,31 +6,26 @@ import {} from '@satorijs/plugin-server'
6
6
  import { Config } from './config'
7
7
  import { ChatDatabase } from './database'
8
8
  import { PluginLogger } from './logger'
9
+ import { resolveSatoriEndpoint } from './satori'
9
10
  import { ContactCacheQuery, ContactCacheResult, HistoryQuery, HistoryResult, PluginConfigPayload, SatoriBootstrap } from './types'
10
11
 
11
- function resolveEndpoint(ctx: Context, config: Config): string {
12
- const url = ctx.satori?.server?.url ?? '/satori'
13
- const clean = url.startsWith('undefined') ? url.slice(9) : url
14
- if (/^https?:\/\//i.test(clean)) return clean
15
- const base = ctx.server?.selfUrl ?? ctx.server?.config?.selfUrl ?? ''
16
- return `${base}${clean.startsWith('/') ? clean : `/${clean}`}`
17
- }
18
-
19
12
  export function registerBootstrap(
20
13
  ctx: Context,
21
14
  config: Config,
22
15
  database: ChatDatabase,
23
16
  logger: PluginLogger,
17
+ getLogins: () => SatoriBootstrap['logins'],
24
18
  ) {
25
19
  ctx.console.addListener('chat-patch/bootstrap', (): SatoriBootstrap => {
26
20
  logger.logInfo('返回 Satori bootstrap:', {
27
- endpoint: resolveEndpoint(ctx, config),
21
+ endpoint: resolveSatoriEndpoint(ctx),
28
22
  basePath: config.basePath,
29
23
  })
30
24
  return {
31
- endpoint: resolveEndpoint(ctx, config),
25
+ endpoint: resolveSatoriEndpoint(ctx),
32
26
  token: ctx.satori?.server?.config?.token ?? '',
33
27
  basePath: config.basePath,
28
+ logins: getLogins(),
34
29
  blockedPlatforms: config.blockedPlatforms ?? [],
35
30
  }
36
31
  }, { authority: 4 })