Support conf/env avatar loading

This commit is contained in:
Luke Murphy 2021-01-16 19:59:09 +01:00
parent 47ba30fe28
commit 128d42c080
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 15 additions and 2 deletions

View File

@ -1,5 +1,9 @@
# xbotlib x.x.x (UNRELEASED)
# xbotlib 0.11.0 (2021-01-16)
- Allow to configure avatar from configuration file and environment
# xbotlib 0.10.0 (2021-01-16)
- Implement Redis based storage ([#21](https://git.autonomic.zone/decentral1se/xbotlib/issues/21))

View File

@ -156,6 +156,7 @@ deployments.
- **XBOT_ACCOUNT**: The bot account
- **XBOT_PASSWORD**: The bot password
- **XBOT_NICK**: The bot nickname
- **XBOT_AVATAR**: The bot avatar icon
## Deploy your bots

View File

@ -200,6 +200,7 @@ class Bot(ClientXMPP):
account = input("Account: ")
password = getpass("Password: ")
nick = input("Nickname: ")
avatar = input("Avatar: ")
config = ConfigParser()
config[self.name] = {"account": account, "password": password}
@ -207,6 +208,9 @@ class Bot(ClientXMPP):
if nick:
config[self.name]["nick"] = nick
if avatar:
config[self.name]["avatar"] = avatar
with open(self.CONFIG_FILE, "w") as file_handle:
config.write(file_handle)
@ -225,6 +229,11 @@ class Bot(ClientXMPP):
nick = (
self.args.nick or self.config.nick or environ.get("XBOT_NICK", None)
)
avatar = (
self.args.avatar
or self.config.avatar
or environ.get("XBOT_AVATAR", None)
)
if not account:
self.log.error("Unable to discover account")
@ -241,8 +250,7 @@ class Bot(ClientXMPP):
self.account = account
self.password = password
self.nick = nick
self.avatar = self.args.avatar
self.avatar = avatar
def register_xmpp_event_handlers(self):
"""Register functions against specific XMPP event handlers."""