utils.cli shouldn't know about Database

This commit is contained in:
jesopo 2019-10-29 18:00:38 +00:00
parent 46e4b75f6b
commit 40a340e94f
2 changed files with 11 additions and 5 deletions

10
bitbotd
View file

@ -103,9 +103,15 @@ if args.remove_server:
sys.stderr.write("Unknown server '%s'\n" % alias) sys.stderr.write("Unknown server '%s'\n" % alias)
sys.exit(0) sys.exit(0)
def _add_server():
details = utils.cli.add_server()
database.servers.add(details.alias, details.hostname, details.port,
details.password, details.tls, details.bindhost, details.nickname,
details.username, details.realname)
if args.add_server: if args.add_server:
print("Adding a new server") print("Adding a new server")
utils.cli.add_server(database) _add_server()
sys.exit(0) sys.exit(0)
cache = Cache.Cache() cache = Cache.Cache()
@ -169,7 +175,7 @@ if len(server_configs):
else: else:
try: try:
if utils.cli.bool_input("no servers found, add one?"): if utils.cli.bool_input("no servers found, add one?"):
utils.cli.add_server(database) _add_server()
except KeyboardInterrupt: except KeyboardInterrupt:
print() print()
pass pass

View file

@ -1,10 +1,10 @@
from src import Database from . import irc
def bool_input(s: str): def bool_input(s: str):
result = input("%s (Y/n): " % s) result = input("%s (Y/n): " % s)
return not result or result[0].lower() in ["", "y"] return not result or result[0].lower() in ["", "y"]
def add_server(database: "Database.Database"): def add_server():
alias = input("alias: ") alias = input("alias: ")
hostname = input("hostname: ") hostname = input("hostname: ")
port = int(input("port: ")) port = int(input("port: "))
@ -15,5 +15,5 @@ def add_server(database: "Database.Database"):
realname = input("realname: ") realname = input("realname: ")
bindhost = input("bindhost?: ") bindhost = input("bindhost?: ")
server_id = database.servers.add(alias, hostname, port, password, tls, return irc.IRCConnectionParameters(-1, alias, hostname, port, password, tls,
bindhost, nickname, username, realname) bindhost, nickname, username, realname)