floating-live 0.15.0-beta.8 → 0.15.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/README.md CHANGED
@@ -17,10 +17,10 @@ GUI版本:[Minteea/floating-live-gui](https://github.com/Minteea/floating-live
17
17
  npm install floating-live
18
18
  ```
19
19
  ``` javascript
20
- // 导入FloatingLive
20
+ // 导入FloatingLive本体
21
21
  const { FloatingLive } = require("floating-live")
22
22
  // 导入bilibili房间生成插件
23
- const bilibili = require("@floating-live/bilibili/plugin")
23
+ const bilibili = require("@floating-live/bilibili")
24
24
 
25
25
  // 创建一个FloatingLive实例
26
26
  const live = new FloatingLive()
@@ -11,6 +11,8 @@ export declare class ModCommand {
11
11
  unregister(name: string): void;
12
12
  /** 调用命令 */
13
13
  call<T extends keyof FloatingCommandMap>(name: T, ...args: Parameters<FloatingCommandMap[T]>): any;
14
+ /** 检测命令是否存在 */
15
+ has<T extends keyof FloatingCommandMap>(name: T): boolean;
14
16
  /** 获取快照 */
15
17
  getSnapshot(): string[];
16
18
  }
@@ -21,6 +21,10 @@ class ModCommand {
21
21
  call(name, ...args) {
22
22
  return this.list.get(name)?.(...args);
23
23
  }
24
+ /** 检测命令是否存在 */
25
+ has(name) {
26
+ return this.list.has(name);
27
+ }
24
28
  /** 获取快照 */
25
29
  getSnapshot() {
26
30
  return [...this.list].map(([key]) => key);
@@ -38,7 +38,7 @@ class ModHook {
38
38
  return false;
39
39
  }
40
40
  }
41
- return false;
41
+ return true;
42
42
  }
43
43
  }
44
44
  exports.ModHook = ModHook;
@@ -9,7 +9,11 @@ export declare class ModPlugin {
9
9
  /** 获取当前安装插件 */
10
10
  get currentPlugin(): string | null;
11
11
  /** 注册插件 */
12
- register(pluginFunc: PluginConstructor, config?: any): void;
12
+ register(pluginFunc: PluginConstructor, options?: any): void;
13
13
  /** 移除插件 */
14
14
  unregister(name: string): void;
15
+ /** 获取插件实例 */
16
+ get(name: string): {
17
+ [key: string]: any;
18
+ } | undefined;
15
19
  }
@@ -13,8 +13,8 @@ class ModPlugin {
13
13
  return this.current;
14
14
  }
15
15
  /** 注册插件 */
16
- register(pluginFunc, config) {
17
- const name = pluginFunc.name;
16
+ register(pluginFunc, options) {
17
+ const name = pluginFunc.pluginName;
18
18
  if (!name) {
19
19
  this.main.throw(Object.assign(new TypeError("缺少插件id"), {
20
20
  from: "plugin",
@@ -30,7 +30,7 @@ class ModPlugin {
30
30
  return;
31
31
  }
32
32
  // 执行插件函数
33
- const plugin = new pluginFunc(this.main, config);
33
+ const plugin = new pluginFunc(this.main, options);
34
34
  this.list.set(name, plugin);
35
35
  this.main.emit("plugin:add", name);
36
36
  this.current = null;
@@ -53,5 +53,9 @@ class ModPlugin {
53
53
  // 移除插件注册
54
54
  this.main.emit("plugin:remove", name);
55
55
  }
56
+ /** 获取插件实例 */
57
+ get(name) {
58
+ return this.list.get(name);
59
+ }
56
60
  }
57
61
  exports.ModPlugin = ModPlugin;
@@ -9,7 +9,7 @@ export declare class ModRoom {
9
9
  /** 添加房间监听实例 */
10
10
  addRoom(room: LiveRoom, open?: boolean): void;
11
11
  /** 添加房间 */
12
- add(platform: string, id: number, config?: boolean | Record<string, any>): void;
12
+ add(platform: string, id: number, options?: boolean | Record<string, any>): void;
13
13
  /** 移除房间 */
14
14
  remove(roomKey: string): void;
15
15
  /** 获取房间 */
@@ -81,12 +81,15 @@ class ModRoom {
81
81
  this.main.emit("room:add", key, room.info);
82
82
  }
83
83
  /** 添加房间 */
84
- add(platform, id, config) {
85
- if (typeof config == "boolean") {
86
- config = { open: config };
87
- }
88
- const room = this.main.call(`${platform}.room.create`, id, config);
89
- room && this.addRoom(room);
84
+ add(platform, id, options) {
85
+ const opt = typeof options == "boolean" ? { open: options } : options;
86
+ const ctx = { platform, id, options: opt || {} };
87
+ this.main.hook.call("add", ctx).then((res) => {
88
+ if (!res)
89
+ return;
90
+ const room = this.main.call(`${platform}.room.create`, id, opt);
91
+ room && this.addRoom(room);
92
+ });
90
93
  }
91
94
  /** 移除房间 */
92
95
  remove(roomKey) {
@@ -1,9 +1,9 @@
1
1
  import { LiveRoom } from "../core";
2
2
  export interface FloatingCommandMap {
3
- add: (platform: string, id: number, config?: boolean | Record<string, any>) => void;
3
+ add: (platform: string, id: number, options?: boolean | Record<string, any>) => void;
4
4
  remove: (key: string) => void;
5
5
  open: (key: string) => void;
6
6
  close: (key: string) => void;
7
7
  update: (key: string) => void;
8
- [name: `${string}.room.create`]: (id: string | number, config?: Record<string, any>) => LiveRoom;
8
+ [name: `${string}.room.create`]: (id: string | number, options?: Record<string, any>) => LiveRoom;
9
9
  }
@@ -1,5 +1,9 @@
1
1
  import { Message } from "./message";
2
2
  export interface FloatingHookMap {
3
3
  message: Message.All;
4
- add: Record<string, any>;
4
+ add: {
5
+ platform: string;
6
+ id: string | number;
7
+ options: Record<string, any>;
8
+ };
5
9
  }
@@ -230,7 +230,7 @@ export interface GiftInfo {
230
230
  /** 总价值 */
231
231
  value: number;
232
232
  /** 平台货币 */
233
- currency: string;
233
+ currency?: string | number;
234
234
  /** 礼物连击数 */
235
235
  combo?: string;
236
236
  /** 礼物连击id */
@@ -3,13 +3,14 @@ import { FloatingLive } from "../live";
3
3
  export declare type FloatingLivePlugin<C extends object = object> = () => {
4
4
  /** 插件名称 */
5
5
  name: string;
6
- register: (ctx: FloatingLive, config?: C) => void;
6
+ register: (ctx: FloatingLive, options?: C) => void;
7
7
  destroy?: (ctx: FloatingLive) => void;
8
8
  };
9
9
  export interface IPlugin {
10
- destroy: () => void;
10
+ [key: string]: any;
11
+ destroy?(): void;
11
12
  }
12
13
  export interface PluginConstructor {
13
14
  pluginName: string;
14
- new (ctx: FloatingLive, config: any): IPlugin;
15
+ new (ctx: FloatingLive, options: any): IPlugin;
15
16
  }
@@ -85,12 +85,14 @@ export interface PlatformInfo {
85
85
  /** 统计信息 */
86
86
  stats?: Record<string, string>;
87
87
  /** 货币信息 */
88
- currency?: Record<string, {
89
- /** 货币名称 */
90
- name: string;
91
- /** 1货币面值等值value (1面值/1数值) */
92
- ratio: number;
93
- /** 1单位消费金额等值value (1.00CNY/1数值) (若为0则为免费货币) */
94
- money?: number;
95
- }>;
88
+ currency?: {
89
+ [key: string | number]: {
90
+ /** 货币名称 */
91
+ name: string;
92
+ /** 1货币面值等值value (1面值/1数值) */
93
+ ratio: number;
94
+ /** 1单位消费金额等值value (1.00CNY/1数值) (若为0则为免费货币) */
95
+ money?: number;
96
+ };
97
+ };
96
98
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "floating-live",
3
- "version": "0.15.0-beta.8",
3
+ "version": "0.15.0",
4
4
  "type": "commonjs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",