From 61f6715b20cd244a08eabf84094b3ede9e91ca30 Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Wed, 25 Aug 2021 07:47:54 +0000 Subject: [PATCH] Start implementing email command --- commands/email.py | 70 ++++++++++++++++++++++++++--------------------- conf/help.json | 3 +- 2 files changed, 41 insertions(+), 32 deletions(-) diff --git a/commands/email.py b/commands/email.py index ab0b5a2..56388ec 100644 --- a/commands/email.py +++ b/commands/email.py @@ -8,38 +8,46 @@ class EmailCommand: def email(self, addr, authed, data, obj, spl, success, failure, info, incUsage, length): if authed: if length == 4: - if spl[1] == "add": - if not spl[2].isdigit(): - failure("Must be a number, not %s" % spl[2]) - return + if not spl[2].isdigit(): + # failure("Must be a number, not %s" % spl[2]) + if spl[2] == "domain": + 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]) - if not num in main.alias.keys(): - failure("No such alias: %i" % num) - return - if not spl[3] in main.alias[num]["emails"]: - main.alias[num]["emails"].append(spl[3]) - main.saveConf("alias") - success("Successfully added email %s to alias %i" % (spl[3], num)) - return - else: - failure("Email already exists in alias %i: %s" % (num, spl[3])) - return - elif spl[1] == "del": - if not spl[2].isdigit(): - 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 - if spl[3] in main.alias[num]["emails"]: - main.alias[num]["emails"].remove(spl[3]) - main.saveConf("alias") - success("Successfully removed email %s from alias %i" % (spl[3], num)) - return - else: - failure("Email does not exist in alias %i: %s" % (spl[3], num)) - return + if spl[1] == "add": + if not num in main.alias.keys(): + failure("No such alias: %i" % num) + return + if not spl[3] in main.alias[num]["emails"]: + main.alias[num]["emails"].append(spl[3]) + main.saveConf("alias") + success("Successfully added email %s to alias %i" % (spl[3], num)) + return + else: + failure("Email already exists in alias %i: %s" % (num, spl[3])) + return + elif spl[1] == "del": + if not num in main.alias.keys(): + failure("No such alias: %i" % num) + return + if spl[3] in main.alias[num]["emails"]: + main.alias[num]["emails"].remove(spl[3]) + main.saveConf("alias") + success("Successfully removed email %s from alias %i" % (spl[3], num)) + return + else: + failure("Email does not exist in alias %i: %s" % (spl[3], num)) + return elif length == 2: if spl[1] == "list": info(dump(main.alias)) diff --git a/conf/help.json b/conf/help.json index e36b6ec..7ea570d 100644 --- a/conf/help.json +++ b/conf/help.json @@ -33,5 +33,6 @@ "pending": "pending []", "authcheck": "authcheck []", "recheckauth": "recheckauth []", - "blacklist": "blacklist " + "blacklist": "blacklist ", + "email": "email [(domain)|] []" }