Start implementing email command

This commit is contained in:
Mark Veidemanis 2021-08-25 07:47:54 +00:00
parent 0854c6d60d
commit 61f6715b20
2 changed files with 41 additions and 32 deletions

View File

@ -8,38 +8,46 @@ class EmailCommand:
def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length):
if authed: if authed:
if length == 4: if length == 4:
if spl[1] == "add": if not spl[2].isdigit():
if not spl[2].isdigit(): # failure("Must be a number, not %s" % spl[2])
failure("Must be a number, not %s" % spl[2]) if spl[2] == "domain":
return domain = spl[3]
if "@" in domain:
failure("Not a domain: %s" % domain)
return
if not domain in main.irc["_"]["domains"]:
main.irc["_"]["domains"].append(domain)
success("Successfully added domain %s to default config" % domain)
else:
failure("Domain already exists in default config: %s" % domain)
return
else:
num = int(spl[2]) num = int(spl[2])
if not num in main.alias.keys(): if spl[1] == "add":
failure("No such alias: %i" % num) if not num in main.alias.keys():
return failure("No such alias: %i" % num)
if not spl[3] in main.alias[num]["emails"]: return
main.alias[num]["emails"].append(spl[3]) if not spl[3] in main.alias[num]["emails"]:
main.saveConf("alias") main.alias[num]["emails"].append(spl[3])
success("Successfully added email %s to alias %i" % (spl[3], num)) main.saveConf("alias")
return success("Successfully added email %s to alias %i" % (spl[3], num))
else: return
failure("Email already exists in alias %i: %s" % (num, spl[3])) else:
return failure("Email already exists in alias %i: %s" % (num, spl[3]))
elif spl[1] == "del": return
if not spl[2].isdigit(): elif spl[1] == "del":
failure("Must be a number, not %s" % spl[2]) if not num in main.alias.keys():
return failure("No such alias: %i" % num)
num = int(spl[2]) return
if not num in main.alias.keys(): if spl[3] in main.alias[num]["emails"]:
failure("No such alias: %i" % num) main.alias[num]["emails"].remove(spl[3])
return main.saveConf("alias")
if spl[3] in main.alias[num]["emails"]: success("Successfully removed email %s from alias %i" % (spl[3], num))
main.alias[num]["emails"].remove(spl[3]) return
main.saveConf("alias") else:
success("Successfully removed email %s from alias %i" % (spl[3], num)) failure("Email does not exist in alias %i: %s" % (spl[3], num))
return return
else:
failure("Email does not exist in alias %i: %s" % (spl[3], num))
return
elif length == 2: elif length == 2:
if spl[1] == "list": if spl[1] == "list":
info(dump(main.alias)) info(dump(main.alias))

View File

@ -33,5 +33,6 @@
"pending": "pending [<network>]", "pending": "pending [<network>]",
"authcheck": "authcheck [<network>]", "authcheck": "authcheck [<network>]",
"recheckauth": "recheckauth [<network>]", "recheckauth": "recheckauth [<network>]",
"blacklist": "blacklist <network> <channel>" "blacklist": "blacklist <network> <channel>",
"email": "email <add|del|list> [(domain)|<num>] [<email>]"
} }