Add error checking in places, set up automatic relay provisioning and fix starting bots

This commit is contained in:
2019-08-25 21:29:11 +01:00
parent ff74968ff8
commit 2d70d5af11
19 changed files with 242 additions and 262 deletions

View File

@@ -7,29 +7,47 @@ class RelayCommand:
def relay(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed:
if length == 7:
if length == 3:
if spl[1] == "add":
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
if not spl[4].isdigit():
failure("Port must be an integer, not %s" % spl[4])
return
else:
id, alias = main.network[spl[2]].add_relay(spl[3], spl[4], spl[5], spl[6])
if spl[2] in main.network.keys():
id, alias = main.network[spl[2]].add_relay()
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
main.saveConf("network")
return
else:
failure("No such network: %s" % spl[2])
return
elif spl[1] == "list":
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
info(dump(main.network[spl[2]].relays))
return
else:
incUsage("relay")
return
elif length == 4:
if spl[1] == "del":
if spl[2] not in main.network.keys():
if spl[1] == "add":
if spl[2] in main.network.keys():
if not spl[3].isdigit():
failure("Must be a number, not %s" % spl[3])
return
id, alias = main.network[spl[2]].add_relay(int(spl[3]))
success("Successfully created relay %s on network %s with alias %s" % (str(id), spl[2], alias))
main.saveConf("network")
return
else:
failure("No such network: %s" % spl[2])
return
if int(spl[3]) not in main.network[spl[2]].relays.keys():
elif spl[1] == "del":
if not spl[2] in main.network.keys():
failure("No such network: %s" % spl[2])
return
if not spl[3].isdigit():
failure("Must be a number, not %s" % spl[3])
return
if not int(spl[3]) in main.network[spl[2]].relays.keys():
failure("No such relay: %s on network %s" % (spl[3], spl[2]))
return
main.network[spl[2]].delete_relay(int(spl[3]))
@@ -39,16 +57,6 @@ class RelayCommand:
else:
incUsage("relay")
return
elif length == 3:
if spl[1] == "list":
if spl[2] not in main.network.keys():
failure("No such network: %s" % spl[2])
return
info(dump(main.network[spl[2]].relays))
return
else:
incUsage("relay")
return
else:
incUsage("relay")
return