Giter VIP home page Giter VIP logo

Comments (9)

euank avatar euank commented on August 15, 2024

I like the parseConfig idea, but I would also like to support more format right off the bat.

Ideally, the following 4 formats would work with no parseConfig method provided:

  • config.json
  • config.js (basically a json file with weaker keys)
  • config.yml
  • config.ini (less important)

We can make this config format sorta module-manager specific. The bot should read the config file and provide it as a string to any module manager that wants it.

The module manager should then be able to add its own functionality on top of that (presumably almost all module managers will implement those formats excluding .js because that's a dumb format for non-node languages).

from euircbot.

cbgbt avatar cbgbt commented on August 15, 2024

Hmm. The way my implementation is right now, the module manager detects the existance of sirc-config.default.(extension) in the module folders. Are you saying that the core bot should be digging around in the module folder?

from euircbot.

euank avatar euank commented on August 15, 2024

No, the core bot absolutely shouldn't and that's a good point.

However, the config folder, like the data folder, has to be centralized. For example, two modules in different languages each might want to login to twitter, and it would make sense for them to use the same config / account via saying "I want twitter.json".

The default config is a much more iffy thing and potentially each module manager could let modules bring their own, but that could lead to duplication. I'm not sure on that one, and I'll be okay with whatever design decision you want to go with I think.

from euircbot.

cbgbt avatar cbgbt commented on August 15, 2024

Maybe instead of dropping a magic file into a module and using an exported function, we could utilize whatever package system is implemented via #30

{
    ...
    "requires-config": [
        {
            "filename": "twitter.json",
            "parser": "module/twitter" // Load the config however module/twitter does it
        },
        {
            "filename": "my-config.ini", // The filename of the config dropped into the conf folder
            "default": "sirc-default.config.ini", // If no config exists, copy this one
            "parser": "default" // Default parser resolution. Try parseConfig, if none exists, fallback on attempting to detect extension and using the default parsers
        }
    ]
    ...
}

I guess my implementation currently might be a little too module manager-specific.

from euircbot.

euank avatar euank commented on August 15, 2024

Looks good to me

from euircbot.

cbgbt avatar cbgbt commented on August 15, 2024

I thought about this a little more.

Why not just export the needed config files?

module.exports.configsNeeded = [
    {
        "filename": "twitter.json",
        "parser": "default"
    }
]

from euircbot.

euank avatar euank commented on August 15, 2024

Yeah, that's also a fine option. That was my original thought. Infer config name if it's not exported, use exported only if it is.

I don't have a strong preference regarding that vs shoving it in package.json.

from euircbot.

cbgbt avatar cbgbt commented on August 15, 2024

So look for (modulename).(predefined list of extensions) if there's no exported list, and do nothing if that file isn't there?

from euircbot.

euank avatar euank commented on August 15, 2024

Yup!

And then set this.config if you find the modulename one, set this.config.[name] for each named config if they're named. Something like that.

Oh, and my preferred code off the top of my head for specifying:

module.exports.configFile = "x" // x.json, x.yml, who cares. Extension optional
module.exports.run = function() {
// this.config is set to x.json's parsed contents
}


// other module
module.exports.configFiles = ['x', 'y', 'z']

module.exports.run = function() {
// this.config.x, this.config.y, and this.config.z are set
}


// another module
module.exports.name = "sirc-example"

module.exports.run = function() {
//this.config is set to the contents of sirc-example.json if it exists
}

// another, custom parser

module.exports.configFiles = [
'x', // Default parser
{
    name: 'y.ini',
    parser: function(rawIn, parsedCallback) { /* todo */ }
}];

The intent here is to make handling single config files very clean because that is the general case, while allowing multiple as needed.

from euircbot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.