Error checking on alias removal and clean up when removing relays

This commit is contained in:
Mark Veidemanis 2019-10-02 20:45:28 +01:00
parent a3b81f8849
commit d35f96de87
3 changed files with 22 additions and 21 deletions

View File

@ -11,16 +11,6 @@ class AliasCommand:
if length == 1:
info(dump(main.alias))
return
elif length == 2:
if spl[1] == "add":
nextNum = max(main.alias.keys())+1
main.alias[nextNum] = alias.generate_alias()
success("Generated new alias: %i" % nextNum)
main.saveConf("alias")
return
else:
incUsage("alias")
return
elif length == 3:
if spl[1] == "add":
if not spl[2].isdigit():
@ -28,6 +18,9 @@ class AliasCommand:
return
num = int(spl[2])
for i in range(num):
if len(main.alias.keys()) == 0:
nextNum = 1
else:
nextNum = max(main.alias.keys())+1
main.alias[nextNum] = alias.generate_alias()
success("Generated new alias: %i" % nextNum)
@ -38,6 +31,9 @@ class AliasCommand:
failure("Must be a number, not %s" % spl[2])
return
num = int(spl[2])
if not num in main.alias.keys():
failure("No such alias: %i" % num)
return
failed = False
for i in main.network.keys():
if num in main.network[i].aliases.keys():

View File

@ -20,12 +20,13 @@
"users": "users <channel> [<channel> ...]",
"relay": "relay <add|del|list> [<network>] [<num>]",
"network": "network <add|del|list> [<name> <address> <port> <ssl|plain> <sasl|ns|none>]",
"alias": "alias [<add>]",
"alias": "alias [<add|del>] [<num>]",
"auto": "auto <network> <relay>",
"cmd": "cmd <relay> <user> <entity> <text ...>",
"token": "token <add|del|list> [<key>] [<relay>]",
"all": "all <entity> <text ...>",
"allc": "allc <network|alias> <(network)|(alias)> <entity> <text ...>",
"admall": "admall <entity> <text ...>",
"swho": "swho <network> [<channel>]"
"swho": "swho <network> [<channel>]",
"exec": "exec <expr ...>"
}

View File

@ -38,14 +38,8 @@ class Network:
# self.start_bot(num)
return num, main.alias[num]["nick"]
def delete_relay(self, id):
del self.relays[id]
del self.aliases[id]
#del main.alias[id] - Aliases are global per num, so don't delete them!
def seppuku(self):
# Removes all bots in preperation for deletion
for i in self.relays.keys():
def killAliases(self, aliasList):
for i in aliasList:
name = self.net+str(i)
if name in main.ReactorPool.keys():
if name in main.FactoryPool.keys():
@ -56,6 +50,16 @@ class Network:
del main.ReactorPool[name]
del main.FactoryPool[name]
def delete_relay(self, id):
del self.relays[id]
del self.aliases[id]
#del main.alias[id] - Aliases are global per num, so don't delete them!
self.killAliases([id])
def seppuku(self):
# Removes all bots in preperation for deletion
self.killAliases(self.relay.keys())
def start_bot(self, num):
# a single name is given to relays in the backend
# e.g. freenode1 for the first relay on freenode network