EuIrcBot icon indicating copy to clipboard operation
EuIrcBot copied to clipboard

Construct a system for inter-bot-module dependencies

Open cbgbt opened this issue 11 years ago • 3 comments

It was discussed that it would be neat if a module could expose an API to other modules.

For instance, say one module exposes link shortening capabilities to IRC users. It would be cool if it could expose a shortenLink() function to other modules, so they they could make their own messages more succinct.

Of course the bot would have to make sure that dependencies get resolved, and that modules are loaded in such a way that dependencies are available to eachother when needed. This is hard because currently moduleMan doesn't actually know when modules have finished loading. In addition, Dependency circles should probably be noticed.

Discussion of design and implementation of such a system should occur here.

cbgbt avatar Jul 04 '14 08:07 cbgbt

See issue #3 as well.

euank avatar Jul 04 '14 08:07 euank

Do you think we should share package.json with npm? Might be better than having to create two different package files.

cbgbt avatar Jul 04 '14 19:07 cbgbt

We can and I'm not sure. I've thought about a little. I was actually thinking about just hooking require for the modules and injecting all other modules as potential require-able things.

https://github.com/felixge/node-sandboxed-module is a related module to this.

However good an idea that looks like, though, I don't think it's doable. "require" is synchronous and we need to be able to depend on modules across the network too which cannot be sync.

However, that's a tangent. We can, of course, drop dependencies in package.json.

My original intent, though, was for modules to export this stuff. The module might have "module.exports.dependencies = ['sirc-google']" or whatever and then the module simply won't be run if the dependency isn't loaded (and an error logged). Likewise, a "module.exports.predependency = ['sirc-database']" specifying module wouldn't be initted unless the database module was already initted.

euank avatar Jul 04 '14 19:07 euank