Re-work for simpler generation flow

This commit is contained in:
Luke Murphy 2021-01-19 20:36:02 +01:00
parent 9597a9214f
commit 34aacc07cb
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 4 additions and 67 deletions

View File

@ -1,5 +1,9 @@
# xbotlib x.x.x (UNRELEASED) # xbotlib x.x.x (UNRELEASED)
# xbotlib 0.14.0 (2021-01-19)
- Reduce generated config flow to only mandatory options
# xbotlib 0.13.1 (2021-01-19) # xbotlib 0.13.1 (2021-01-19)
- Document `Bot` attributes/functions ([#35](https://git.autonomic.zone/decentral1se/xbotlib/issues/35)) - Document `Bot` attributes/functions ([#35](https://git.autonomic.zone/decentral1se/xbotlib/issues/35))

View File

@ -266,7 +266,6 @@ class Bot(ClientXMPP):
def generate_config_interactively(self): def generate_config_interactively(self):
"""Generate bot configuration.""" """Generate bot configuration."""
print("*" * 79) print("*" * 79)
print( print(
"Please enter the XMPP user account of your bot. ", "Please enter the XMPP user account of your bot. ",
"This is often referred to as the JID (Jabbed ID). ", "This is often referred to as the JID (Jabbed ID). ",
@ -277,77 +276,11 @@ class Bot(ClientXMPP):
print("Please enter the password for your bot account") print("Please enter the password for your bot account")
password = getpass("Password: ") password = getpass("Password: ")
print("Please enter the nickname for your bot account")
nick = input("Nickname: ")
print(
"Please enter the path to your avatar file",
"The default is an avatar.png file in the current directory",
"(leave empty if you want the default or have no avatar)",
sep="\n",
)
avatar = input("Avatar: ")
print(
"Please enter the connection URL of your Redis instance",
"(leave empty if you are not using Redis)",
sep="\n",
)
redis_url = input("Redis URL: ")
print(
"Please supply a list of rooms to automatically join",
"for example, foo@muc.vvvaria.org, bar@muc.vvvvvvaria.org",
"(leave empty if you don't want to join rooms when starting)",
sep="\n",
)
rooms = input("Rooms: ")
print(
"Please choose to disable auto-join on invite if you prefer",
"that your bot does not join after being invited to a room",
"(type 'y' to choose to disable)",
sep="\n",
)
no_auto_join = input("Disable auto-join on invite? ")
print(
"Please choose the port to serve HTTP from",
"(leave empty to choose default value of 8080)",
sep="\n",
)
port = input("Port: ")
print(
"Please choose Jinja template file path",
"(leave empty to choose default value of index.html.j2)",
sep="\n",
)
template = input("Jinja HTML template: ")
print("*" * 79) print("*" * 79)
config = ConfigParser() config = ConfigParser()
config[self.name] = {"account": account, "password": password} config[self.name] = {"account": account, "password": password}
if nick:
config[self.name]["nick"] = nick
if avatar:
config[self.name]["avatar"] = avatar
if redis_url:
config[self.name]["redis_url"] = redis_url
if rooms:
config[self.name]["rooms"] = rooms
if no_auto_join:
config[self.name]["auto_join"] = (
True if no_auto_join == "y" else False
)
if port:
config[self.name]["port"] = port
if template:
config[self.name]["template"] = template
with open(self.CONFIG_FILE, "w") as file_handle: with open(self.CONFIG_FILE, "w") as file_handle:
config.write(file_handle) config.write(file_handle)
self.log.info(f"Generated {self.CONFIG_FILE}") self.log.info(f"Generated {self.CONFIG_FILE}")