@atri-bot/core 2.0.0-beta.2 → 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 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
@@ -165,6 +165,7 @@ interface PluginRuntime<T extends object = object, Extra extends object = object
165
165
  type Plugin<T extends object = object, Extra extends object = object> = PluginRuntime<T, Extra> & PluginOptions<T, Extra>;
166
166
  type PluginOptions<T extends object = object, Extra extends object = object> = Extra & {
167
167
  defaultConfig?: T;
168
+ config?: T;
168
169
  pluginName: string;
169
170
  install: () => MaybePromise<void>;
170
171
  uninstall: () => MaybePromise<void>;
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};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@atri-bot/core",
3
3
  "type": "module",
4
- "version": "2.0.0-beta.2",
4
+ "version": "2.0.0-beta.3",
5
5
  "description": "QQBOT TypeScript framework",
6
6
  "author": "huankong233",
7
7
  "license": "MIT",