meocord 1.2.0 → 1.2.1
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/CHANGELOG.md +10 -0
- package/dist/bin/meocord.js +2 -2
- package/dist/core/meocord.app.d.ts +1 -0
- package/dist/core/meocord.app.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.2.1] - 2026-03-18
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Fix graceful shutdown requiring double Ctrl+C to fully exit by properly handling SIGINT across parent and child processes. ([293377b](https://github.com/l7aromeo/meocord/commit/293377b))
|
|
13
|
+
- Clear activity `setInterval` on shutdown to prevent it from keeping the process alive. ([293377b](https://github.com/l7aromeo/meocord/commit/293377b))
|
|
14
|
+
- Remove unnecessary `wait()` delays in shutdown path for faster exit. ([293377b](https://github.com/l7aromeo/meocord/commit/293377b))
|
|
15
|
+
- Add force-exit on second Ctrl+C at all process levels to prevent hanging when `bot.destroy()` stalls. ([293377b](https://github.com/l7aromeo/meocord/commit/293377b))
|
|
16
|
+
- Propagate child process exit code to parent instead of always exiting with 0. ([293377b](https://github.com/l7aromeo/meocord/commit/293377b))
|
|
17
|
+
|
|
8
18
|
## [1.2.0] - 2026-03-11
|
|
9
19
|
|
|
10
20
|
### Added
|
package/dist/bin/meocord.js
CHANGED
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
*/},{key:"build",value:(function(){function build(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(a){var b,c,d,e,f=this;return _regenerator().w(function(g){for(;1;)switch(g.p=g.n){case 0:return g.p=0,this.clearConsole(),this.logger.info("Building ".concat(a," version...")),g.n=1,import(this.webpackConfigPath);case 1:if(b=g.v["default"],c=webpack(_objectSpread(_objectSpread({},b),{},{mode:a})),c){g.n=2;break}throw this.logger.error("Failed to create webpack compiler instance."),new Error("Failed to create webpack compiler instance.");case 2:return d=null,g.n=3,new Promise(function(b,e){d=setInterval(function(){// Keeps event loop active
|
|
25
25
|
},100),c.run(function(g,h){return d&&(clearInterval(d),d=null),g?(f.logger.error("Build encountered an error: ".concat(g.message)),e("Build encountered an error: ".concat(g.message))):void(null!==h&&void 0!==h&&h.hasErrors()?f.logger.error("Build failed due to errors in the compilation process:",h.compilation.errors):f.logger.info("".concat(capitalize(a)," build completed successfully.")),c.close(function(a){return a?(f.logger.error("Error occurred while closing the compiler: ".concat(a.message)),e("Error occurred while closing the compiler: ".concat(a.message))):void b()}))})});case 3:g.n=6;break;case 4:return g.p=4,e=g.v,this.logger.error("Build process failed: ".concat(e.message)),g.n=5,wait(100);case 5:process.exit(1);case 6:return g.a(2)}},_callee6,this,[[0,4]])}));return build}()/**
|
|
26
26
|
* Starts the MeoCord application in development mode with live updates.
|
|
27
|
-
*/)},{key:"startDev",value:(function(){function startDev(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function
|
|
27
|
+
*/)},{key:"startDev",value:(function(){function startDev(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(){var a,b,c,d,e,f,g,h,i,j=this;return _regenerator().w(function(k){for(;1;)switch(k.p=k.n){case 0:return k.p=0,this.clearConsole(),this.logger.log("Starting watch mode..."),k.n=1,import(this.webpackConfigPath);case 1:if(a=k.v["default"],b=webpack(_objectSpread(_objectSpread({},a),{},{mode:"development"})),b){k.n=3;break}return this.logger.error("Failed to create webpack compiler instance."),k.n=2,wait(100);case 2:process.exit(1);case 3:c=null,d=!1,e=function watch(){return b.watch({},function(a,b){return a?void j.logger.error("Webpack Error: ".concat(a.message)):void(null!==b&&void 0!==b&&b.hasErrors()?j.logger.error("Build failed due to errors in the compilation process:",b.compilation.errors):(c&&(c.kill(),c=null),c=spawn("npx -y nodemon",["-q",j.mainJSPath],{shell:!0,cwd:j.projectRoot,stdio:"inherit"}),d=!0))})},e(),g=fs.watch(path.resolve(process.cwd(),"meocord.config.ts"),function(){clearTimeout(f),f=setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(){return _regenerator().w(function(a){for(;1;)switch(a.n){case 0:if(!(d&&c)){a.n=3;break}return d=!1,j.logger.log("MeoCord config change detected, recompiling config..."),c&&!c.killed&&(c.kill(),c=null),a.n=1,new Promise(function(a){return b.close(a)});case 1:return a.n=2,compileMeoCordConfig();case 2:e();case 3:return a.a(2)}},_callee7)})),300)}),h=!1,process.on("SIGINT",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(){return _regenerator().w(function(a){for(;1;)switch(a.n){case 0:if(h&&(c&&!c.killed&&c.kill("SIGKILL"),process.exit(1)),h=!0,g.close(),!c||c.killed){a.n=1;break}c.on("exit",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(){return _regenerator().w(function(a){for(;1;)switch(a.n){case 0:return a.n=1,new Promise(function(a){return b.close(a)});case 1:process.exit(0);case 2:return a.a(2)}},_callee8)}))),a.n=3;break;case 1:return a.n=2,new Promise(function(a){return b.close(a)});case 2:process.exit(0);case 3:return a.a(2)}},_callee9)}))),k.n=5;break;case 4:k.p=4,i=k.v,this.logger.error("Failed to start: ".concat(i.message));case 5:return k.a(2)}},_callee0,this,[[0,4]])}));return startDev}()/**
|
|
28
28
|
* Starts the MeoCord application in production mode.
|
|
29
|
-
*/)},{key:"startProd",value:(function(){function startProd(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(){var a,b;return _regenerator().w(function(
|
|
29
|
+
*/)},{key:"startProd",value:(function(){function startProd(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(){var a,b,c;return _regenerator().w(function(d){for(;1;)switch(d.p=d.n){case 0:if(d.p=0,fs.existsSync(this.mainJSPath)){d.n=2;break}return this.logger.error("Main entry file (main.js) not found! You might need to build before running in production mode."),d.n=1,wait(100);case 1:process.exit(1);case 2:this.clearConsole(),this.logger.log("Starting..."),a=spawn("node ".concat(this.mainJSPath),{shell:!0,cwd:this.projectRoot,stdio:"inherit"}).on("spawn",this.clearConsole),a.on("exit",function(a){process.exit(null!==a&&void 0!==a?a:0)}),b=!1,process.on("SIGINT",function(){b&&(!a.killed&&a.kill("SIGKILL"),process.exit(1)),b=!0}),d.n=5;break;case 3:return d.p=3,c=d.v,this.logger.error("Failed to start:",c instanceof Error?c.message:c+""),d.n=4,wait(100);case 4:process.exit(1);case 5:return d.a(2)}},_callee1,this,[[0,3]])}));return startProd}()/**
|
|
30
30
|
* Clears the console on all platforms.
|
|
31
31
|
*/)},{key:"clearConsole",value:function clearConsole(){process.stdout.write("\x1B[3J\x1B[2J\x1B[H")}}])}(),cli=new MeoCordCLI;/**
|
|
32
32
|
* A Command Line Interface (CLI) for managing the MeoCord application.
|
|
@@ -24,6 +24,7 @@ export declare class MeoCordApp {
|
|
|
24
24
|
private readonly logger;
|
|
25
25
|
private readonly bot;
|
|
26
26
|
private isShuttingDown;
|
|
27
|
+
private activityInterval;
|
|
27
28
|
private controllerInstancesCache;
|
|
28
29
|
constructor(controllers: any[], discordClient: Client, discordToken: string, activities?: ActivityOptions[] | undefined);
|
|
29
30
|
start(): Promise<void>;
|
package/dist/core/meocord.app.js
CHANGED
|
@@ -14,4 +14,4 @@ function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof
|
|
|
14
14
|
*
|
|
15
15
|
* You should have received a copy of the GNU General Public License
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
*/import{MessageFlagsBitField,SlashCommandBuilder}from"discord.js";import{Logger}from"../common/index.js";import{getCommandMap,getMessageHandlers,getReactionHandlers,mainContainer}from"../decorator/index.js";import{sample}from"lodash-es";import{EmbedUtil}from"../util/index.js";import wait from"../util/wait.util.js";import{CommandType}from"../enum/index.js";import{ReactionHandlerAction}from"../enum/controller.enum.js";export var MeoCordApp=/*#__PURE__*/function(){function MeoCordApp(a,b,c,d){var e=this;_classCallCheck(this,MeoCordApp),_defineProperty(this,"logger",new Logger(MeoCordApp.name)),_defineProperty(this,"isShuttingDown",!1),_defineProperty(this,"controllerInstancesCache",new Map),this.controllers=a,this.discordClient=b,this.discordToken=c,this.activities=d,this.bot=this.discordClient,process.on("SIGINT",function(){return e.gracefulShutdown()}),process.on("SIGTERM",function(){return e.gracefulShutdown()})}return _createClass(MeoCordApp,[{key:"start",value:function(){function start(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var a,b=this;return _regenerator().w(function(c){for(;1;)switch(c.p=c.n){case 0:return c.p=0,this.logger.log("Starting bot..."),this.bot.on("clientReady",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(){return _regenerator().w(function(a){for(;1;)switch(a.n){case 0:return setInterval(function(){var a;null===(a=b.bot.user)||void 0===a||a.setActivity(sample(b.activities))},1e4),a.n=1,b.registerCommands();case 1:return a.a(2)}},_callee)}))),this.bot.on("interactionCreate",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(a){return _regenerator().w(function(c){for(;1;)switch(c.n){case 0:return c.n=1,b.handleInteraction(a);case 1:return c.a(2)}},_callee2)}));return function(b){return a.apply(this,arguments)}}()),this.bot.on("messageCreate",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(a){return _regenerator().w(function(c){for(;1;)switch(c.n){case 0:return c.n=1,b.handleMessage(a);case 1:return c.a(2)}},_callee3)}));return function(b){return a.apply(this,arguments)}}()),this.bot.on("messageReactionAdd",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(a,c){return _regenerator().w(function(d){for(;1;)switch(d.n){case 0:return d.n=1,b.handleReaction(a,{user:c,action:ReactionHandlerAction.ADD});case 1:return d.a(2)}},_callee4)}));return function(b,c){return a.apply(this,arguments)}}()),this.bot.on("messageReactionRemove",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(a,c){return _regenerator().w(function(d){for(;1;)switch(d.n){case 0:return d.n=1,b.handleReaction(a,{user:c,action:ReactionHandlerAction.REMOVE});case 1:return d.a(2)}},_callee5)}));return function(b,c){return a.apply(this,arguments)}}()),c.n=1,this.bot.login(this.discordToken);case 1:this.logger.log("Bot is online!"),c.n=3;break;case 2:c.p=2,a=c.v,this.logger.error("Error during bot startup:",a);case 3:return c.a(2)}},_callee6,this,[[0,2]])}));return start}()},{key:"registerCommands",value:function(){function registerCommands(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;return _regenerator().w(function(q){for(;1;)switch(q.p=q.n){case 0:a=[],b=_createForOfIteratorHelper(this.controllers),q.p=1,b.s();case 2:if((c=b.n()).done){q.n=6;break}d=c.value,e=getCommandMap(d),m=_regeneratorKeys(e);case 3:if((n=m()).done){q.n=5;break}if(f=n.value,g=e[f],Array.isArray(g)){q.n=4;break}return q.a(3,3);case 4:h=_createForOfIteratorHelper(g);try{for(h.s();!(i=h.n()).done;)j=i.value,k=j.builder,l=j.type,l in CommandType&&k&&a.push(k)}catch(a){h.e(a)}finally{h.f()}q.n=3;break;case 5:q.n=2;break;case 6:q.n=8;break;case 7:q.p=7,o=q.v,b.e(o);case 8:return q.p=8,b.f(),q.f(8);case 9:if(q.p=9,!this.bot.application){q.n=11;break}return q.n=10,this.bot.application.commands.set(a);case 10:this.logger.log("Registered ".concat(a.length," bot commands:"),a.map(function(a){var b="function"==typeof a.toJSON?a.toJSON():a,c=1===(null===b||void 0===b?void 0:b.type)?"SlashCommand":2===(null===b||void 0===b?void 0:b.type)?"UserContextMenu":3===(null===b||void 0===b?void 0:b.type)?"MessageContextMenu":a instanceof SlashCommandBuilder?"SlashCommand":"Command",d=Array.isArray(null===b||void 0===b?void 0:b.options)&&b.options.length?b.options.map(function(a){return{name:a.name,options:a.options.map(function(a){return a.name})}}):void 0,e=(null===b||void 0===b?void 0:b.name)||a.name;return d?{type:c,name:e,subCommands:d}:{type:c,name:e}}));case 11:q.n=13;break;case 12:q.p=12,p=q.v,this.logger.error("Error during command registration:",p);case 13:return q.a(2)}},_callee7,this,[[9,12],[1,7,8,9]])}));return registerCommands}()},{key:"handleInteraction",value:function(){function handleInteraction(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(a){var b,c,d,e,f,g,h=this;return _regenerator().w(function(i){for(;1;)switch(i.p=i.n){case 0:b=_createForOfIteratorHelper(this.controllers),i.p=1,d=/*#__PURE__*/_regenerator().m(function _loop(){var b,d,e,f,g,i,j,k,l,m,n,o;return _regenerator().w(function(p){for(;1;)switch(p.p=p.n){case 0:if(b=c.value,d=h.controllerInstancesCache.get(b),d||(d=mainContainer.get(b.constructor),h.controllerInstancesCache.set(b,d)),e=getCommandMap(d),e){p.n=1;break}return p.a(2,0);case 1:if(f=void 0,g=void 0,a.isChatInputCommand()||a.isContextMenuCommand()?(g=a.commandName,f=e[g]):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(g=a.customId,i=Object.entries(e).find(function(b){var c=_slicedToArray(b,2),d=c[0],e=c[1];return!!Array.isArray(e)&&e.some(function(b){if(!b.regex||!g)return!1;var c=b.regex.exec(g);return null!==c&&void 0!==c&&c.groups?(a.dynamicParams=c.groups,!0):g===d})}),i&&(f=i[1])),!(f&&0<f.length)){p.n=8;break}if(j=f[0],k=j.methodName,l=j.type,p.p=2,!(l===CommandType.SLASH&&a.isChatInputCommand()||l===CommandType.BUTTON&&a.isButton()||l===CommandType.SELECT_MENU&&a.isStringSelectMenu()||l===CommandType.CONTEXT_MENU&&a.isUserContextMenuCommand()||l===CommandType.CONTEXT_MENU&&a.isMessageContextMenuCommand()||l===CommandType.MODAL_SUBMIT&&a.isModalSubmit())){p.n=4;break}return h.logger.log("[INTERACTION]","[".concat(CommandType[l],"]"),"[".concat(k,"]")),m={},a.isChatInputCommand()&&a.options?m=a.options.data.reduce(function(a,b){return a[b.name]=b.value,a},{}):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(m=a.dynamicParams||{}),p.n=3,d[k](a,m);case 3:return p.a(2,{v:void 0});case 4:h.logger.debug(l,k,CommandType.BUTTON,a.isButton()),h.logger.warn("Interaction type mismatch for command \"".concat(g,"\". Interaction type: ").concat(a.type,"."));case 5:p.n=7;break;case 6:if(p.p=6,o=p.v,h.logger.error("Error executing command \"".concat(g,"\":"),o),!a.isRepliable()){p.n=7;break}return n=EmbedUtil.createErrorEmbed("An error occurred while executing the command."),p.n=7,a.reply({embeds:[n],flags:MessageFlagsBitField.Flags.Ephemeral});case 7:return p.a(2,{v:void 0});case 8:return p.a(2)}},_loop,null,[[2,6]])}),b.s();case 2:if((c=b.n()).done){i.n=6;break}return i.d(_regeneratorValues(d()),3);case 3:if(e=i.v,0!==e){i.n=4;break}return i.a(3,5);case 4:if(!e){i.n=5;break}return i.a(2,e.v);case 5:i.n=2;break;case 6:i.n=8;break;case 7:i.p=7,g=i.v,b.e(g);case 8:return i.p=8,b.f(),i.f(8);case 9:if(!a.isRepliable()){i.n=10;break}return f=EmbedUtil.createErrorEmbed("Command not found!"),i.n=10,a.reply({embeds:[f],flags:MessageFlagsBitField.Flags.Ephemeral});case 10:return i.a(2)}},_callee8,this,[[1,7,8,9]])}));return handleInteraction}()},{key:"handleMessage",value:function(){function handleMessage(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;return _regenerator().w(function(s){for(;1;)switch(s.p=s.n){case 0:if(!a.author.bot&&null!==(b=a.content)&&void 0!==b&&b.trim()){s.n=1;break}return s.a(2);case 1:c=a.content.trim(),d=this.controllers.filter(function(a){var b=getMessageHandlers(a);return b.some(function(a){return!a.keyword||a.keyword===c})}),e=_createForOfIteratorHelper(d),s.p=2,e.s();case 3:if((f=e.n()).done){s.n=14;break}g=f.value,h=this.controllerInstancesCache.get(g.constructor),h||(i=Reflect.getMetadata("inversify:container",g.constructor),h=i.get(g.constructor,{autobind:!0}),this.controllerInstancesCache.set(g.constructor,h)),j=getMessageHandlers(g),j=j.sort(function(c,a){return c.keyword&&!a.keyword?-1:!c.keyword&&a.keyword?1:0}),k=_createForOfIteratorHelper(j),s.p=4,k.s();case 5:if((l=k.n()).done){s.n=10;break}if(m=l.value,n=m.keyword,o=m.method,n&&n!==c){s.n=9;break}return s.p=6,s.n=7,h[o](a);case 7:s.n=9;break;case 8:s.p=8,p=s.v,this.logger.error("Error handling message \"".concat(c,"\" for method \"").concat(o,"\":"),p);case 9:s.n=5;break;case 10:s.n=12;break;case 11:s.p=11,q=s.v,k.e(q);case 12:return s.p=12,k.f(),s.f(12);case 13:s.n=3;break;case 14:s.n=16;break;case 15:s.p=15,r=s.v,e.e(r);case 16:return s.p=16,e.f(),s.f(16);case 17:return s.a(2)}},_callee9,this,[[6,8],[4,11,12,13],[2,15,16,17]])}));return handleMessage}()},{key:"handleReaction",value:function(){function handleReaction(b,c){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return _regenerator().w(function(t){for(;1;)switch(t.p=t.n){case 0:return c=b.user,d=b.action,t.n=1,a.message.fetch();case 1:e=this.controllers.filter(function(b){var c=getReactionHandlers(b);return c.some(function(b){return!b.emoji||b.emoji===a.emoji.name})}),f=_createForOfIteratorHelper(e),t.p=2,f.s();case 3:if((g=f.n()).done){t.n=14;break}h=g.value,i=this.controllerInstancesCache.get(h.constructor),i||(j=Reflect.getMetadata("inversify:container",h.constructor),i=j.get(h.constructor,{autobind:!0}),this.controllerInstancesCache.set(h.constructor,i)),k=getReactionHandlers(h),k=k.sort(function(c,a){return c.emoji&&!a.emoji?-1:!c.emoji&&a.emoji?1:0}),l=_createForOfIteratorHelper(k),t.p=4,l.s();case 5:if((m=l.n()).done){t.n=10;break}if(n=m.value,o=n.emoji,p=n.method,o&&o!==a.emoji.name){t.n=9;break}return t.p=6,t.n=7,i[p](a,{user:c,action:d});case 7:t.n=9;break;case 8:t.p=8,q=t.v,this.logger.error("Error handling reaction \"".concat(a.emoji.name,"\" for method \"").concat(p,"\":"),q);case 9:t.n=5;break;case 10:t.n=12;break;case 11:t.p=11,r=t.v,l.e(r);case 12:return t.p=12,l.f(),t.f(12);case 13:t.n=3;break;case 14:t.n=16;break;case 15:t.p=15,s=t.v,f.e(s);case 16:return t.p=16,f.f(),t.f(16);case 17:return t.a(2)}},_callee0,this,[[6,8],[4,11,12,13],[2,15,16,17]])}));return handleReaction}()},{key:"gracefulShutdown",value:function(){function gracefulShutdown(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(){var a;return _regenerator().w(function(b){for(;1;)switch(b.p=b.n){case 0:if(!this.bot||this.isShuttingDown){b.n=6;break}return b.p=1,this.isShuttingDown=!0,this.logger.log("Shutting down bot..."),this.bot.removeAllListeners(),b.n=2,this.bot.destroy();case 2:return this.logger.log("Bot has shut down"),b.n=3,wait(100);case 3:process.exit(0),b.n=6;break;case 4:return b.p=4,a=b.v,this.logger.error("Error during shutdown:",a),b.n=5,wait(100);case 5:process.exit(0);case 6:return b.a(2)}},_callee1,this,[[1,4]])}));return gracefulShutdown}()}])}();
|
|
17
|
+
*/import{MessageFlagsBitField,SlashCommandBuilder}from"discord.js";import{Logger}from"../common/index.js";import{getCommandMap,getMessageHandlers,getReactionHandlers,mainContainer}from"../decorator/index.js";import{sample}from"lodash-es";import{EmbedUtil}from"../util/index.js";import{CommandType}from"../enum/index.js";import{ReactionHandlerAction}from"../enum/controller.enum.js";export var MeoCordApp=/*#__PURE__*/function(){function MeoCordApp(a,b,c,d){var e=this;_classCallCheck(this,MeoCordApp),_defineProperty(this,"logger",new Logger(MeoCordApp.name)),_defineProperty(this,"isShuttingDown",!1),_defineProperty(this,"activityInterval",null),_defineProperty(this,"controllerInstancesCache",new Map),this.controllers=a,this.discordClient=b,this.discordToken=c,this.activities=d,this.bot=this.discordClient,process.on("SIGINT",function(){return e.gracefulShutdown()}),process.on("SIGTERM",function(){return e.gracefulShutdown()})}return _createClass(MeoCordApp,[{key:"start",value:function(){function start(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(){var a,b=this;return _regenerator().w(function(c){for(;1;)switch(c.p=c.n){case 0:return c.p=0,this.logger.log("Starting bot..."),this.bot.on("clientReady",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(){return _regenerator().w(function(a){for(;1;)switch(a.n){case 0:return b.activityInterval=setInterval(function(){var a;null===(a=b.bot.user)||void 0===a||a.setActivity(sample(b.activities))},1e4),a.n=1,b.registerCommands();case 1:return a.a(2)}},_callee)}))),this.bot.on("interactionCreate",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(a){return _regenerator().w(function(c){for(;1;)switch(c.n){case 0:return c.n=1,b.handleInteraction(a);case 1:return c.a(2)}},_callee2)}));return function(b){return a.apply(this,arguments)}}()),this.bot.on("messageCreate",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(a){return _regenerator().w(function(c){for(;1;)switch(c.n){case 0:return c.n=1,b.handleMessage(a);case 1:return c.a(2)}},_callee3)}));return function(b){return a.apply(this,arguments)}}()),this.bot.on("messageReactionAdd",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(a,c){return _regenerator().w(function(d){for(;1;)switch(d.n){case 0:return d.n=1,b.handleReaction(a,{user:c,action:ReactionHandlerAction.ADD});case 1:return d.a(2)}},_callee4)}));return function(b,c){return a.apply(this,arguments)}}()),this.bot.on("messageReactionRemove",/*#__PURE__*/function(){var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(a,c){return _regenerator().w(function(d){for(;1;)switch(d.n){case 0:return d.n=1,b.handleReaction(a,{user:c,action:ReactionHandlerAction.REMOVE});case 1:return d.a(2)}},_callee5)}));return function(b,c){return a.apply(this,arguments)}}()),c.n=1,this.bot.login(this.discordToken);case 1:this.logger.log("Bot is online!"),c.n=3;break;case 2:c.p=2,a=c.v,this.logger.error("Error during bot startup:",a);case 3:return c.a(2)}},_callee6,this,[[0,2]])}));return start}()},{key:"registerCommands",value:function(){function registerCommands(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(){var a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;return _regenerator().w(function(q){for(;1;)switch(q.p=q.n){case 0:a=[],b=_createForOfIteratorHelper(this.controllers),q.p=1,b.s();case 2:if((c=b.n()).done){q.n=6;break}d=c.value,e=getCommandMap(d),m=_regeneratorKeys(e);case 3:if((n=m()).done){q.n=5;break}if(f=n.value,g=e[f],Array.isArray(g)){q.n=4;break}return q.a(3,3);case 4:h=_createForOfIteratorHelper(g);try{for(h.s();!(i=h.n()).done;)j=i.value,k=j.builder,l=j.type,l in CommandType&&k&&a.push(k)}catch(a){h.e(a)}finally{h.f()}q.n=3;break;case 5:q.n=2;break;case 6:q.n=8;break;case 7:q.p=7,o=q.v,b.e(o);case 8:return q.p=8,b.f(),q.f(8);case 9:if(q.p=9,!this.bot.application){q.n=11;break}return q.n=10,this.bot.application.commands.set(a);case 10:this.logger.log("Registered ".concat(a.length," bot commands:"),a.map(function(a){var b="function"==typeof a.toJSON?a.toJSON():a,c=1===(null===b||void 0===b?void 0:b.type)?"SlashCommand":2===(null===b||void 0===b?void 0:b.type)?"UserContextMenu":3===(null===b||void 0===b?void 0:b.type)?"MessageContextMenu":a instanceof SlashCommandBuilder?"SlashCommand":"Command",d=Array.isArray(null===b||void 0===b?void 0:b.options)&&b.options.length?b.options.map(function(a){return{name:a.name,options:a.options.map(function(a){return a.name})}}):void 0,e=(null===b||void 0===b?void 0:b.name)||a.name;return d?{type:c,name:e,subCommands:d}:{type:c,name:e}}));case 11:q.n=13;break;case 12:q.p=12,p=q.v,this.logger.error("Error during command registration:",p);case 13:return q.a(2)}},_callee7,this,[[9,12],[1,7,8,9]])}));return registerCommands}()},{key:"handleInteraction",value:function(){function handleInteraction(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(a){var b,c,d,e,f,g,h=this;return _regenerator().w(function(i){for(;1;)switch(i.p=i.n){case 0:b=_createForOfIteratorHelper(this.controllers),i.p=1,d=/*#__PURE__*/_regenerator().m(function _loop(){var b,d,e,f,g,i,j,k,l,m,n,o;return _regenerator().w(function(p){for(;1;)switch(p.p=p.n){case 0:if(b=c.value,d=h.controllerInstancesCache.get(b),d||(d=mainContainer.get(b.constructor),h.controllerInstancesCache.set(b,d)),e=getCommandMap(d),e){p.n=1;break}return p.a(2,0);case 1:if(f=void 0,g=void 0,a.isChatInputCommand()||a.isContextMenuCommand()?(g=a.commandName,f=e[g]):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(g=a.customId,i=Object.entries(e).find(function(b){var c=_slicedToArray(b,2),d=c[0],e=c[1];return!!Array.isArray(e)&&e.some(function(b){if(!b.regex||!g)return!1;var c=b.regex.exec(g);return null!==c&&void 0!==c&&c.groups?(a.dynamicParams=c.groups,!0):g===d})}),i&&(f=i[1])),!(f&&0<f.length)){p.n=8;break}if(j=f[0],k=j.methodName,l=j.type,p.p=2,!(l===CommandType.SLASH&&a.isChatInputCommand()||l===CommandType.BUTTON&&a.isButton()||l===CommandType.SELECT_MENU&&a.isStringSelectMenu()||l===CommandType.CONTEXT_MENU&&a.isUserContextMenuCommand()||l===CommandType.CONTEXT_MENU&&a.isMessageContextMenuCommand()||l===CommandType.MODAL_SUBMIT&&a.isModalSubmit())){p.n=4;break}return h.logger.log("[INTERACTION]","[".concat(CommandType[l],"]"),"[".concat(k,"]")),m={},a.isChatInputCommand()&&a.options?m=a.options.data.reduce(function(a,b){return a[b.name]=b.value,a},{}):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(m=a.dynamicParams||{}),p.n=3,d[k](a,m);case 3:return p.a(2,{v:void 0});case 4:h.logger.debug(l,k,CommandType.BUTTON,a.isButton()),h.logger.warn("Interaction type mismatch for command \"".concat(g,"\". Interaction type: ").concat(a.type,"."));case 5:p.n=7;break;case 6:if(p.p=6,o=p.v,h.logger.error("Error executing command \"".concat(g,"\":"),o),!a.isRepliable()){p.n=7;break}return n=EmbedUtil.createErrorEmbed("An error occurred while executing the command."),p.n=7,a.reply({embeds:[n],flags:MessageFlagsBitField.Flags.Ephemeral});case 7:return p.a(2,{v:void 0});case 8:return p.a(2)}},_loop,null,[[2,6]])}),b.s();case 2:if((c=b.n()).done){i.n=6;break}return i.d(_regeneratorValues(d()),3);case 3:if(e=i.v,0!==e){i.n=4;break}return i.a(3,5);case 4:if(!e){i.n=5;break}return i.a(2,e.v);case 5:i.n=2;break;case 6:i.n=8;break;case 7:i.p=7,g=i.v,b.e(g);case 8:return i.p=8,b.f(),i.f(8);case 9:if(!a.isRepliable()){i.n=10;break}return f=EmbedUtil.createErrorEmbed("Command not found!"),i.n=10,a.reply({embeds:[f],flags:MessageFlagsBitField.Flags.Ephemeral});case 10:return i.a(2)}},_callee8,this,[[1,7,8,9]])}));return handleInteraction}()},{key:"handleMessage",value:function(){function handleMessage(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r;return _regenerator().w(function(s){for(;1;)switch(s.p=s.n){case 0:if(!a.author.bot&&null!==(b=a.content)&&void 0!==b&&b.trim()){s.n=1;break}return s.a(2);case 1:c=a.content.trim(),d=this.controllers.filter(function(a){var b=getMessageHandlers(a);return b.some(function(a){return!a.keyword||a.keyword===c})}),e=_createForOfIteratorHelper(d),s.p=2,e.s();case 3:if((f=e.n()).done){s.n=14;break}g=f.value,h=this.controllerInstancesCache.get(g.constructor),h||(i=Reflect.getMetadata("inversify:container",g.constructor),h=i.get(g.constructor,{autobind:!0}),this.controllerInstancesCache.set(g.constructor,h)),j=getMessageHandlers(g),j=j.sort(function(c,a){return c.keyword&&!a.keyword?-1:!c.keyword&&a.keyword?1:0}),k=_createForOfIteratorHelper(j),s.p=4,k.s();case 5:if((l=k.n()).done){s.n=10;break}if(m=l.value,n=m.keyword,o=m.method,n&&n!==c){s.n=9;break}return s.p=6,s.n=7,h[o](a);case 7:s.n=9;break;case 8:s.p=8,p=s.v,this.logger.error("Error handling message \"".concat(c,"\" for method \"").concat(o,"\":"),p);case 9:s.n=5;break;case 10:s.n=12;break;case 11:s.p=11,q=s.v,k.e(q);case 12:return s.p=12,k.f(),s.f(12);case 13:s.n=3;break;case 14:s.n=16;break;case 15:s.p=15,r=s.v,e.e(r);case 16:return s.p=16,e.f(),s.f(16);case 17:return s.a(2)}},_callee9,this,[[6,8],[4,11,12,13],[2,15,16,17]])}));return handleMessage}()},{key:"handleReaction",value:function(){function handleReaction(b,c){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s;return _regenerator().w(function(t){for(;1;)switch(t.p=t.n){case 0:return c=b.user,d=b.action,t.n=1,a.message.fetch();case 1:e=this.controllers.filter(function(b){var c=getReactionHandlers(b);return c.some(function(b){return!b.emoji||b.emoji===a.emoji.name})}),f=_createForOfIteratorHelper(e),t.p=2,f.s();case 3:if((g=f.n()).done){t.n=14;break}h=g.value,i=this.controllerInstancesCache.get(h.constructor),i||(j=Reflect.getMetadata("inversify:container",h.constructor),i=j.get(h.constructor,{autobind:!0}),this.controllerInstancesCache.set(h.constructor,i)),k=getReactionHandlers(h),k=k.sort(function(c,a){return c.emoji&&!a.emoji?-1:!c.emoji&&a.emoji?1:0}),l=_createForOfIteratorHelper(k),t.p=4,l.s();case 5:if((m=l.n()).done){t.n=10;break}if(n=m.value,o=n.emoji,p=n.method,o&&o!==a.emoji.name){t.n=9;break}return t.p=6,t.n=7,i[p](a,{user:c,action:d});case 7:t.n=9;break;case 8:t.p=8,q=t.v,this.logger.error("Error handling reaction \"".concat(a.emoji.name,"\" for method \"").concat(p,"\":"),q);case 9:t.n=5;break;case 10:t.n=12;break;case 11:t.p=11,r=t.v,l.e(r);case 12:return t.p=12,l.f(),t.f(12);case 13:t.n=3;break;case 14:t.n=16;break;case 15:t.p=15,s=t.v,f.e(s);case 16:return t.p=16,f.f(),t.f(16);case 17:return t.a(2)}},_callee0,this,[[6,8],[4,11,12,13],[2,15,16,17]])}));return handleReaction}()},{key:"gracefulShutdown",value:function(){function gracefulShutdown(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(){var a;return _regenerator().w(function(b){for(;1;)switch(b.p=b.n){case 0:if(this.isShuttingDown&&process.exit(1),!this.bot){b.n=4;break}return b.p=1,this.isShuttingDown=!0,this.logger.log("Shutting down bot..."),this.activityInterval&&clearInterval(this.activityInterval),this.bot.removeAllListeners(),b.n=2,this.bot.destroy();case 2:this.logger.log("Bot has shut down"),process.exit(0),b.n=4;break;case 3:b.p=3,a=b.v,this.logger.error("Error during shutdown:",a),process.exit(1);case 4:return b.a(2)}},_callee1,this,[[1,3]])}));return gracefulShutdown}()}])}();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "meocord",
|
|
3
3
|
"description": "MeoCord is a lightweight and modular framework for building scalable Discord bots using TypeScript and Discord.js. It simplifies bot development with an extensible architecture, TypeScript-first approach, and powerful CLI tools.",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"packageManager": "yarn@4.12.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|