hubotio / hubot

A customizable life embetterment robot.
https://hubotio.github.io/hubot/
MIT License
16.64k stars 3.75k forks source link

Is it possible to have nested modules and in which case how? #1567

Closed gonace closed 1 year ago

gonace commented 2 years ago

I'm trying to include nested modules but can't get it to work, is it possible in which case how?

This is what I'm trying out but can't get to work

This file is called serie.js and is located under the scripts folder.


const floorball = require('./serie/floorball/index');
const hockey = require('./serie/hockey/index');

const command = { floorball , hockey, }; module.exports = command;


> Both `'./serie/floorball/index'` and `'./serie/floorball/index'` looks like this

module.exports = (robot) => { robot.hear(/serie floorball help/i, (res) => { res.reply('Test'); }); };

module.exports = (robot) => { robot.hear(/serie hockey help/i, (res) => { res.reply('Test'); }); };



But this does not work, any ideas?
joeyguerra commented 1 year ago

Hubot's loadScripts API expects a module to export a function with a single argument like

module.exports = (robot) => {}

But scripts/serie.js exports an object.

I think if you try something like the following, you might get what you want.

const floorball = require('./serie/floorball/index');
const hockey = require('./serie/hockey/index');

const command = {
    floorball ,
    hockey,
};
module.exports = (robot) =>{
  floorball(robot);
  hockey(robot);
};
joeyguerra commented 1 year ago

Closing for now.