add --remove-server/-R cli arg
This commit is contained in:
parent
c083d4845a
commit
89c12e845a
2 changed files with 19 additions and 0 deletions
|
@ -21,6 +21,10 @@ class Servers(Table):
|
||||||
realname])
|
realname])
|
||||||
return self.database.execute_fetchone(
|
return self.database.execute_fetchone(
|
||||||
"SELECT server_id FROM servers ORDER BY server_id DESC LIMIT 1")[0]
|
"SELECT server_id FROM servers ORDER BY server_id DESC LIMIT 1")[0]
|
||||||
|
def by_alias(self, alias: str) -> typing.Optional[int]:
|
||||||
|
ids = self.database.execute_fetchone(
|
||||||
|
"SELECT server_id FROM servers WHERE alias=?", [alias])
|
||||||
|
return ids[0] if ids else None
|
||||||
def get_all(self):
|
def get_all(self):
|
||||||
return self.database.execute_fetchall(
|
return self.database.execute_fetchall(
|
||||||
"SELECT server_id, alias FROM servers")
|
"SELECT server_id, alias FROM servers")
|
||||||
|
@ -45,6 +49,8 @@ class Servers(Table):
|
||||||
raise ValueError("Unknown column on servers table '%s'" % column)
|
raise ValueError("Unknown column on servers table '%s'" % column)
|
||||||
self.database.execute(
|
self.database.execute(
|
||||||
"UPDATE servers SET %s=? WHERE server_id=?" % column, [value, id])
|
"UPDATE servers SET %s=? WHERE server_id=?" % column, [value, id])
|
||||||
|
def delete(self, id: int):
|
||||||
|
self.database.execute("DELETE FROM servers WHERE server_id=?", [id])
|
||||||
|
|
||||||
class Channels(Table):
|
class Channels(Table):
|
||||||
def add(self, server_id: int, name: str):
|
def add(self, server_id: int, name: str):
|
||||||
|
|
13
start.py
13
start.py
|
@ -46,6 +46,9 @@ arg_parser.add_argument("--module-args", "-M",
|
||||||
arg_parser.add_argument("--startup-disconnects", "-D",
|
arg_parser.add_argument("--startup-disconnects", "-D",
|
||||||
help="Tolerate failed connections on startup", action="store_true")
|
help="Tolerate failed connections on startup", action="store_true")
|
||||||
|
|
||||||
|
arg_parser.add_argument("--remove-server", "-R",
|
||||||
|
help="Remove a server by it's alias")
|
||||||
|
|
||||||
args = arg_parser.parse_args()
|
args = arg_parser.parse_args()
|
||||||
|
|
||||||
if args.version:
|
if args.version:
|
||||||
|
@ -63,6 +66,16 @@ log.info("Starting BitBot %s (Python v%s)",
|
||||||
|
|
||||||
database = Database.Database(log, args.database)
|
database = Database.Database(log, args.database)
|
||||||
|
|
||||||
|
if args.remove_server:
|
||||||
|
alias = args.remove_server
|
||||||
|
id = database.servers.by_alias(alias)
|
||||||
|
if not id == None:
|
||||||
|
database.servers.delete(id)
|
||||||
|
print("Deleted server '%s'" % alias)
|
||||||
|
else:
|
||||||
|
sys.stderr.write("Unknown server '%s'\n" % alias)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
if args.add_server:
|
if args.add_server:
|
||||||
print("Adding a new server")
|
print("Adding a new server")
|
||||||
utils.cli.add_server(database)
|
utils.cli.add_server(database)
|
||||||
|
|
Loading…
Reference in a new issue