meocord 1.0.3 → 1.0.5
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.
|
@@ -16,11 +16,9 @@
|
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
import 'reflect-metadata';
|
|
19
|
-
import { type
|
|
19
|
+
import { type ServiceIdentifier } from 'inversify';
|
|
20
20
|
import { MeoCordApp } from '../core/meocord.app.js';
|
|
21
|
-
type ServiceIdentifier = interfaces.ServiceIdentifier;
|
|
22
21
|
export declare class MeoCordFactory {
|
|
23
22
|
private static logger;
|
|
24
23
|
static create(target: ServiceIdentifier): MeoCordApp;
|
|
25
24
|
}
|
|
26
|
-
export {};
|
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,size}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__*/_regeneratorRuntime().mark(function _callee6(){var a=this;return _regeneratorRuntime().wrap(function _callee6$(b){for(;;)switch(b.prev=b.next){case 0:return b.prev=0,this.logger.log("Starting bot..."),this.bot.on("ready",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){return _regeneratorRuntime().wrap(function _callee$(b){for(;1;)switch(b.prev=b.next){case 0:return setInterval(function(){var b;null===(b=a.bot.user)||void 0===b||b.setActivity(sample(a.activities))},1e4),b.next=3,a.registerCommands();case 3:case"end":return b.stop()}},_callee)}))),this.bot.on("interactionCreate",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(b){return _regeneratorRuntime().wrap(function _callee2$(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,a.handleInteraction(b);case 2:case"end":return c.stop()}},_callee2)}));return function(a){return b.apply(this,arguments)}}()),this.bot.on("messageCreate",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(b){return _regeneratorRuntime().wrap(function _callee3$(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,a.handleMessage(b);case 2:case"end":return c.stop()}},_callee3)}));return function(a){return b.apply(this,arguments)}}()),this.bot.on("messageReactionAdd",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(b,c){return _regeneratorRuntime().wrap(function _callee4$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,a.handleReaction(b,{user:c,action:ReactionHandlerAction.ADD});case 2:case"end":return d.stop()}},_callee4)}));return function(a,c){return b.apply(this,arguments)}}()),this.bot.on("messageReactionRemove",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(b,c){return _regeneratorRuntime().wrap(function _callee5$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,a.handleReaction(b,{user:c,action:ReactionHandlerAction.REMOVE});case 2:case"end":return d.stop()}},_callee5)}));return function(a,c){return b.apply(this,arguments)}}()),b.next=9,this.bot.login(this.discordToken);case 9:this.logger.log("Bot is online!"),b.next=15;break;case 12:b.prev=12,b.t0=b["catch"](0),this.logger.error("Error during bot startup:",b.t0);case 15:case"end":return b.stop()}},_callee6,this,[[0,12]])}));return start}()},{key:"registerCommands",value:function(){function registerCommands(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(){var a,b,c,d,e,f,g,h,i;return _regeneratorRuntime().wrap(function _callee7$(j){for(;1;)switch(j.prev=j.next){case 0:a=[],b=_createForOfIteratorHelper(this.controllers);try{for(b.s();!(c=b.n()).done;)for(f in d=c.value,e=getCommandMap(d),e)g=e[f],h=g.builder,i=g.type,i in CommandType&&h&&a.push(h)}catch(a){b.e(a)}finally{b.f()}if(j.prev=3,!this.bot.application){j.next=8;break}return j.next=7,this.bot.application.commands.set(a);case 7:this.logger.log("Registered ".concat(size(a)," bot commands:"),a.map(function(a){if(a instanceof SlashCommandBuilder&&a.options.length){var b;return{name:a.name,subCommands:null===(b=a.toJSON().options)||void 0===b?void 0:b.map(function(a){return a.name})}}return{name:a.name}}));case 8:j.next=13;break;case 10:j.prev=10,j.t0=j["catch"](3),this.logger.error("Error during command registration:",j.t0);case 13:case"end":return j.stop()}},_callee7,this,[[3,10]])}));return registerCommands}()},{key:"handleInteraction",value:function(){function handleInteraction(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(a){var b,c,d,e,f,g=this;return _regeneratorRuntime().wrap(function _callee8$(h){for(;1;)switch(h.prev=h.next){case 0:b=_createForOfIteratorHelper(this.controllers),h.prev=1,d=/*#__PURE__*/_regeneratorRuntime().mark(function _loop(){var b,d,e,f,h,i,j,k,l,m,n;return _regeneratorRuntime().wrap(function _loop$(o){for(;1;)switch(o.prev=o.next){case 0:if(b=c.value,d=g.controllerInstancesCache.get(b),d||(d=mainContainer.get(b.constructor),g.controllerInstancesCache.set(b,d)),e=getCommandMap(d),e){o.next=6;break}return o.abrupt("return",0);case 6:if(f=void 0,h=void 0,a.isChatInputCommand()||a.isContextMenuCommand()?(h=a.commandName,f=e[h]):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(h=a.customId,f=null===(i=Object.entries(e).find(function(b){var c=_slicedToArray(b,2),d=c[0],e=c[1];if(!e.regex||!h)return!1;var f=e.regex.exec(h);return null!==f&&void 0!==f&&f.groups?(a.dynamicParams=f.groups,!0):h===d}))||void 0===i?void 0:i[1]),!f){o.next=32;break}if(j=f,k=j.methodName,l=j.type,o.prev=11,!(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())){o.next=20;break}return g.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())&&(m=a.dynamicParams||{}),o.next=18,d[k](a,m);case 18:o.next=22;break;case 20:g.logger.debug(l,k,CommandType.BUTTON,a.isButton()),g.logger.warn("Interaction type mismatch for command \"".concat(h,"\". Interaction type: ").concat(a.type,"."));case 22:o.next=31;break;case 24:if(o.prev=24,o.t0=o["catch"](11),g.logger.error("Error executing command \"".concat(h,"\":"),o.t0),!a.isRepliable()){o.next=31;break}return n=EmbedUtil.createErrorEmbed("An error occurred while executing the command."),o.next=31,a.reply({embeds:[n],flags:MessageFlagsBitField.Flags.Ephemeral});case 31:return o.abrupt("return",{v:void 0});case 32:case"end":return o.stop()}},_loop,null,[[11,24]])}),b.s();case 4:if((c=b.n()).done){h.next=13;break}return h.delegateYield(d(),"t0",6);case 6:if(e=h.t0,0!==e){h.next=9;break}return h.abrupt("continue",11);case 9:if(!e){h.next=11;break}return h.abrupt("return",e.v);case 11:h.next=4;break;case 13:h.next=18;break;case 15:h.prev=15,h.t1=h["catch"](1),b.e(h.t1);case 18:return h.prev=18,b.f(),h.finish(18);case 21:if(!a.isRepliable()){h.next=25;break}return f=EmbedUtil.createErrorEmbed("Command not found!"),h.next=25,a.reply({embeds:[f],flags:MessageFlagsBitField.Flags.Ephemeral});case 25:case"end":return h.stop()}},_callee8,this,[[1,15,18,21]])}));return handleInteraction}()},{key:"handleMessage",value:function(){function handleMessage(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o;return _regeneratorRuntime().wrap(function _callee9$(p){for(;1;)switch(p.prev=p.next){case 0:if(!a.author.bot&&null!==(b=a.content)&&void 0!==b&&b.trim()){p.next=2;break}return p.abrupt("return");case 2: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),p.prev=5,e.s();case 7:if((f=e.n()).done){p.next=40;break}g=f.value,h=this.controllerInstancesCache.get(g.constructor),h||(i=Reflect.getMetadata("inversify:container",g.constructor),h=i.resolve(g.constructor),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),p.prev=14,k.s();case 16:if((l=k.n()).done){p.next=30;break}if(m=l.value,n=m.keyword,o=m.method,n&&n!==c){p.next=28;break}return p.prev=20,p.next=23,h[o](a);case 23:p.next=28;break;case 25:p.prev=25,p.t0=p["catch"](20),this.logger.error("Error handling message \"".concat(c,"\" for method \"").concat(o,"\":"),p.t0);case 28:p.next=16;break;case 30:p.next=35;break;case 32:p.prev=32,p.t1=p["catch"](14),k.e(p.t1);case 35:return p.prev=35,k.f(),p.finish(35);case 38:p.next=7;break;case 40:p.next=45;break;case 42:p.prev=42,p.t2=p["catch"](5),e.e(p.t2);case 45:return p.prev=45,e.f(),p.finish(45);case 48:case"end":return p.stop()}},_callee9,this,[[5,42,45,48],[14,32,35,38],[20,25]])}));return handleMessage}()},{key:"handleReaction",value:function(){function handleReaction(b,c){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p;return _regeneratorRuntime().wrap(function _callee10$(q){for(;1;)switch(q.prev=q.next){case 0:return c=b.user,d=b.action,q.next=3,a.message.fetch();case 3: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),q.prev=5,f.s();case 7:if((g=f.n()).done){q.next=40;break}h=g.value,i=this.controllerInstancesCache.get(h.constructor),i||(j=Reflect.getMetadata("inversify:container",h.constructor),i=j.resolve(h.constructor),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),q.prev=14,l.s();case 16:if((m=l.n()).done){q.next=30;break}if(n=m.value,o=n.emoji,p=n.method,o&&o!==a.emoji.name){q.next=28;break}return q.prev=20,q.next=23,i[p](a,{user:c,action:d});case 23:q.next=28;break;case 25:q.prev=25,q.t0=q["catch"](20),this.logger.error("Error handling reaction \"".concat(a.emoji.name,"\" for method \"").concat(p,"\":"),q.t0);case 28:q.next=16;break;case 30:q.next=35;break;case 32:q.prev=32,q.t1=q["catch"](14),l.e(q.t1);case 35:return q.prev=35,l.f(),q.finish(35);case 38:q.next=7;break;case 40:q.next=45;break;case 42:q.prev=42,q.t2=q["catch"](5),f.e(q.t2);case 45:return q.prev=45,f.f(),q.finish(45);case 48:case"end":return q.stop()}},_callee10,this,[[5,42,45,48],[14,32,35,38],[20,25]])}));return handleReaction}()},{key:"gracefulShutdown",value:function(){function gracefulShutdown(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(){return _regeneratorRuntime().wrap(function _callee11$(a){for(;1;)switch(a.prev=a.next){case 0:if(!this.bot||this.isShuttingDown){a.next=19;break}return a.prev=1,this.isShuttingDown=!0,this.logger.log("Shutting down bot..."),this.bot.removeAllListeners(),a.next=7,this.bot.destroy();case 7:return this.logger.log("Bot has shut down"),a.next=10,wait(100);case 10:process.exit(0),a.next=19;break;case 13:return a.prev=13,a.t0=a["catch"](1),this.logger.error("Error during shutdown:",a.t0),a.next=18,wait(100);case 18:process.exit(0);case 19:case"end":return a.stop()}},_callee11,this,[[1,13]])}));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,size}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__*/_regeneratorRuntime().mark(function _callee6(){var a=this;return _regeneratorRuntime().wrap(function _callee6$(b){for(;;)switch(b.prev=b.next){case 0:return b.prev=0,this.logger.log("Starting bot..."),this.bot.on("ready",/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){return _regeneratorRuntime().wrap(function _callee$(b){for(;1;)switch(b.prev=b.next){case 0:return setInterval(function(){var b;null===(b=a.bot.user)||void 0===b||b.setActivity(sample(a.activities))},1e4),b.next=3,a.registerCommands();case 3:case"end":return b.stop()}},_callee)}))),this.bot.on("interactionCreate",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(b){return _regeneratorRuntime().wrap(function _callee2$(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,a.handleInteraction(b);case 2:case"end":return c.stop()}},_callee2)}));return function(a){return b.apply(this,arguments)}}()),this.bot.on("messageCreate",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(b){return _regeneratorRuntime().wrap(function _callee3$(c){for(;1;)switch(c.prev=c.next){case 0:return c.next=2,a.handleMessage(b);case 2:case"end":return c.stop()}},_callee3)}));return function(a){return b.apply(this,arguments)}}()),this.bot.on("messageReactionAdd",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(b,c){return _regeneratorRuntime().wrap(function _callee4$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,a.handleReaction(b,{user:c,action:ReactionHandlerAction.ADD});case 2:case"end":return d.stop()}},_callee4)}));return function(a,c){return b.apply(this,arguments)}}()),this.bot.on("messageReactionRemove",/*#__PURE__*/function(){var b=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee5(b,c){return _regeneratorRuntime().wrap(function _callee5$(d){for(;1;)switch(d.prev=d.next){case 0:return d.next=2,a.handleReaction(b,{user:c,action:ReactionHandlerAction.REMOVE});case 2:case"end":return d.stop()}},_callee5)}));return function(a,c){return b.apply(this,arguments)}}()),b.next=9,this.bot.login(this.discordToken);case 9:this.logger.log("Bot is online!"),b.next=15;break;case 12:b.prev=12,b.t0=b["catch"](0),this.logger.error("Error during bot startup:",b.t0);case 15:case"end":return b.stop()}},_callee6,this,[[0,12]])}));return start}()},{key:"registerCommands",value:function(){function registerCommands(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee7(){var a,b,c,d,e,f,g,h,i;return _regeneratorRuntime().wrap(function _callee7$(j){for(;1;)switch(j.prev=j.next){case 0:a=[],b=_createForOfIteratorHelper(this.controllers);try{for(b.s();!(c=b.n()).done;)for(f in d=c.value,e=getCommandMap(d),e)g=e[f],h=g.builder,i=g.type,i in CommandType&&h&&a.push(h)}catch(a){b.e(a)}finally{b.f()}if(j.prev=3,!this.bot.application){j.next=8;break}return j.next=7,this.bot.application.commands.set(a);case 7:this.logger.log("Registered ".concat(size(a)," bot commands:"),a.map(function(a){if(a instanceof SlashCommandBuilder&&a.options.length){var b;return{name:a.name,subCommands:null===(b=a.toJSON().options)||void 0===b?void 0:b.map(function(a){return a.name})}}return{name:a.name}}));case 8:j.next=13;break;case 10:j.prev=10,j.t0=j["catch"](3),this.logger.error("Error during command registration:",j.t0);case 13:case"end":return j.stop()}},_callee7,this,[[3,10]])}));return registerCommands}()},{key:"handleInteraction",value:function(){function handleInteraction(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee8(a){var b,c,d,e,f,g=this;return _regeneratorRuntime().wrap(function _callee8$(h){for(;1;)switch(h.prev=h.next){case 0:b=_createForOfIteratorHelper(this.controllers),h.prev=1,d=/*#__PURE__*/_regeneratorRuntime().mark(function _loop(){var b,d,e,f,h,i,j,k,l,m,n;return _regeneratorRuntime().wrap(function _loop$(o){for(;1;)switch(o.prev=o.next){case 0:if(b=c.value,d=g.controllerInstancesCache.get(b),d||(d=mainContainer.get(b.constructor),g.controllerInstancesCache.set(b,d)),e=getCommandMap(d),e){o.next=6;break}return o.abrupt("return",0);case 6:if(f=void 0,h=void 0,a.isChatInputCommand()||a.isContextMenuCommand()?(h=a.commandName,f=e[h]):(a.isButton()||a.isStringSelectMenu()||a.isModalSubmit())&&(h=a.customId,f=null===(i=Object.entries(e).find(function(b){var c=_slicedToArray(b,2),d=c[0],e=c[1];if(!e.regex||!h)return!1;var f=e.regex.exec(h);return null!==f&&void 0!==f&&f.groups?(a.dynamicParams=f.groups,!0):h===d}))||void 0===i?void 0:i[1]),!f){o.next=32;break}if(j=f,k=j.methodName,l=j.type,o.prev=11,!(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())){o.next=20;break}return g.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())&&(m=a.dynamicParams||{}),o.next=18,d[k](a,m);case 18:o.next=22;break;case 20:g.logger.debug(l,k,CommandType.BUTTON,a.isButton()),g.logger.warn("Interaction type mismatch for command \"".concat(h,"\". Interaction type: ").concat(a.type,"."));case 22:o.next=31;break;case 24:if(o.prev=24,o.t0=o["catch"](11),g.logger.error("Error executing command \"".concat(h,"\":"),o.t0),!a.isRepliable()){o.next=31;break}return n=EmbedUtil.createErrorEmbed("An error occurred while executing the command."),o.next=31,a.reply({embeds:[n],flags:MessageFlagsBitField.Flags.Ephemeral});case 31:return o.abrupt("return",{v:void 0});case 32:case"end":return o.stop()}},_loop,null,[[11,24]])}),b.s();case 4:if((c=b.n()).done){h.next=13;break}return h.delegateYield(d(),"t0",6);case 6:if(e=h.t0,0!==e){h.next=9;break}return h.abrupt("continue",11);case 9:if(!e){h.next=11;break}return h.abrupt("return",e.v);case 11:h.next=4;break;case 13:h.next=18;break;case 15:h.prev=15,h.t1=h["catch"](1),b.e(h.t1);case 18:return h.prev=18,b.f(),h.finish(18);case 21:if(!a.isRepliable()){h.next=25;break}return f=EmbedUtil.createErrorEmbed("Command not found!"),h.next=25,a.reply({embeds:[f],flags:MessageFlagsBitField.Flags.Ephemeral});case 25:case"end":return h.stop()}},_callee8,this,[[1,15,18,21]])}));return handleInteraction}()},{key:"handleMessage",value:function(){function handleMessage(b){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee9(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o;return _regeneratorRuntime().wrap(function _callee9$(p){for(;1;)switch(p.prev=p.next){case 0:if(!a.author.bot&&null!==(b=a.content)&&void 0!==b&&b.trim()){p.next=2;break}return p.abrupt("return");case 2: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),p.prev=5,e.s();case 7:if((f=e.n()).done){p.next=40;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),p.prev=14,k.s();case 16:if((l=k.n()).done){p.next=30;break}if(m=l.value,n=m.keyword,o=m.method,n&&n!==c){p.next=28;break}return p.prev=20,p.next=23,h[o](a);case 23:p.next=28;break;case 25:p.prev=25,p.t0=p["catch"](20),this.logger.error("Error handling message \"".concat(c,"\" for method \"").concat(o,"\":"),p.t0);case 28:p.next=16;break;case 30:p.next=35;break;case 32:p.prev=32,p.t1=p["catch"](14),k.e(p.t1);case 35:return p.prev=35,k.f(),p.finish(35);case 38:p.next=7;break;case 40:p.next=45;break;case 42:p.prev=42,p.t2=p["catch"](5),e.e(p.t2);case 45:return p.prev=45,e.f(),p.finish(45);case 48:case"end":return p.stop()}},_callee9,this,[[5,42,45,48],[14,32,35,38],[20,25]])}));return handleMessage}()},{key:"handleReaction",value:function(){function handleReaction(b,c){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee10(a,b){var c,d,e,f,g,h,i,j,k,l,m,n,o,p;return _regeneratorRuntime().wrap(function _callee10$(q){for(;1;)switch(q.prev=q.next){case 0:return c=b.user,d=b.action,q.next=3,a.message.fetch();case 3: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),q.prev=5,f.s();case 7:if((g=f.n()).done){q.next=40;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),q.prev=14,l.s();case 16:if((m=l.n()).done){q.next=30;break}if(n=m.value,o=n.emoji,p=n.method,o&&o!==a.emoji.name){q.next=28;break}return q.prev=20,q.next=23,i[p](a,{user:c,action:d});case 23:q.next=28;break;case 25:q.prev=25,q.t0=q["catch"](20),this.logger.error("Error handling reaction \"".concat(a.emoji.name,"\" for method \"").concat(p,"\":"),q.t0);case 28:q.next=16;break;case 30:q.next=35;break;case 32:q.prev=32,q.t1=q["catch"](14),l.e(q.t1);case 35:return q.prev=35,l.f(),q.finish(35);case 38:q.next=7;break;case 40:q.next=45;break;case 42:q.prev=42,q.t2=q["catch"](5),f.e(q.t2);case 45:return q.prev=45,f.f(),q.finish(45);case 48:case"end":return q.stop()}},_callee10,this,[[5,42,45,48],[14,32,35,38],[20,25]])}));return handleReaction}()},{key:"gracefulShutdown",value:function(){function gracefulShutdown(){return a.apply(this,arguments)}var a=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee11(){return _regeneratorRuntime().wrap(function _callee11$(a){for(;1;)switch(a.prev=a.next){case 0:if(!this.bot||this.isShuttingDown){a.next=19;break}return a.prev=1,this.isShuttingDown=!0,this.logger.log("Shutting down bot..."),this.bot.removeAllListeners(),a.next=7,this.bot.destroy();case 7:return this.logger.log("Bot has shut down"),a.next=10,wait(100);case 10:process.exit(0),a.next=19;break;case 13:return a.prev=13,a.t0=a["catch"](1),this.logger.error("Error during shutdown:",a.t0),a.next=18,wait(100);case 18:process.exit(0);case 19:case"end":return a.stop()}},_callee11,this,[[1,13]])}));return gracefulShutdown}()}])}();
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
import 'reflect-metadata';
|
|
19
|
-
import { Container, type
|
|
19
|
+
import { Container, type ServiceIdentifier } from 'inversify';
|
|
20
20
|
import { type ActivityOptions, type ClientOptions } from 'discord.js';
|
|
21
|
-
type ServiceIdentifier = interfaces.ServiceIdentifier;
|
|
22
21
|
/** The main Inversify container for managing dependencies. */
|
|
23
22
|
export declare const mainContainer: Container;
|
|
24
23
|
/**
|
|
@@ -60,4 +59,3 @@ export declare function MeoCord(options: {
|
|
|
60
59
|
activities?: ActivityOptions[];
|
|
61
60
|
services?: ServiceIdentifier[];
|
|
62
61
|
}): (target: any) => void;
|
|
63
|
-
export {};
|
|
@@ -78,4 +78,4 @@ var b=Reflect.getMetadata("design:paramtypes",a)||[];b.forEach(function(a){mainC
|
|
|
78
78
|
* ```
|
|
79
79
|
*/export function UseGuard(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return function(a,c,d){var e=d.value;// TypeScript: Enforce that the first argument is an Interaction
|
|
80
80
|
// Store guard metadata for later access (if needed)
|
|
81
|
-
d.value=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){var a,d,f,g,h,i,j,k,l,m,n,o=arguments;return _regeneratorRuntime().wrap(function _callee$(p){for(;1;)switch(p.prev=p.next){case 0:for(a=o.length,d=Array(a),f=0;f<a;f++)d[f]=o[f];if(d[0]instanceof BaseInteraction){p.next=3;break}throw new Error("The first argument of ".concat(c+""," must be an instance of Interaction."));case 3:g=0,h=b;case 4:if(!(g<h.length)){p.next=18;break}if(j=h[g],k=void 0,isGuardWithParams(j)?(l=j.provide,m=j.params,k=mainContainer.
|
|
81
|
+
d.value=/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(){var a,d,f,g,h,i,j,k,l,m,n,o=arguments;return _regeneratorRuntime().wrap(function _callee$(p){for(;1;)switch(p.prev=p.next){case 0:for(a=o.length,d=Array(a),f=0;f<a;f++)d[f]=o[f];if(d[0]instanceof BaseInteraction){p.next=3;break}throw new Error("The first argument of ".concat(c+""," must be an instance of Interaction."));case 3:g=0,h=b;case 4:if(!(g<h.length)){p.next=18;break}if(j=h[g],k=void 0,isGuardWithParams(j)?(l=j.provide,m=j.params,k=mainContainer.get(l,{autobind:!0}),Object.assign(k,m)):k=mainContainer.get(j,{autobind:!0}),k.canActivate){p.next=10;break}throw new Error("Guard ".concat(j.constructor.name," applied to ").concat(c+""," does not have a valid canActivate method."));case 10:return p.next=12,(i=k).canActivate.apply(i,d);case 12:if(n=p.sent,n){p.next=15;break}return p.abrupt("return");case 15:g++,p.next=4;break;case 18:return p.abrupt("return",e.apply(this,d));case 19:case"end":return p.stop()}},_callee,this)})),Reflect.defineMetadata("guards",b,a,c)}}
|
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.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"packageManager": "yarn@4.7.0",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
@@ -59,29 +59,29 @@
|
|
|
59
59
|
],
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@babel/cli": "^7.26.4",
|
|
62
|
-
"@babel/core": "^7.26.
|
|
62
|
+
"@babel/core": "^7.26.10",
|
|
63
63
|
"@babel/preset-env": "^7.26.9",
|
|
64
64
|
"@babel/preset-typescript": "^7.26.0",
|
|
65
|
-
"@eslint/js": "^9.
|
|
65
|
+
"@eslint/js": "^9.22.0",
|
|
66
66
|
"@types/copyfiles": "^2.4.4",
|
|
67
67
|
"@types/lodash-es": "^4.17.12",
|
|
68
68
|
"@types/webpack-node-externals": "^3.0.4",
|
|
69
|
-
"@typescript-eslint/parser": "^8.
|
|
69
|
+
"@typescript-eslint/parser": "^8.27.0",
|
|
70
70
|
"babel-plugin-module-resolver": "^5.0.2",
|
|
71
71
|
"babel-preset-minify": "^0.5.2",
|
|
72
72
|
"copyfiles": "^2.4.1",
|
|
73
|
-
"eslint": "^9.
|
|
74
|
-
"eslint-config-prettier": "^10.
|
|
73
|
+
"eslint": "^9.22.0",
|
|
74
|
+
"eslint-config-prettier": "^10.1.1",
|
|
75
75
|
"eslint-plugin-headers": "^1.2.1",
|
|
76
76
|
"eslint-plugin-import": "^2.31.0",
|
|
77
77
|
"eslint-plugin-prettier": "^5.2.3",
|
|
78
78
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
79
79
|
"globals": "^16.0.0",
|
|
80
80
|
"husky": "^9.1.7",
|
|
81
|
-
"prettier": "^3.5.
|
|
82
|
-
"tsc-alias": "^1.8.
|
|
83
|
-
"typescript": "^5.
|
|
84
|
-
"typescript-eslint": "^8.
|
|
81
|
+
"prettier": "^3.5.3",
|
|
82
|
+
"tsc-alias": "^1.8.11",
|
|
83
|
+
"typescript": "^5.8.2",
|
|
84
|
+
"typescript-eslint": "^8.27.0"
|
|
85
85
|
},
|
|
86
86
|
"peerDependencies": {
|
|
87
87
|
"discord.js": "^14.17.3",
|
|
@@ -95,13 +95,13 @@
|
|
|
95
95
|
"discord.js": "^14.18.0",
|
|
96
96
|
"dotenv": "^16.4.7",
|
|
97
97
|
"file-loader": "^6.2.0",
|
|
98
|
-
"inversify": "^
|
|
98
|
+
"inversify": "^7.1.0",
|
|
99
99
|
"lodash-es": "^4.17.21",
|
|
100
100
|
"nodemon": "^3.1.9",
|
|
101
101
|
"raw-loader": "^4.0.2",
|
|
102
102
|
"reflect-metadata": "^0.2.2",
|
|
103
103
|
"simple-git": "^3.27.0",
|
|
104
|
-
"terser-webpack-plugin": "^5.3.
|
|
104
|
+
"terser-webpack-plugin": "^5.3.14",
|
|
105
105
|
"ts-loader": "^9.5.2",
|
|
106
106
|
"tsconfig-paths-webpack-plugin": "^4.2.0",
|
|
107
107
|
"webpack": "^5.98.0",
|