@kotori-bot/core 1.1.0 → 1.2.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 (85) hide show
  1. package/README.md +5 -0
  2. package/lib/components/config.d.ts +16 -0
  3. package/lib/components/config.js +39 -0
  4. package/lib/components/core.d.ts +33 -0
  5. package/lib/components/core.js +34 -0
  6. package/lib/components/index.d.ts +1 -0
  7. package/lib/components/index.js +17 -0
  8. package/lib/components/message.d.ts +25 -0
  9. package/lib/components/message.js +152 -0
  10. package/lib/components/modules.d.ts +12 -0
  11. package/lib/components/modules.js +118 -0
  12. package/lib/consts.d.ts +10 -8
  13. package/lib/consts.js +12 -8
  14. package/lib/context/context.d.ts +34 -0
  15. package/lib/context/context.js +94 -0
  16. package/lib/context/index.d.ts +2 -0
  17. package/lib/context/index.js +18 -0
  18. package/lib/context/symbols.d.ts +13 -0
  19. package/lib/context/symbols.js +18 -0
  20. package/lib/index.d.ts +5 -11
  21. package/lib/index.js +5 -21
  22. package/lib/{components → service}/adapter.d.ts +15 -12
  23. package/lib/service/adapter.js +119 -0
  24. package/lib/service/api.d.ts +32 -0
  25. package/lib/{components → service}/api.js +12 -14
  26. package/lib/service/cache.d.ts +9 -0
  27. package/lib/service/cache.js +28 -0
  28. package/lib/service/database.d.ts +5 -0
  29. package/lib/service/database.js +14 -0
  30. package/lib/service/elements.d.ts +12 -0
  31. package/lib/service/elements.js +39 -0
  32. package/lib/service/index.d.ts +6 -0
  33. package/lib/service/index.js +22 -0
  34. package/lib/service/service.d.ts +20 -0
  35. package/lib/service/service.js +33 -0
  36. package/lib/types/config.d.ts +24 -0
  37. package/lib/types/core.d.ts +7 -0
  38. package/lib/types/core.js +2 -0
  39. package/lib/types/index.d.ts +5 -0
  40. package/lib/types/index.js +21 -0
  41. package/lib/types/message.d.ts +218 -0
  42. package/lib/types/message.js +17 -0
  43. package/lib/types/modules.d.ts +39 -0
  44. package/lib/types/modules.js +2 -0
  45. package/lib/types/service.d.ts +23 -0
  46. package/lib/types/service.js +3 -0
  47. package/lib/utils/command.d.ts +44 -0
  48. package/lib/utils/command.js +208 -0
  49. package/lib/utils/commandError.d.ts +7 -0
  50. package/lib/utils/commandError.js +13 -0
  51. package/lib/utils/container.d.ts +9 -0
  52. package/lib/utils/container.js +21 -0
  53. package/lib/utils/errror.d.ts +5 -21
  54. package/lib/utils/errror.js +9 -14
  55. package/lib/utils/factory.d.ts +7 -0
  56. package/lib/utils/factory.js +25 -0
  57. package/package.json +10 -7
  58. package/lib/base/command.d.ts +0 -20
  59. package/lib/base/command.js +0 -217
  60. package/lib/base/core.d.ts +0 -30
  61. package/lib/base/core.js +0 -52
  62. package/lib/base/events.d.ts +0 -13
  63. package/lib/base/events.js +0 -41
  64. package/lib/base/filter.d.ts +0 -1
  65. package/lib/base/internal.d.ts +0 -34
  66. package/lib/base/internal.js +0 -89
  67. package/lib/base/message.d.ts +0 -18
  68. package/lib/base/message.js +0 -177
  69. package/lib/base/modules.d.ts +0 -15
  70. package/lib/base/modules.js +0 -205
  71. package/lib/components/adapter.js +0 -128
  72. package/lib/components/api.d.ts +0 -35
  73. package/lib/components/elements.d.ts +0 -12
  74. package/lib/components/elements.js +0 -28
  75. package/lib/components/service.d.ts +0 -13
  76. package/lib/components/service.js +0 -7
  77. package/lib/context.d.ts +0 -13
  78. package/lib/context.js +0 -35
  79. package/lib/types.d.ts +0 -417
  80. package/lib/types.js +0 -81
  81. package/lib/utils/commandExtra.d.ts +0 -6
  82. package/lib/utils/commandExtra.js +0 -11
  83. package/lib/utils/i18n.d.ts +0 -13
  84. package/lib/utils/i18n.js +0 -65
  85. /package/lib/{base/filter.js → types/config.js} +0 -0
@@ -0,0 +1,13 @@
1
+ export declare class Symbols {
2
+ static readonly container: unique symbol;
3
+ static readonly table: unique symbol;
4
+ static readonly containerKey: (prop: string) => symbol;
5
+ static readonly service: unique symbol;
6
+ static readonly adapter: unique symbol;
7
+ static readonly bot: unique symbol;
8
+ static readonly midware: unique symbol;
9
+ static readonly command: unique symbol;
10
+ static readonly regexp: unique symbol;
11
+ static readonly modules: unique symbol;
12
+ }
13
+ export default Symbols;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Symbols = void 0;
4
+ class Symbols {
5
+ static container = Symbol.for('kotori.context.container');
6
+ static table = Symbol.for('kotori.context.table');
7
+ static containerKey = (prop) => Symbol.for(`kotori.context.container.${prop}`);
8
+ /* custom */
9
+ static service = Symbol.for('kotori.core.service');
10
+ static adapter = Symbol.for('kotori.core.adapter');
11
+ static bot = Symbol.for('kotori.core.bot');
12
+ static midware = Symbol.for('kotori.core.midware');
13
+ static command = Symbol.for('kotori.core.command');
14
+ static regexp = Symbol.for('kotori.core.regexp');
15
+ static modules = Symbol.for('kotori.loader.module');
16
+ }
17
+ exports.Symbols = Symbols;
18
+ exports.default = Symbols;
package/lib/index.d.ts CHANGED
@@ -1,17 +1,11 @@
1
- import Context from './context';
2
- export * from './components/adapter';
3
- export * from './components/api';
4
- export * from './components/elements';
5
1
  export * from './context';
2
+ export * from './components';
3
+ export * from './service';
4
+ export * from './utils/command';
6
5
  export * from './utils/errror';
6
+ export * from './utils/commandError';
7
+ export * from './utils/container';
7
8
  export * from './consts';
8
9
  export * from './types';
9
10
  export * from '@kotori-bot/tools';
10
11
  export * from 'tsukiko';
11
- export declare class ContextInstance {
12
- protected constructor();
13
- private static instance;
14
- protected static setInstance(ctx: Context): void;
15
- static getInstance(): Context;
16
- static getMixin(): any;
17
- }
package/lib/index.js CHANGED
@@ -14,30 +14,14 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.ContextInstance = void 0;
18
- const tools_1 = require("@kotori-bot/tools");
19
- __exportStar(require("./components/adapter"), exports);
20
- __exportStar(require("./components/api"), exports);
21
- __exportStar(require("./components/elements"), exports);
22
17
  __exportStar(require("./context"), exports);
18
+ __exportStar(require("./components"), exports);
19
+ __exportStar(require("./service"), exports);
20
+ __exportStar(require("./utils/command"), exports);
23
21
  __exportStar(require("./utils/errror"), exports);
22
+ __exportStar(require("./utils/commandError"), exports);
23
+ __exportStar(require("./utils/container"), exports);
24
24
  __exportStar(require("./consts"), exports);
25
25
  __exportStar(require("./types"), exports);
26
26
  __exportStar(require("@kotori-bot/tools"), exports);
27
27
  __exportStar(require("tsukiko"), exports);
28
- class ContextInstance {
29
- constructor() {
30
- (0, tools_1.none)();
31
- }
32
- static instance = {};
33
- static setInstance(ctx) {
34
- this.instance = ctx;
35
- }
36
- static getInstance() {
37
- return this.instance;
38
- }
39
- static getMixin() {
40
- return Object.assign(ContextInstance.getInstance() /* , Context */);
41
- }
42
- }
43
- exports.ContextInstance = ContextInstance;
@@ -1,8 +1,12 @@
1
1
  import type Api from './api';
2
- import type Context from '../context';
3
- import type { EventDataApiBase, AdapterConfig, EventType, EventDataTargetId, ApiConstructor, ElementsParam, MessageScope } from '../types';
2
+ import { Context } from '../context';
3
+ import { EventDataApiBase, EventsList, EventDataTargetId, AdapterConfig } from '../types';
4
4
  import Service from './service';
5
- interface Status {
5
+ import Elements from './elements';
6
+ type EventApiType = {
7
+ [K in keyof EventsList]: EventsList[K] extends EventDataApiBase ? EventsList[K] : never;
8
+ };
9
+ interface AdapterStatus {
6
10
  value: 'online' | 'offline';
7
11
  createTime: Date;
8
12
  lastMsgTime: Date | null;
@@ -10,29 +14,28 @@ interface Status {
10
14
  sentMsg: number;
11
15
  offlineTimes: number;
12
16
  }
13
- interface AdapterImpl<T extends Api> {
17
+ interface AdapterImpl<T extends Api = Api> extends Service {
18
+ readonly ctx: Context;
14
19
  readonly platform: string;
15
20
  readonly selfId: EventDataTargetId;
16
21
  readonly identity: string;
17
22
  readonly api: T;
18
- readonly status: Status;
23
+ readonly elements: Elements;
24
+ readonly status: AdapterStatus;
19
25
  }
20
- export declare function ApiProxy<T extends Api>(api: T, ctx: Context): T;
21
- type EventApiType = {
22
- [K in Extract<EventType[keyof EventType], EventDataApiBase<keyof EventType, MessageScope>>['type']]: EventType[K];
23
- };
24
26
  export declare abstract class Adapter<T extends Api = Api> extends Service implements AdapterImpl<T> {
25
- constructor(ctx: Context, config: AdapterConfig, identity: string, ApiConstructor: ApiConstructor<T>, el?: ElementsParam);
27
+ constructor(ctx: Context, config: AdapterConfig, identity: string, Api: new (adapter: Adapter) => T, el?: Elements);
26
28
  abstract send(action: string, params?: object): void | object | Promise<unknown> | null | undefined;
27
29
  protected online(): void;
28
30
  protected offline(): void;
29
- protected emit<N extends keyof EventApiType>(type: N, data: Omit<EventApiType[N], 'type' | 'api' | 'send' | 'locale' | 'quick' | 'error' | 'el' | 'messageType'>): void;
31
+ protected session<N extends keyof EventApiType>(type: N, data: Omit<EventApiType[N], 'api' | 'send' | 'i18n' | 'quick' | 'el' | 'error'>): void;
30
32
  readonly ctx: Context;
31
33
  readonly config: AdapterConfig;
32
34
  readonly identity: string;
33
35
  readonly platform: string;
34
36
  readonly api: T;
35
- readonly status: Status;
37
+ readonly elements: Elements;
38
+ readonly status: AdapterStatus;
36
39
  selfId: EventDataTargetId;
37
40
  }
38
41
  export default Adapter;
@@ -0,0 +1,119 @@
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.Adapter = void 0;
7
+ const tools_1 = require("@kotori-bot/tools");
8
+ const context_1 = require("../context");
9
+ const types_1 = require("../types");
10
+ const service_1 = __importDefault(require("./service"));
11
+ const elements_1 = __importDefault(require("./elements"));
12
+ const factory_1 = require("../utils/factory");
13
+ const commandError_1 = __importDefault(require("../utils/commandError"));
14
+ function setProxy(api, ctx) {
15
+ const proxy = Object.create(api);
16
+ proxy.sendPrivateMsg = new Proxy(api.sendPrivateMsg, {
17
+ apply(_, __, argArray) {
18
+ const { '0': message, '1': targetId } = argArray;
19
+ const cancel = (0, factory_1.cancelFactory)();
20
+ ctx.emit('before_send', { api, message, messageType: types_1.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
21
+ if (cancel.value)
22
+ return;
23
+ api.sendPrivateMsg(message, targetId, argArray[2]);
24
+ }
25
+ });
26
+ proxy.sendGroupMsg = new Proxy(api.sendGroupMsg, {
27
+ apply(_, __, argArray) {
28
+ const { '0': message, '1': targetId } = argArray;
29
+ const cancel = (0, factory_1.cancelFactory)();
30
+ ctx.emit('before_send', { api, message, messageType: types_1.MessageScope.PRIVATE, targetId, cancel: cancel.get() });
31
+ if (cancel.value)
32
+ return;
33
+ api.sendGroupMsg(message, targetId, argArray[2]);
34
+ }
35
+ });
36
+ return proxy;
37
+ }
38
+ function sendMessageFactory(adapter, data) {
39
+ if (data.type === types_1.MessageScope.GROUP && 'groupId' in data) {
40
+ return (message) => {
41
+ adapter.api.sendGroupMsg(message, data.groupId, data.extra);
42
+ };
43
+ }
44
+ return (message) => {
45
+ adapter.api.sendPrivateMsg(message, data.userId, data.extra);
46
+ };
47
+ }
48
+ function qucikFactory(send, i18n) {
49
+ return async (message) => {
50
+ const msg = await message;
51
+ if (!msg || msg instanceof commandError_1.default)
52
+ return;
53
+ if (typeof msg === 'string') {
54
+ send(i18n.locale(msg));
55
+ return;
56
+ }
57
+ const params = msg[1];
58
+ Object.keys(params).forEach((key) => {
59
+ if (typeof params[key] !== 'string')
60
+ return;
61
+ params[key] = i18n.locale(params[key]);
62
+ });
63
+ send((0, tools_1.stringTemp)(i18n.locale(msg[0]), params));
64
+ };
65
+ }
66
+ function error(type, data) {
67
+ return new commandError_1.default(Object.assign(data ?? {}, { type }));
68
+ }
69
+ class Adapter extends service_1.default {
70
+ constructor(ctx, config, identity, Api, el = new elements_1.default()) {
71
+ super('adapter', '');
72
+ this.ctx = ctx;
73
+ this.config = config;
74
+ this.identity = identity;
75
+ this.platform = config.extends;
76
+ this.api = setProxy(new Api(this), this.ctx);
77
+ this.elements = el;
78
+ if (!this.ctx[context_1.Symbols.bot].get(this.platform))
79
+ this.ctx[context_1.Symbols.bot].set(this.platform, new Set());
80
+ this.ctx[context_1.Symbols.bot].get(this.platform).add(this.api);
81
+ }
82
+ online() {
83
+ if (this.status.value !== 'offline')
84
+ return;
85
+ this.ctx.emit('status', { adapter: this, status: 'online' });
86
+ this.status.value = 'online';
87
+ }
88
+ offline() {
89
+ if (this.status.value !== 'online')
90
+ return;
91
+ this.ctx.emit('status', { adapter: this, status: 'offline' });
92
+ this.status.value = 'offline';
93
+ this.status.offlineTimes += 1;
94
+ }
95
+ session(type, data) {
96
+ const i18n = this.ctx.i18n.extends(this.config.lang ?? this.ctx.config.global.lang);
97
+ const send = sendMessageFactory(this, data);
98
+ const quick = qucikFactory(send, i18n);
99
+ const { api, elements: el } = this;
100
+ this.ctx.emit(type, { ...data, api, el, send, i18n, quick, error });
101
+ }
102
+ ctx;
103
+ config;
104
+ identity;
105
+ platform;
106
+ api;
107
+ elements;
108
+ status = {
109
+ value: 'offline',
110
+ createTime: new Date(),
111
+ lastMsgTime: null,
112
+ receivedMsg: 0,
113
+ sentMsg: 0,
114
+ offlineTimes: 0
115
+ };
116
+ selfId = -1;
117
+ }
118
+ exports.Adapter = Adapter;
119
+ exports.default = Adapter;
@@ -0,0 +1,32 @@
1
+ import type Adapter from './adapter';
2
+ import type { EventDataTargetId, MessageRaw } from '../types';
3
+ interface ApiImpl {
4
+ readonly adapter: Adapter<this>;
5
+ sendPrivateMsg(message: MessageRaw, userId: EventDataTargetId): void;
6
+ sendGroupMsg(message: MessageRaw, groupId: EventDataTargetId): void;
7
+ deleteMsg(messageId: EventDataTargetId): void;
8
+ setGroupName(groupId: EventDataTargetId, groupName: string): void;
9
+ setGroupAvatar(groupId: EventDataTargetId, image: string): void;
10
+ setGroupAdmin(groupId: EventDataTargetId, userId: EventDataTargetId, enable: boolean): void;
11
+ setGroupCard(groupId: EventDataTargetId, userId: EventDataTargetId, card: string): void;
12
+ setGroupBan(groupId: EventDataTargetId, userId?: EventDataTargetId, time?: number): void;
13
+ sendGroupNotice(groupId: EventDataTargetId, content: string, image?: string): void;
14
+ setGroupKick(groupId: EventDataTargetId, userId: EventDataTargetId): void;
15
+ setGroupLeave(groupId: EventDataTargetId): void;
16
+ }
17
+ export declare abstract class Api implements ApiImpl {
18
+ readonly adapter: Adapter<this>;
19
+ constructor(adapter: Adapter);
20
+ sendPrivateMsg(message: MessageRaw, userId: EventDataTargetId, ...extra: unknown[]): void;
21
+ sendGroupMsg(message: MessageRaw, groupId: EventDataTargetId, ...extra: unknown[]): void;
22
+ deleteMsg(messageId: EventDataTargetId, ...extra: unknown[]): void;
23
+ setGroupName(groupId: EventDataTargetId, groupName: string, ...extra: unknown[]): void;
24
+ setGroupAvatar(groupId: EventDataTargetId, image: string, ...extra: unknown[]): void;
25
+ setGroupAdmin(groupId: EventDataTargetId, userId: EventDataTargetId, enable: boolean, ...extra: unknown[]): void;
26
+ setGroupCard(groupId: EventDataTargetId, userId: EventDataTargetId, card: string, ...extra: unknown[]): void;
27
+ setGroupBan(groupId: EventDataTargetId, userId?: EventDataTargetId, time?: number, ...extra: unknown[]): void;
28
+ sendGroupNotice(groupId: EventDataTargetId, content: string, image?: string, ...extra: unknown[]): void;
29
+ setGroupKick(groupId: EventDataTargetId, userId: EventDataTargetId, ...extra: unknown[]): void;
30
+ setGroupLeave(groupId: EventDataTargetId, ...extra: unknown[]): void;
31
+ }
32
+ export default Api;
@@ -4,42 +4,40 @@ exports.Api = void 0;
4
4
  const tools_1 = require("@kotori-bot/tools");
5
5
  class Api {
6
6
  adapter;
7
- elements;
8
- constructor(adapter, el) {
7
+ constructor(adapter) {
9
8
  this.adapter = adapter;
10
- this.elements = el;
11
9
  }
12
- send_private_msg(message, userId, extra) {
10
+ sendPrivateMsg(message, userId, ...extra) {
13
11
  (0, tools_1.none)(this, message, userId, extra);
14
12
  }
15
- send_group_msg(message, groupId, extra) {
13
+ sendGroupMsg(message, groupId, ...extra) {
16
14
  (0, tools_1.none)(this, message, groupId, extra, extra);
17
15
  }
18
- delete_msg(messageId, extra) {
16
+ deleteMsg(messageId, ...extra) {
19
17
  (0, tools_1.none)(this, messageId, extra);
20
18
  }
21
- set_group_name(groupId, groupName, extra) {
19
+ setGroupName(groupId, groupName, ...extra) {
22
20
  (0, tools_1.none)(this, groupId, groupName, extra);
23
21
  }
24
- set_group_avatar(groupId, image, extra) {
22
+ setGroupAvatar(groupId, image, ...extra) {
25
23
  (0, tools_1.none)(this, groupId, image, extra);
26
24
  }
27
- set_group_admin(groupId, userId, enable, extra) {
25
+ setGroupAdmin(groupId, userId, enable, ...extra) {
28
26
  (0, tools_1.none)(this, groupId, userId, enable, extra);
29
27
  }
30
- set_group_card(groupId, userId, card, extra) {
28
+ setGroupCard(groupId, userId, card, ...extra) {
31
29
  (0, tools_1.none)(this, groupId, userId, card, extra);
32
30
  }
33
- set_group_ban(groupId, userId, time, extra) {
31
+ setGroupBan(groupId, userId, time, ...extra) {
34
32
  (0, tools_1.none)(this, groupId, userId, time, extra);
35
33
  }
36
- send_group_notice(groupId, content, image, extra) {
34
+ sendGroupNotice(groupId, content, image, ...extra) {
37
35
  (0, tools_1.none)(this, groupId, content, image, extra);
38
36
  }
39
- set_group_kick(groupId, userId, extra) {
37
+ setGroupKick(groupId, userId, ...extra) {
40
38
  (0, tools_1.none)(this, groupId, userId, extra);
41
39
  }
42
- set_group_leave(groupId, extra) {
40
+ setGroupLeave(groupId, ...extra) {
43
41
  (0, tools_1.none)(this, groupId, groupId, extra);
44
42
  }
45
43
  }
@@ -0,0 +1,9 @@
1
+ import Service from './service';
2
+ export declare class Cache extends Service {
3
+ private cacheStack?;
4
+ constructor();
5
+ handle(data: unknown[]): void;
6
+ start(): void;
7
+ stop(): void;
8
+ }
9
+ export default Cache;
@@ -0,0 +1,28 @@
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.Cache = void 0;
7
+ const tools_1 = require("@kotori-bot/tools");
8
+ const service_1 = __importDefault(require("./service"));
9
+ class Cache extends service_1.default {
10
+ cacheStack;
11
+ constructor() {
12
+ super('custom', 'cache');
13
+ }
14
+ handle(data) {
15
+ (0, tools_1.none)(this);
16
+ }
17
+ start() {
18
+ this.cacheStack = {};
19
+ }
20
+ stop() {
21
+ Object.keys(this.cacheStack).forEach((key) => {
22
+ delete this.cacheStack[key];
23
+ });
24
+ delete this.cacheStack;
25
+ }
26
+ }
27
+ exports.Cache = Cache;
28
+ exports.default = Cache;
@@ -0,0 +1,5 @@
1
+ import Service from './service';
2
+ export declare abstract class Database extends Service {
3
+ constructor();
4
+ }
5
+ export default Database;
@@ -0,0 +1,14 @@
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.Database = void 0;
7
+ const service_1 = __importDefault(require("./service"));
8
+ class Database extends service_1.default {
9
+ constructor() {
10
+ super('database', '');
11
+ }
12
+ }
13
+ exports.Database = Database;
14
+ exports.default = Database;
@@ -0,0 +1,12 @@
1
+ import type { EventDataTargetId } from '../types';
2
+ export declare class Elements {
3
+ private default;
4
+ at(target: EventDataTargetId, ...extra: unknown[]): string;
5
+ image(url: string, ...extra: unknown[]): string;
6
+ voice(url: string, ...extra: unknown[]): string;
7
+ video(url: string, ...extra: unknown[]): string;
8
+ face(id: number | string, ...extra: unknown[]): string;
9
+ file(data: unknown, ...extra: unknown[]): string;
10
+ supports(): (keyof Elements)[];
11
+ }
12
+ export default Elements;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Elements = void 0;
4
+ const tools_1 = require("@kotori-bot/tools");
5
+ class Elements {
6
+ default(...args) {
7
+ (0, tools_1.none)(this, args);
8
+ return '';
9
+ }
10
+ at(target, ...extra) {
11
+ return this.default(target, extra);
12
+ }
13
+ image(url, ...extra) {
14
+ return this.default(url, extra);
15
+ }
16
+ voice(url, ...extra) {
17
+ return this.default(url, extra);
18
+ }
19
+ video(url, ...extra) {
20
+ return this.default(url, extra);
21
+ }
22
+ face(id, ...extra) {
23
+ return this.default(id, extra);
24
+ }
25
+ file(data, ...extra) {
26
+ return this.default(data, extra);
27
+ }
28
+ supports() {
29
+ const supports = [];
30
+ const keys = ['at', 'image', 'voice', 'video', 'face', 'file'];
31
+ keys.forEach((key) => {
32
+ if (this[key] !== new Elements()[key])
33
+ supports.push(key);
34
+ });
35
+ return supports;
36
+ }
37
+ }
38
+ exports.Elements = Elements;
39
+ exports.default = Elements;
@@ -0,0 +1,6 @@
1
+ export * from './service';
2
+ export * from './adapter';
3
+ export * from './api';
4
+ export * from './elements';
5
+ export * from './database';
6
+ export * from './cache';
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./service"), exports);
18
+ __exportStar(require("./adapter"), exports);
19
+ __exportStar(require("./api"), exports);
20
+ __exportStar(require("./elements"), exports);
21
+ __exportStar(require("./database"), exports);
22
+ __exportStar(require("./cache"), exports);
@@ -0,0 +1,20 @@
1
+ type ModuleType = 'database' | 'adapter' | 'service' | 'plugin';
2
+ type ServiceType = Exclude<ModuleType, 'plugin' | 'service'> | 'custom';
3
+ interface ServiceImpl {
4
+ readonly config: object;
5
+ readonly serviceType: ServiceType;
6
+ readonly service: string;
7
+ handle(...data: unknown[]): void;
8
+ start(): void;
9
+ stop(): void;
10
+ }
11
+ export declare abstract class Service implements ServiceImpl {
12
+ handle(...data: unknown[]): void;
13
+ start(): void;
14
+ stop(): void;
15
+ readonly serviceType: ServiceType;
16
+ readonly service: string;
17
+ readonly config: object;
18
+ constructor(serviceType: ServiceType, service: string, config?: object);
19
+ }
20
+ export default Service;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Service = void 0;
4
+ const tools_1 = require("@kotori-bot/tools");
5
+ class Service {
6
+ handle(...data) {
7
+ return (0, tools_1.none)(this, data);
8
+ }
9
+ start() {
10
+ return (0, tools_1.none)(this);
11
+ }
12
+ stop() {
13
+ return (0, tools_1.none)(this);
14
+ }
15
+ serviceType;
16
+ service;
17
+ config;
18
+ constructor(serviceType, service, config = {}) {
19
+ this.serviceType = serviceType;
20
+ this.config = config;
21
+ if (serviceType === 'adapter') {
22
+ this.service = 'adapter';
23
+ return;
24
+ }
25
+ if (serviceType === 'database') {
26
+ this.service = 'database';
27
+ return;
28
+ }
29
+ this.service = service;
30
+ }
31
+ }
32
+ exports.Service = Service;
33
+ exports.default = Service;
@@ -0,0 +1,24 @@
1
+ import { LocaleType } from '@kotori-bot/i18n';
2
+ import { EventDataTargetId } from '.';
3
+ export interface CoreConfig {
4
+ global: GlobalConfig;
5
+ adapter: {
6
+ [propName: string]: AdapterConfig;
7
+ };
8
+ plugin: {
9
+ [propName: string]: ModuleConfig;
10
+ };
11
+ }
12
+ export interface GlobalConfig {
13
+ lang: LocaleType;
14
+ 'command-prefix': string;
15
+ }
16
+ export interface AdapterConfig {
17
+ extends: string;
18
+ master: EventDataTargetId;
19
+ lang: LocaleType;
20
+ 'command-prefix': string;
21
+ }
22
+ export interface ModuleConfig {
23
+ filter: object;
24
+ }
@@ -0,0 +1,7 @@
1
+ export type EventsList = {
2
+ [K in keyof EventsMapping]: Parameters<EventsMapping[K]>[1] extends never | undefined | null ? Parameters<EventsMapping[K]>[0] : [...Parameters<EventsMapping[K]>];
3
+ };
4
+ export interface EventsMapping {
5
+ ready(): void;
6
+ dispose(): void;
7
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export * from './core';
2
+ export * from './config';
3
+ export * from './modules';
4
+ export * from './message';
5
+ export * from './service';
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./core"), exports);
18
+ __exportStar(require("./config"), exports);
19
+ __exportStar(require("./modules"), exports);
20
+ __exportStar(require("./message"), exports);
21
+ __exportStar(require("./service"), exports);