mosbth / irc2phpbb

IRC bot, now lives on Discord bur remains its power to visit IRC whenever it wants.
12 stars 16 forks source link

Rework how the configuration of marvin is done #71

Open mosbth opened 1 week ago

mosbth commented 1 week ago

We have two bot protocols, irc and discord. They need separate settings and perhaps they have some common settings.

Today each bot has its own configuration as a dictionary in each bot and that is merged with the external config file, if such exists at startup.

The bot should work, if possible, with the default hard coded settings. That is to avoid the need of actual creating a separate config file.

It should be easy to start marvin, like this.

marvin irc
marvin discord

Some generic options should be available, such as:

marvin --help
marvin --version

The default configuration file could be named marvin.json and it should be possible to use another config file using cli.

marvin --config marvin2.json irc

An example of the generic and default configuration file can be like this.

{
    "general": {
        "dirIncoming": "work/incoming",
        "dirDone": "work/done"
    },
    "irc": {
        "server": "127.0.0.1",
        "port": 6667,
        "channel": "marvin",
        "nick": "marvin",
        "realname": "Marvin The All Mighty",
        "ident": null
    },
    "discord": {
        "token": ""
    }
}

An alternative, or complement, to a json config file could be .env, if that for some reason seems suitable.

We could support environment variables (without env) if needed. That could be useful for example when dealing with secrets. Each bot can have its own support for various environment variables.For example the irc bot could have IDENT and the discord bot could have TOKEN.

In the existing irc configuration we also have items like irclogfile, irclogmax and lastfm which might be removed.

kh31d4r commented 1 week ago

i like the .env file (combined with environment variables) better than the json file.

mosbth commented 1 week ago

Ok, if moving on with dotenv, the config file would look something like this.

# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
#  * .env                contains default values for the environment variables needed by the app
#  * .env.local          uncommitted file with local overrides
#  * .env.$APP_ENV       committed environment-specific defaults
#  * .env.$APP_ENV.local uncommitted environment-specific overrides
#
# Real environment variables win over .env files.
#
# DO NOT DEFINE PRODUCTION SECRETS IN THIS FILE NOR IN ANY OTHER COMMITTED FILES.

# General for any bot
DIR_INCOMING="work/incoming"
DIR_DONE="work/done"

# Bot irc specifics
IRC_SERVER="127.0.0.1"
IRC_PORT=6667
IRC_CHANNEL="marvin"
IRC_NICK="marvin"
IRC_REAL_NAME="Marvin The All Mighty"
IRC_IDENT=

# Bot discord specifics
DISCORD_TOKEN=
kh31d4r commented 1 week ago

maybe we should prefix the "framework" related config with "MARVIN" or "BOT" or something, and in case we have config for plugins they can have the plugin name in uppercase as prefix?

mosbth commented 1 week ago

Sounds nice. All fine with me.

All and all, I guess/feel dotenv is better than json in many aspects for this configuration, so lets move on with that.