@atri-bot/core 2.0.0-beta.1 → 2.0.0-beta.3
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 +11 -0
- package/dist/index.d.mts +18 -15
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<img src="https://github.com/HkTeamX/ATRI/blob/main/ATRI.png?raw=true" align="right" style="height:530px;width:450px;" alt="logo"/>
|
|
2
|
+
|
|
3
|
+
# 🤖 ATRI
|
|
4
|
+
|
|
5
|
+
基于 [NapCat](https://github.com/NapNeko/NapCatQQ) 设计的机器人框架
|
|
6
|
+
|
|
7
|
+
取名来自 [亚托莉(ATRI)](https://mzh.moegirl.org.cn/%E4%BA%9A%E6%89%98%E8%8E%89)
|
|
8
|
+
|
|
9
|
+
## 🎉 [更新日志](./CHANGELOG.md)
|
|
10
|
+
|
|
11
|
+
## 📑 [开发文档](https://atri.huankong.top)
|
package/dist/index.d.mts
CHANGED
|
@@ -149,7 +149,7 @@ declare class Bot {
|
|
|
149
149
|
}
|
|
150
150
|
//#endregion
|
|
151
151
|
//#region src/plugin.d.ts
|
|
152
|
-
interface
|
|
152
|
+
interface PluginRuntime<T extends object = object, Extra extends object = object> {
|
|
153
153
|
atri: ATRI;
|
|
154
154
|
bot: ATRI['bot'];
|
|
155
155
|
ws: ATRI['bot']['ws'];
|
|
@@ -157,19 +157,22 @@ interface Plugin<T extends object = object> extends PluginOptions<T> {
|
|
|
157
157
|
logger: Logger;
|
|
158
158
|
refreshConfig: () => Promise<void>;
|
|
159
159
|
saveConfig: (config?: T) => Promise<void>;
|
|
160
|
-
regMessageEvent: <K extends keyof MessageHandler>(this: Plugin<T>, event: Omit<MessageEvent<K>, 'type' | 'pluginName'>) => void;
|
|
161
|
-
regCommandEvent: <K extends keyof MessageHandler, U extends Argv>(this: Plugin<T>, event: Omit<CommandEvent<K, U>, 'type' | 'pluginName'>) => void;
|
|
162
|
-
regNoticeEvent: <K extends keyof NoticeHandler>(this: Plugin<T>, event: Omit<NoticeEvent<K>, 'type' | 'pluginName'>) => void;
|
|
163
|
-
regRequestEvent: <K extends keyof RequestHandler>(this: Plugin<T>, event: Omit<RequestEvent<K>, 'type' | 'pluginName'>) => void;
|
|
160
|
+
regMessageEvent: <K extends keyof MessageHandler>(this: Plugin<T, Extra>, event: Omit<MessageEvent<K>, 'type' | 'pluginName'>) => void;
|
|
161
|
+
regCommandEvent: <K extends keyof MessageHandler, U extends Argv>(this: Plugin<T, Extra>, event: Omit<CommandEvent<K, U>, 'type' | 'pluginName'>) => void;
|
|
162
|
+
regNoticeEvent: <K extends keyof NoticeHandler>(this: Plugin<T, Extra>, event: Omit<NoticeEvent<K>, 'type' | 'pluginName'>) => void;
|
|
163
|
+
regRequestEvent: <K extends keyof RequestHandler>(this: Plugin<T, Extra>, event: Omit<RequestEvent<K>, 'type' | 'pluginName'>) => void;
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
type Plugin<T extends object = object, Extra extends object = object> = PluginRuntime<T, Extra> & PluginOptions<T, Extra>;
|
|
166
|
+
type PluginOptions<T extends object = object, Extra extends object = object> = Extra & {
|
|
166
167
|
defaultConfig?: T;
|
|
168
|
+
config?: T;
|
|
167
169
|
pluginName: string;
|
|
168
|
-
install: (
|
|
169
|
-
uninstall: (
|
|
170
|
-
}
|
|
171
|
-
type definePluginReturnType<T extends object> = (atri: ATRI) => Promise<Plugin<T>>;
|
|
172
|
-
declare function definePlugin<T extends object>(_pluginOptions: PluginOptions<T>
|
|
170
|
+
install: () => MaybePromise<void>;
|
|
171
|
+
uninstall: () => MaybePromise<void>;
|
|
172
|
+
} & ThisType<Plugin<T, Extra>>;
|
|
173
|
+
type definePluginReturnType<T extends object, Extra extends object = object> = (atri: ATRI) => Promise<Plugin<T, Extra>>;
|
|
174
|
+
declare function definePlugin<T extends object, Extra extends object = object>(_pluginOptions: PluginOptions<T, Extra>): definePluginReturnType<T, Extra>;
|
|
175
|
+
declare function definePlugin<T extends object, Extra extends object = object>(_pluginOptions: () => MaybePromise<PluginOptions<T, Extra>>): definePluginReturnType<T, Extra>;
|
|
173
176
|
//#endregion
|
|
174
177
|
//#region src/atri.d.ts
|
|
175
178
|
interface ATRIConfig {
|
|
@@ -179,14 +182,14 @@ interface ATRIConfig {
|
|
|
179
182
|
logDir: string;
|
|
180
183
|
saveLogs: boolean;
|
|
181
184
|
maxFiles?: number;
|
|
182
|
-
plugins?: definePluginReturnType<any>[];
|
|
185
|
+
plugins?: definePluginReturnType<any, any>[];
|
|
183
186
|
}
|
|
184
187
|
declare class ATRI {
|
|
185
188
|
config: ATRIConfig;
|
|
186
189
|
logger: Logger;
|
|
187
190
|
bot: Bot;
|
|
188
191
|
plugins: {
|
|
189
|
-
[key: string]: Plugin<any>;
|
|
192
|
+
[key: string]: Plugin<any, any>;
|
|
190
193
|
};
|
|
191
194
|
configs: {
|
|
192
195
|
[key: string]: any;
|
|
@@ -195,10 +198,10 @@ declare class ATRI {
|
|
|
195
198
|
private removeUselessLogs;
|
|
196
199
|
constructor(config: ATRIConfig);
|
|
197
200
|
init(): Promise<void>;
|
|
198
|
-
installPlugin<T extends object>(plugin: definePluginReturnType<T>): Promise<void>;
|
|
201
|
+
installPlugin<T extends object, Extra extends object>(plugin: definePluginReturnType<T, Extra>): Promise<void>;
|
|
199
202
|
uninstallPlugin(pluginName: string): Promise<void>;
|
|
200
203
|
loadConfig<T extends object>(pluginName: string, defaultConfig?: T, refresh?: boolean): Promise<T>;
|
|
201
204
|
saveConfig<T extends object>(pluginName: string, config: T): Promise<void>;
|
|
202
205
|
}
|
|
203
206
|
//#endregion
|
|
204
|
-
export { ATRI, ATRIConfig, Bot, BotConfig, BotEvents, CommandContext, CommandEvent, MaybePromise, MessageEvent, NonEmptyArray, NoticeEvent, Plugin, PluginOptions, RegEventOptions, RequestEvent, definePlugin, definePluginReturnType, sortObjectArray };
|
|
207
|
+
export { ATRI, ATRIConfig, Bot, BotConfig, BotEvents, CommandContext, CommandEvent, MaybePromise, MessageEvent, NonEmptyArray, NoticeEvent, Plugin, PluginOptions, PluginRuntime, RegEventOptions, RequestEvent, definePlugin, definePluginReturnType, sortObjectArray };
|
package/dist/index.mjs
CHANGED
|
@@ -4,4 +4,4 @@ import e from"node:path";import{LogLevel as t,Logger as n,defaultTransformer as
|
|
|
4
4
|
\\__ \\ \\ __\\ \\_ __ \\ | |
|
|
5
5
|
/ __ \\_ | | | | \\/ | |
|
|
6
6
|
(____ / |__| |__| |__|
|
|
7
|
-
\\/`,`font-family: Consolas;`),this.logger.INFO(`アトリは、高性能ですから!`),await this.bot.init();for(let e of this.config.plugins??[])await this.installPlugin(e);this.logger.INFO(`ATRI 初始化完成`)}async installPlugin(e){let t=await e(this);if(t.pluginName in this.plugins){this.logger.WARN(`插件 ${t.pluginName} 已经安装,跳过本次安装`);return}await t.install(),this.plugins[t.pluginName]=t,this.logger.INFO(`插件 ${t.pluginName} 安装成功`)}async uninstallPlugin(e){let t=this.plugins[e];if(!t){this.logger.WARN(`插件 ${e} 未找到,无法卸载`);return}let n=this.bot.unloaders[e]??[];for(let e of n)e();await t.uninstall(),delete this.plugins[e],this.logger.INFO(`插件 ${e} 卸载成功`)}async loadConfig(t,n,r=!1){if(!n)return{};if(t=this.normalizeConfigKey(t),!r)return this.configs[t]??await this.loadConfig(t,n,!0);await a.ensureDir(this.config.configDir);let i=e.join(this.config.configDir,`${t}.json`);if(!await a.exists(i))return await a.writeJSON(i,n,{spaces:2}),n;try{let e=await a.readJSON(i,`utf-8`),r={...n,...e};return this.configs[t]=r,r}catch(e){return this.logger.ERROR(`插件 ${t} 配置加载失败:`,e),{}}}async saveConfig(t,n){t=this.normalizeConfigKey(t),await a.ensureDir(this.config.configDir);let r=e.join(this.config.configDir,`${t}.json`);await a.writeJSON(r,n,{spaces:2}),Object.assign(this.configs[t],n)}};function f(e){return async t=>{let n=await Promise.resolve(typeof e==`function`?e():e),r={...n,atri:t,bot:t.bot,ws:t.bot.ws,config:await t.loadConfig(n.pluginName,n.defaultConfig),logger:t.logger.clone({title:n.pluginName}),refreshConfig:async()=>{r.config=await t.loadConfig(n.pluginName,n.defaultConfig)},saveConfig:async e=>{await t.saveConfig(n.pluginName,e??r.config)},regMessageEvent:e=>t.bot.regMessageEvent({...e,pluginName:n.pluginName}),regCommandEvent:e=>t.bot.regCommandEvent({...e,pluginName:n.pluginName}),regNoticeEvent:e=>t.bot.regNoticeEvent({...e,pluginName:n.pluginName}),regRequestEvent:e=>t.bot.regRequestEvent({...e,pluginName:n.pluginName})};return r}}export{d as ATRI,u as Bot,f as definePlugin,l as sortObjectArray};
|
|
7
|
+
\\/`,`font-family: Consolas;`),this.logger.INFO(`アトリは、高性能ですから!`),await this.bot.init();for(let e of this.config.plugins??[])await this.installPlugin(e);this.logger.INFO(`ATRI 初始化完成`)}async installPlugin(e){let t=await e(this);if(t.pluginName in this.plugins){this.logger.WARN(`插件 ${t.pluginName} 已经安装,跳过本次安装`);return}await t.install(),this.plugins[t.pluginName]=t,this.logger.INFO(`插件 ${t.pluginName} 安装成功`)}async uninstallPlugin(e){let t=this.plugins[e];if(!t){this.logger.WARN(`插件 ${e} 未找到,无法卸载`);return}let n=this.bot.unloaders[e]??[];for(let e of n)e();await t.uninstall(),delete this.plugins[e],this.logger.INFO(`插件 ${e} 卸载成功`)}async loadConfig(t,n,r=!1){if(!n)return{};if(t=this.normalizeConfigKey(t),!r)return this.configs[t]??await this.loadConfig(t,n,!0);await a.ensureDir(this.config.configDir);let i=e.join(this.config.configDir,`${t}.json`);if(!await a.exists(i))return await a.writeJSON(i,n,{spaces:2}),n;try{let e=await a.readJSON(i,`utf-8`),r={...n,...e};return this.configs[t]=r,r}catch(e){return this.logger.ERROR(`插件 ${t} 配置加载失败:`,e),{}}}async saveConfig(t,n){t=this.normalizeConfigKey(t),await a.ensureDir(this.config.configDir);let r=e.join(this.config.configDir,`${t}.json`);await a.writeJSON(r,n,{spaces:2}),Object.assign(this.configs[t],n)}};function f(e){return async t=>{let n=await Promise.resolve(typeof e==`function`?e():e),r={...n,atri:t,bot:t.bot,ws:t.bot.ws,config:n.config??await t.loadConfig(n.pluginName,n.defaultConfig),logger:t.logger.clone({title:n.pluginName}),refreshConfig:async()=>{n.config||(r.config=await t.loadConfig(n.pluginName,n.defaultConfig))},saveConfig:async e=>{n.config||await t.saveConfig(n.pluginName,e??r.config)},regMessageEvent:e=>t.bot.regMessageEvent({...e,pluginName:n.pluginName}),regCommandEvent:e=>t.bot.regCommandEvent({...e,pluginName:n.pluginName}),regNoticeEvent:e=>t.bot.regNoticeEvent({...e,pluginName:n.pluginName}),regRequestEvent:e=>t.bot.regRequestEvent({...e,pluginName:n.pluginName})};return r}}export{d as ATRI,u as Bot,f as definePlugin,l as sortObjectArray};
|