@atri-bot/core 1.1.12 → 1.1.14
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/dist/index.d.ts +13 -13
- package/dist/index.js +5 -5
- package/package.json +31 -31
package/dist/index.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ interface CommandEvent<Opts extends CommandContext = CommandContext, T extends k
|
|
|
37
37
|
type: 'command';
|
|
38
38
|
endPoint?: T;
|
|
39
39
|
callback: (context: CommandCallback<Opts, T>) => CallbackReturn;
|
|
40
|
-
|
|
40
|
+
packageName: string;
|
|
41
41
|
commandName: string | RegExp;
|
|
42
42
|
commander?: Command;
|
|
43
43
|
priority?: number;
|
|
@@ -53,7 +53,7 @@ interface MessageEvent<T extends keyof MessageHandler = 'message'> {
|
|
|
53
53
|
endPoint?: T;
|
|
54
54
|
regexp?: RegExp;
|
|
55
55
|
callback: (context: MessageCallback<T>) => CallbackReturn;
|
|
56
|
-
|
|
56
|
+
packageName: string;
|
|
57
57
|
priority?: number;
|
|
58
58
|
needReply?: boolean;
|
|
59
59
|
needAdmin?: boolean;
|
|
@@ -65,7 +65,7 @@ interface NoticeEvent<T extends keyof NoticeHandler = 'notice'> {
|
|
|
65
65
|
type: 'notice';
|
|
66
66
|
endPoint?: T;
|
|
67
67
|
callback: (context: NoticeCallback<T>) => CallbackReturn;
|
|
68
|
-
|
|
68
|
+
packageName: string;
|
|
69
69
|
priority?: number;
|
|
70
70
|
}
|
|
71
71
|
interface RequestCallback<T extends keyof RequestHandler = 'request'> {
|
|
@@ -75,27 +75,27 @@ interface RequestEvent<T extends keyof RequestHandler = 'request'> {
|
|
|
75
75
|
type: 'request';
|
|
76
76
|
endPoint?: T;
|
|
77
77
|
callback: (context: RequestCallback<T>) => CallbackReturn;
|
|
78
|
-
|
|
78
|
+
packageName: string;
|
|
79
79
|
priority?: number;
|
|
80
80
|
}
|
|
81
81
|
type RegEventOptions = CommandEvent | MessageEvent | NoticeEvent | RequestEvent;
|
|
82
82
|
type AutoInferCommandEndPoint<Opts extends CommandContext = CommandContext> = {
|
|
83
|
-
[T in keyof MessageHandler]: RemoveField<CommandEvent<Opts, T>, '
|
|
83
|
+
[T in keyof MessageHandler]: RemoveField<CommandEvent<Opts, T>, 'packageName' | 'type'> & {
|
|
84
84
|
endPoint: T;
|
|
85
85
|
};
|
|
86
86
|
}[keyof MessageHandler];
|
|
87
87
|
type AutoInferMessageEndPoint = {
|
|
88
|
-
[T in keyof MessageHandler]: RemoveField<MessageEvent<T>, '
|
|
88
|
+
[T in keyof MessageHandler]: RemoveField<MessageEvent<T>, 'packageName' | 'type'> & {
|
|
89
89
|
endPoint: T;
|
|
90
90
|
};
|
|
91
91
|
}[keyof MessageHandler];
|
|
92
92
|
type AutoInferRequestEndPoint = {
|
|
93
|
-
[T in keyof RequestHandler]: RemoveField<RequestEvent<T>, '
|
|
93
|
+
[T in keyof RequestHandler]: RemoveField<RequestEvent<T>, 'packageName' | 'type'> & {
|
|
94
94
|
endPoint: T;
|
|
95
95
|
};
|
|
96
96
|
}[keyof RequestHandler];
|
|
97
97
|
type AutoInferNoticeEndPoint = {
|
|
98
|
-
[T in keyof NoticeHandler]: RemoveField<NoticeEvent<T>, '
|
|
98
|
+
[T in keyof NoticeHandler]: RemoveField<NoticeEvent<T>, 'packageName' | 'type'> & {
|
|
99
99
|
endPoint: T;
|
|
100
100
|
};
|
|
101
101
|
}[keyof NoticeHandler];
|
|
@@ -115,13 +115,13 @@ declare abstract class BasePlugin<TConfig extends object = object> {
|
|
|
115
115
|
abstract unload(): void | Promise<void>;
|
|
116
116
|
saveConfig(config?: TConfig): void;
|
|
117
117
|
regCommandEvent<Opts extends CommandContext = CommandContext>(options: AutoInferCommandEndPoint<Opts>): () => void;
|
|
118
|
-
regCommandEvent<Opts extends CommandContext = CommandContext>(options: RemoveField<CommandEvent<Opts, 'message'>, '
|
|
118
|
+
regCommandEvent<Opts extends CommandContext = CommandContext>(options: RemoveField<CommandEvent<Opts, 'message'>, 'packageName' | 'type'>): () => void;
|
|
119
119
|
regMessageEvent(options: AutoInferMessageEndPoint): () => void;
|
|
120
|
-
regMessageEvent(options: RemoveField<MessageEvent<'message'>, '
|
|
120
|
+
regMessageEvent(options: RemoveField<MessageEvent<'message'>, 'packageName' | 'type'>): () => void;
|
|
121
121
|
regRequestEvent(options: AutoInferRequestEndPoint): () => void;
|
|
122
|
-
regRequestEvent(options: RemoveField<RequestEvent<'request'>, '
|
|
122
|
+
regRequestEvent(options: RemoveField<RequestEvent<'request'>, 'packageName' | 'type'>): () => void;
|
|
123
123
|
regNoticeEvent(options: AutoInferNoticeEndPoint): () => void;
|
|
124
|
-
regNoticeEvent(options: RemoveField<NoticeEvent<'notice'>, '
|
|
124
|
+
regNoticeEvent(options: RemoveField<NoticeEvent<'notice'>, 'packageName' | 'type'>): () => void;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
type BotConfig = {
|
|
@@ -277,7 +277,7 @@ declare class ATRI extends InjectLogger {
|
|
|
277
277
|
loadPlugin(packageName: string, options?: LoadPluginOptions): Promise<[0, BasePlugin] | [1 | 2, string]>;
|
|
278
278
|
unloadPlugin(packageName: string): Promise<[0] | [1, string]>;
|
|
279
279
|
loadConfig<TConfig extends object>(packageName: string, defaultConfig: TConfig): Promise<{}>;
|
|
280
|
-
saveConfig<TConfig extends object>(
|
|
280
|
+
saveConfig<TConfig extends object>(packageName: string, config: TConfig): Promise<void>;
|
|
281
281
|
addPluginLoadHook(hookName: string, hook: LoadPluginHook): void;
|
|
282
282
|
removePluginLoadHook(hookName: string): void;
|
|
283
283
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
var x=Object.defineProperty;var g=(
|
|
2
|
-
(\u4F7F\u7528 -h \u83B7\u53D6\u5E2E\u52A9\u4FE1\u606F)`)]}else return this.logger.ERROR("\u547D\u4EE4\u5904\u7406\u51FA\u9519:",a),[2,a instanceof Error?a.message:"\u672A\u77E5\u9519\u8BEF"]}return[0,{prefix:
|
|
3
|
-
`)),t=[...
|
|
1
|
+
var x=Object.defineProperty;var g=(m,e)=>x(m,"name",{value:e,configurable:!0});import{InjectLogger as $,Logger as A,LogLevel as _}from"@huan_kong/logger";import{createRequire as I}from"module";import l from"fs";import u from"path";import H from"process";import{InjectLogger as T,Logger as N,LogLevel as b}from"@huan_kong/logger";import{CommanderError as q}from"commander";import{NCWebsocket as w,Structs as f}from"node-napcat-ts";function R(){let m=performance.now();return()=>(performance.now()-m).toFixed(2)}g(R,"performanceCounter");function c(m,e,t="up"){return m.sort((n,o)=>n[e]>o[e]?t==="up"?1:-1:n[e]<o[e]?t==="up"?-1:1:0)}g(c,"sortObjectArray");var h=class m extends T{static{g(this,"Bot")}ws;config;events={command:[],message:[],notice:[],request:[]};constructor(e,t){super({level:e.debug?b.DEBUG:e.logLevel}),this.ws=t,this.config=e,e.debug&&(t.on("api.preSend",n=>this.logger.DEBUG("\u53D1\u9001API\u8BF7\u6C42",n)),t.on("api.response.success",n=>this.logger.DEBUG("\u6536\u5230API\u6210\u529F\u54CD\u5E94",n)),t.on("api.response.failure",n=>this.logger.DEBUG("\u6536\u5230API\u5931\u8D25\u54CD\u5E94",n)),t.on("message",n=>{if(n.message.length===0){this.logger.DEBUG("\u6536\u5230\u7A7A\u6D88\u606F, \u5DF2\u8DF3\u8FC7\u5904\u7406\u6D41\u7A0B:",n);return}this.logger.DEBUG("\u6536\u5230\u6D88\u606F:",n)}),t.on("request",n=>this.logger.DEBUG("\u6536\u5230\u8BF7\u6C42:",n)),t.on("notice",n=>this.logger.DEBUG("\u6536\u5230\u901A\u77E5:",n))),t.on("message",async n=>{if(n.message.length===0)return;let o=`message.${n.message_type}.${n.sub_type}`,s=this.config.adminId.includes(n.user_id),i=n.message[0].type==="reply";for(let r of this.events.message)if(o.includes(r.endPoint??"message")&&(!r.needReply||i)&&(!r.needAdmin||s)&&(!r.regexp||r.regexp.test(n.raw_message)))try{if(await r.callback({context:n})==="quit"){this.logger.DEBUG(`\u63D2\u4EF6 ${r.packageName} \u8BF7\u6C42\u63D0\u524D\u7EC8\u6B62`);break}}catch(d){this.logger.ERROR(`\u63D2\u4EF6 ${r.packageName} \u4E8B\u4EF6\u5904\u7406\u5931\u8D25:`,d)}for(let r of this.events.command)if(o.includes(r.endPoint??"message")&&(!r.needAdmin||s)&&(!r.needReply||i)){let[d,a]=this.parseCommand(n.raw_message,r.commandName,r.commander);if(d===1)continue;if(d===2){await this.sendMsg(n,[f.text(a)]);continue}let{prefix:y,commandName:v,params:p,args:C}=a;try{if(await r.callback({context:n,prefix:y,commandName:v,params:p,args:C})==="quit"){this.logger.DEBUG(`\u63D2\u4EF6 ${r.packageName} \u8BF7\u6C42\u63D0\u524D\u7EC8\u6B62`);break}}catch(E){this.logger.ERROR(`\u63D2\u4EF6 ${r.packageName} \u4E8B\u4EF6\u5904\u7406\u5931\u8D25:`,E)}}}),t.on("request",async n=>{let o=`request.${n.request_type}.${"sub_type"in n?n.sub_type:""}`;for(let s of this.events.request)if(o.includes(s.endPoint??"request"))try{if(await s.callback({context:n})==="quit"){this.logger.DEBUG(`\u63D2\u4EF6 ${s.packageName} \u8BF7\u6C42\u63D0\u524D\u7EC8\u6B62`);break}}catch(i){this.logger.ERROR(`\u63D2\u4EF6 ${s.packageName} \u4E8B\u4EF6\u5904\u7406\u5931\u8D25:`,i)}}),t.on("notice",async n=>{let o=`notice.${n.notice_type}.${"sub_type"in n?n.sub_type:""}`;n.notice_type==="notify"&&(n.sub_type==="input_status"?o+=`.${n.group_id!==0?"group":"friend"}`:n.sub_type==="poke"&&(o+=`.${"group_id"in n?"group":"friend"}`));for(let s of this.events.notice)if(o.includes(s.endPoint??"notice"))try{if(await s.callback({context:n})==="quit"){this.logger.DEBUG(`\u63D2\u4EF6 ${s.packageName} \u8BF7\u6C42\u63D0\u524D\u7EC8\u6B62`);break}}catch(i){this.logger.ERROR(`\u63D2\u4EF6 ${s.packageName} \u4E8B\u4EF6\u5904\u7406\u5931\u8D25:`,i)}}),this.logger.INFO("Bot \u521D\u59CB\u5316\u5B8C\u6210")}static async init(e){return new Promise((t,n)=>{let o=new N({title:"Bot",level:e.debug?b.DEBUG:e.logLevel}),s=new w({...e.connection,reconnection:e.reconnection}),i=R();s.on("socket.connecting",r=>{i=R(),o.INFO(`\u8FDE\u63A5\u4E2D [#${r.reconnection.nowAttempts}/${r.reconnection.attempts}]`)}),s.on("socket.error",r=>{if(o.ERROR(`\u8FDE\u63A5\u5931\u8D25 [#${r.reconnection.nowAttempts}/${r.reconnection.attempts}]`),o.ERROR("\u9519\u8BEF\u4FE1\u606F:",r),r.error_type==="response_error"&&(o.ERROR("NapCat \u670D\u52A1\u7AEF\u8FD4\u56DE\u9519\u8BEF, \u53EF\u80FD\u662F AccessToken \u9519\u8BEF"),process.exit(1)),r.reconnection.nowAttempts>=r.reconnection.attempts)throw n(`\u91CD\u8BD5\u6B21\u6570\u8D85\u8FC7\u8BBE\u7F6E\u7684${r.reconnection.attempts}\u6B21!`),new Error(`\u91CD\u8BD5\u6B21\u6570\u8D85\u8FC7\u8BBE\u7F6E\u7684${r.reconnection.attempts}\u6B21!`)}),s.on("socket.open",async r=>{o.INFO(`\u8FDE\u63A5\u6210\u529F [#${r.reconnection.nowAttempts}/${r.reconnection.attempts}]`),o.INFO(`\u8FDE\u63A5 NapCat \u8017\u65F6: ${i()}ms`),t(new m(e,s))}),s.connect()})}regEvent(e){let t={...e,priority:e.priority??1};switch(t.type){case"command":return this.events.command=c([...this.events.command,t],"priority","down"),()=>{let n=this.events.command.indexOf(t);n!==-1&&this.events.command.splice(n,1)};case"message":return this.events.message=c([...this.events.message,t],"priority","down"),()=>{let n=this.events.message.indexOf(t);n!==-1&&this.events.message.splice(n,1)};case"notice":return this.events.notice=c([...this.events.notice,t],"priority","down"),()=>{let n=this.events.notice.indexOf(t);n!==-1&&this.events.notice.splice(n,1)};case"request":return this.events.request=c([...this.events.request,t],"priority","down"),()=>{let n=this.events.request.indexOf(t);n!==-1&&this.events.request.splice(n,1)}}}parseCommand(e,t,n){let o=e.charAt(0),s=this.config.prefix.find(a=>a===o);if(!s)return[1,"\u672A\u5339\u914D\u5230\u524D\u7F00"];let i=e.split(" ");if(i.length===0)return[1,"\u547D\u4EE4\u4FE1\u606F\u672A\u7A7A"];let r=i[0].slice(s.length),d=i.slice(1).filter(a=>a!=="");if(t!=="*"&&(typeof t=="string"&&t!==r||t instanceof RegExp&&r.match(t)===null))return[1,"\u547D\u4EE4\u540D\u4E0D\u5339\u914D"];if(n)try{let a=n.configureOutput({writeErr:g(()=>{},"writeErr"),writeOut:g(()=>{},"writeOut")}).exitOverride().parse(d,{from:"user"});return[0,{prefix:s,commandName:r,params:a.opts(),args:a.processedArgs}]}catch(a){if(a instanceof q||"code"in a&&"message"in a){let{code:y,message:v}=a;if(y==="commander.helpDisplayed")return[2,this.getCommandHelpInformation(t.toString())??""];let p=v.replace("error:","\u9519\u8BEF:").replace("unknown option","\u672A\u77E5\u9009\u9879").replace("missing required argument","\u7F3A\u5C11\u5FC5\u8981\u53C2\u6570").replace("too many arguments","\u53C2\u6570\u8FC7\u591A").replace("invalid argument","\u65E0\u6548\u53C2\u6570").replace("option '","\u9009\u9879 '").replace("argument missing","\u7F3A\u5C11\u53C2\u6570").replace("Did you mean","\u4F60\u662F\u60F3\u8981").replace(/Expected (\d+) arguments? but got (\d+)\./,"\u671F\u671B $1 \u4E2A\u53C2\u6570\uFF0C\u4F46\u5F97\u5230\u4E86 $2 \u4E2A\u53C2\u6570\u3002");return[2,p+(p.includes("\u4F60\u662F\u60F3\u8981")?"":`
|
|
2
|
+
(\u4F7F\u7528 -h \u83B7\u53D6\u5E2E\u52A9\u4FE1\u606F)`)]}else return this.logger.ERROR("\u547D\u4EE4\u5904\u7406\u51FA\u9519:",a),[2,a instanceof Error?a.message:"\u672A\u77E5\u9519\u8BEF"]}return[0,{prefix:s,commandName:r,params:{},args:[]}]}getCommandInfo(e,t,n="name"){let o=e[n]().replace("/","");return o===""||o==="program"?t:o}getCommandHelpInformation(e){let t=this.events.command.find(i=>i.commandName.toString()===e);if(!t||!t.commander)return;let n=this.getCommandInfo(t.commander,t.commandName.toString()),o=this.config.prefix[0];return t.commander.name(n.includes(o)?n:`${o}${n}`).helpOption("-h, --help","\u5C55\u793A\u5E2E\u52A9\u4FE1\u606F").helpInformation().replace("default:","\u9ED8\u8BA4\u503C:").replace("Arguments:","\u53C2\u6570:").replace("Options:","\u9009\u9879:").replace("Usage:","\u7528\u6CD5:")}async sendMsg(e,t,{reply:n=!0,at:o=!0}={}){try{if(e.message_type==="private")return await this.ws.send_private_msg({user_id:e.user_id,message:t});{let s=[];return n&&e.message_id&&s.push(f.reply(e.message_id)),o&&e.user_id&&s.push(f.at(e.user_id),f.text(`
|
|
3
|
+
`)),t=[...s,...t],await this.ws.send_group_msg({group_id:e.group_id,message:t})}}catch{return null}}async sendForwardMsg(e,t){try{return e.message_type==="private"?await this.ws.send_private_forward_msg({user_id:e.user_id,message:t}):await this.ws.send_group_forward_msg({group_id:e.group_id,message:t})}catch{return null}}async isFriend(e){return this.ws.get_friend_list().then(t=>t.find(n=>n.user_id===e.user_id))}async getUsername(e){return"group_id"in e?this.ws.get_group_member_info({group_id:e.group_id,user_id:e.user_id}).then(t=>t.nickname):this.ws.get_stranger_info({user_id:e.user_id}).then(t=>t.nickname)}};var k=class m extends ${static{g(this,"ATRI")}config;configDir;bot;import;loadedPlugins={};loadPluginHooks={};constructor(e,t){super({level:e.debug?_.DEBUG:e.logLevel}),this.config=e,this.bot=t,this.configDir=e.configDir??u.join(e.baseDir,"config"),this.import=I(e.baseDir)}static async init(e){e.debug&&(e.logLevel=_.DEBUG);let t=new A({title:"ATRI",level:e.debug?_.DEBUG:e.logLevel});e.disableClearTerminal||console.log("\x1Bc"),e.disableStartupMessage||(console.log(`%c __ .__
|
|
4
4
|
_____ _/ |_ _______ |__|
|
|
5
5
|
\\__ \\ \\ __\\ \\_ __ \\ | |
|
|
6
6
|
/ __ \\_ | | | | \\/ | |
|
|
7
7
|
(____ / |__| |__| |__|
|
|
8
|
-
\\/`,"font-family: Consolas;"),t.INFO("\u30A2\u30C8\u30EA\u306F\u3001\u9AD8\u6027\u80FD\u3067\u3059\u304B\u3089\uFF01")),"debug"in e.bot||(e.bot.debug=e.debug),"logLevel"in e.bot||(e.bot.logLevel=e.logLevel);let n=await
|
|
8
|
+
\\/`,"font-family: Consolas;"),t.INFO("\u30A2\u30C8\u30EA\u306F\u3001\u9AD8\u6027\u80FD\u3067\u3059\u304B\u3089\uFF01")),"debug"in e.bot||(e.bot.debug=e.debug),"logLevel"in e.bot||(e.bot.logLevel=e.logLevel);let n=await h.init(e.bot),o=new m(e,n);for(let s of e.plugins??[]){let[i]=await o.loadPlugin(s);i!==0&&(t.ERROR("\u63D2\u4EF6\u52A0\u8F7D\u5931\u8D25\uFF0C\u7A0B\u5E8F\u7EC8\u6B62"),H.exit(1))}return t.INFO("ATRI \u521D\u59CB\u5316\u5B8C\u6210"),o}async loadPlugin(e,t){if(t={initPlugin:!0,quiet:!1,...t??{}},t.quiet||this.logger.INFO(`\u52A0\u8F7D\u63D2\u4EF6: ${e}`),this.loadedPlugins[e])return t.quiet||this.logger.WARN(`\u63D2\u4EF6 ${e} \u5DF2\u52A0\u8F7D\uFF0C\u8DF3\u8FC7\u52A0\u8F7D`),[0,this.loadedPlugins[e]];let n=[e,u.join(e,"src/index.ts")];this.config.debug&&(n=n.reverse());let o;try{o=await this.import(n[0])}catch{try{o=await this.import(n[1])}catch(r){return t.quiet||this.logger.ERROR(`\u63D2\u4EF6 ${e} \u5BFC\u5165\u5931\u8D25:`,r),[1,r instanceof Error?r.message:String(r)]}}if(!o.Plugin)return t.quiet||this.logger.ERROR(`\u63D2\u4EF6 ${e} \u52A0\u8F7D\u5931\u8D25: \u672A\u627E\u5230 Plugin \u7C7B`),[1,"\u672A\u627E\u5230 Plugin \u7C7B"];let s;try{let r=this.import.resolve(u.join(e,"package.json"));s=JSON.parse(l.readFileSync(r,"utf-8"))}catch(r){t.quiet||(this.logger.WARN(`\u63D2\u4EF6 ${e} \u672A\u627E\u5230 package.json, \u5C06\u4F7F\u7528\u672A\u77E5\u4EE3\u66FF`),this.logger.DEBUG(r)),s={name:"\u672A\u77E5",version:"\u672A\u77E5"}}let i;try{i=new o.Plugin(this,s)}catch(r){return t.quiet||this.logger.ERROR(`\u63D2\u4EF6 ${e} \u5B9E\u4F8B\u5316\u5931\u8D25:`,r),[1,r instanceof Error?r.message:String(r)]}if(!t.initPlugin)return[0,i];try{for(let r in this.loadPluginHooks){let d=this.loadPluginHooks[r];if(!await d({plugin:i,packageName:e}))return t.quiet||this.logger.ERROR(`\u63D2\u4EF6 ${e} \u52A0\u8F7D\u5931\u8D25: \u52A0\u8F7D\u94A9\u5B50 ${r} \u8FD4\u56DE false`),[2,r]}return i.disableAutoLoadConfig||(i.config=await this.loadConfig(i.configName??e,i.defaultConfig??{})),await i.load(),this.loadedPlugins[e]=i,t.quiet||this.logger.INFO(`\u63D2\u4EF6 ${e} \u52A0\u8F7D\u6210\u529F`),[0,i]}catch(r){return t.quiet||this.logger.ERROR(`\u63D2\u4EF6 ${e} \u52A0\u8F7D\u5931\u8D25:`,r),[1,r instanceof Error?r.message:String(r)]}}async unloadPlugin(e){let t=this.loadedPlugins[e];if(!t)return this.logger.WARN(`\u63D2\u4EF6 ${e} \u672A\u52A0\u8F7D`),[1,"\u63D2\u4EF6\u672A\u52A0\u8F7D"];try{return t.unregHandlers.forEach(n=>n()),await t.unload(),delete this.loadedPlugins[e],this.logger.INFO(`\u63D2\u4EF6 ${e} \u5378\u8F7D\u6210\u529F`),[0]}catch(n){return this.logger.ERROR(`\u63D2\u4EF6 ${e} \u5378\u8F7D\u5931\u8D25:`,n),[1,n instanceof Error?n.message:String(n)]}}async loadConfig(e,t){e=e.replaceAll("/","__"),l.existsSync(this.configDir)||l.mkdirSync(this.configDir,{recursive:!0});let n=u.join(this.configDir,`${e}.json`);if(!l.existsSync(n))return l.writeFileSync(n,JSON.stringify(t,null,2)),t;try{let o=JSON.parse(l.readFileSync(n,"utf-8"));return{...t,...o}}catch(o){return this.logger.ERROR(`\u63D2\u4EF6 ${e} \u914D\u7F6E\u52A0\u8F7D\u5931\u8D25:`,o),{}}}async saveConfig(e,t){e=e.replaceAll("/","__"),l.existsSync(this.configDir)||l.mkdirSync(this.configDir,{recursive:!0});let n=u.join(this.configDir,`${e}.json`);l.writeFileSync(n,JSON.stringify(t,null,2))}addPluginLoadHook(e,t){this.loadPluginHooks[e]=t}removePluginLoadHook(e){delete this.loadPluginHooks[e]}};var P=class{static{g(this,"CommanderUtils")}static enum(e){return function(t){if(!e.includes(t))throw new Error(`\u53C2\u6570 "${t}" \u4E0D\u662F\u6709\u6548\u53C2\u6570, \u6709\u6548\u53C2\u6570:
|
|
9
9
|
${e.map(n=>` - ${n}`).join(`
|
|
10
|
-
`)}`);return t}}};import{Logger as B,LogLevel as M}from"@huan_kong/logger";var O=class{static{g(this,"BasePlugin")}packageJson;disableAutoLoadConfig;configName;defaultConfig;config;atri;bot;ws;unregHandlers=[];logger;constructor(e,t){this.atri=e,this.bot=e.bot,this.ws=e.bot.ws,this.config={},this.packageJson=t,this.logger=new B({title:this.packageJson.name,level:e.config.debug?M.DEBUG:e.config.logLevel})}saveConfig(e){this.atri.saveConfig(this.configName??this.packageJson.name,e??this.config)}regCommandEvent(e){let t=this.bot.regEvent({...e,type:"command",
|
|
10
|
+
`)}`);return t}}};import{Logger as B,LogLevel as M}from"@huan_kong/logger";var O=class{static{g(this,"BasePlugin")}packageJson;disableAutoLoadConfig;configName;defaultConfig;config;atri;bot;ws;unregHandlers=[];logger;constructor(e,t){this.atri=e,this.bot=e.bot,this.ws=e.bot.ws,this.config={},this.packageJson=t,this.logger=new B({title:this.packageJson.name,level:e.config.debug?M.DEBUG:e.config.logLevel})}saveConfig(e){this.atri.saveConfig(this.configName??this.packageJson.name,e??this.config)}regCommandEvent(e){let t=this.bot.regEvent({...e,type:"command",packageName:this.packageJson.name});return this.unregHandlers.push(t),t}regMessageEvent(e){let t=this.bot.regEvent({...e,type:"message",packageName:this.packageJson.name});return this.unregHandlers.push(t),t}regRequestEvent(e){let t=this.bot.regEvent({...e,type:"request",packageName:this.packageJson.name});return this.unregHandlers.push(t),t}regNoticeEvent(e){let t=this.bot.regEvent({...e,type:"notice",packageName:this.packageJson.name});return this.unregHandlers.push(t),t}};export{k as ATRI,O as BasePlugin,h as Bot,P as CommanderUtils,R as performanceCounter,c as sortObjectArray};
|
package/package.json
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@atri-bot/core",
|
|
3
|
-
"version": "1.1.
|
|
4
|
-
"description": "QQBOT TypeScript framework",
|
|
5
|
-
"author": "huankong233",
|
|
6
|
-
"license": "MIT",
|
|
7
|
-
"type": "module",
|
|
8
|
-
"main": "./dist/index.js",
|
|
9
|
-
"types": "./dist/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"./dist/**/*"
|
|
12
|
-
],
|
|
13
|
-
"repository": {
|
|
14
|
-
"type": "git",
|
|
15
|
-
"url": "git+https://github.com/HkTeamX/ATRI.git"
|
|
16
|
-
},
|
|
17
|
-
"scripts": {
|
|
18
|
-
"build": "tsup",
|
|
19
|
-
"clean": "rimraf dist",
|
|
20
|
-
"lint": "eslint",
|
|
21
|
-
"lint:fix": "eslint --fix",
|
|
22
|
-
"type-check": "tsc --noEmit -p tsconfig.json --composite false"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@huan_kong/logger": "^1.0.6",
|
|
26
|
-
"commander": "^14.0.0",
|
|
27
|
-
"compare-versions": "^6.1.1",
|
|
28
|
-
"node-napcat-ts": "^0.4.19",
|
|
29
|
-
"picocolors": "^1.1.1"
|
|
30
|
-
}
|
|
31
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@atri-bot/core",
|
|
3
|
+
"version": "1.1.14",
|
|
4
|
+
"description": "QQBOT TypeScript framework",
|
|
5
|
+
"author": "huankong233",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"./dist/**/*"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/HkTeamX/ATRI.git"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsup",
|
|
19
|
+
"clean": "rimraf dist",
|
|
20
|
+
"lint": "eslint",
|
|
21
|
+
"lint:fix": "eslint --fix",
|
|
22
|
+
"type-check": "tsc --noEmit -p tsconfig.json --composite false"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@huan_kong/logger": "^1.0.6",
|
|
26
|
+
"commander": "^14.0.0",
|
|
27
|
+
"compare-versions": "^6.1.1",
|
|
28
|
+
"node-napcat-ts": "^0.4.19",
|
|
29
|
+
"picocolors": "^1.1.1"
|
|
30
|
+
}
|
|
31
|
+
}
|