bot.conf
-> $name.conf
Closes https://git.autonomic.zone/decentral1se/xbotlib/issues/3.
This commit is contained in:
parent
5b43a2cde2
commit
aabe1fa683
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,8 +6,8 @@
|
|||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
.tox/
|
.tox/
|
||||||
__pycache__
|
__pycache__
|
||||||
bot.conf
|
*.conf
|
||||||
bot.py
|
echobot.py
|
||||||
build/
|
build/
|
||||||
dist/
|
dist/
|
||||||
pip-wheel-metadata/
|
pip-wheel-metadata/
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
- Arrange precedence logic for config loading ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
- Arrange precedence logic for config loading ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
||||||
- Remove `--no-input` option and detect it automatically ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
- Remove `--no-input` option and detect it automatically ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
||||||
- Refer to `jid` as `account` from now on both internally and externally ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
- Refer to `jid` as `account` from now on both internally and externally ([#14](https://git.autonomic.zone/decentral1se/xbotlib/issues/14))
|
||||||
|
- `bot.conf` -> `$name.conf` ([#3](https://git.autonomic.zone/decentral1se/xbotlib/issues/3))
|
||||||
|
|
||||||
# xbotlib 0.7.1 (2021-01-13)
|
# xbotlib 0.7.1 (2021-01-13)
|
||||||
|
|
||||||
|
18
xbotlib.py
18
xbotlib.py
@ -46,9 +46,10 @@ class SimpleMessage:
|
|||||||
class Config:
|
class Config:
|
||||||
"""Bot file configuration."""
|
"""Bot file configuration."""
|
||||||
|
|
||||||
def __init__(self, config):
|
def __init__(self, name, config):
|
||||||
|
self.name = name
|
||||||
self.config = config
|
self.config = config
|
||||||
self.section = config["bot"] if "bot" in config else {}
|
self.section = config[self.name] if self.name in config else {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def account(self):
|
def account(self):
|
||||||
@ -66,9 +67,10 @@ class Config:
|
|||||||
class Bot(ClientXMPP):
|
class Bot(ClientXMPP):
|
||||||
"""XMPP bots for humans."""
|
"""XMPP bots for humans."""
|
||||||
|
|
||||||
CONFIG_FILE = "bot.conf"
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
self.name = type(self).__name__.lower()
|
||||||
|
self.CONFIG_FILE = f"{self.name}.conf"
|
||||||
|
|
||||||
self.parse_arguments()
|
self.parse_arguments()
|
||||||
self.setup_logging()
|
self.setup_logging()
|
||||||
self.read_config()
|
self.read_config()
|
||||||
@ -130,7 +132,7 @@ class Bot(ClientXMPP):
|
|||||||
if exists(config_file_path):
|
if exists(config_file_path):
|
||||||
config.read(config_file_path)
|
config.read(config_file_path)
|
||||||
|
|
||||||
self.config = Config(config)
|
self.config = Config(self.name, config)
|
||||||
|
|
||||||
def generate_config_interactively(self):
|
def generate_config_interactively(self):
|
||||||
"""Generate bot configuration."""
|
"""Generate bot configuration."""
|
||||||
@ -139,12 +141,12 @@ class Bot(ClientXMPP):
|
|||||||
nick = input("Nickname: ")
|
nick = input("Nickname: ")
|
||||||
|
|
||||||
config = ConfigParser()
|
config = ConfigParser()
|
||||||
config["bot"] = {"account": account, "password": password}
|
config[self.name] = {"account": account, "password": password}
|
||||||
|
|
||||||
if nick:
|
if nick:
|
||||||
config["bot"]["nick"] = nick
|
config[self.name]["nick"] = nick
|
||||||
|
|
||||||
with open("bot.conf", "w") as file_handle:
|
with open(self.CONFIG_FILE, "w") as file_handle:
|
||||||
config.write(file_handle)
|
config.write(file_handle)
|
||||||
|
|
||||||
def init_bot(self):
|
def init_bot(self):
|
||||||
|
Reference in New Issue
Block a user