monolith/legacy/commands/email.py

120 lines
4.8 KiB
Python
Raw Permalink Normal View History

2022-07-21 12:40:09 +00:00
import main
2022-09-05 06:20:30 +00:00
from yaml import dump
2022-07-21 12:40:09 +00:00
2022-07-21 12:39:41 +00:00
2021-06-06 10:31:13 +00:00
class EmailCommand:
def __init__(self, *args):
self.email(*args)
2022-09-05 06:20:30 +00:00
def email(
self, addr, authed, data, obj, spl, success, failure, info, incUsage, length
):
2021-06-06 10:31:13 +00:00
if authed:
if length == 4:
2022-07-21 12:39:43 +00:00
if spl[1] == "add":
2022-08-11 20:47:27 +00:00
if spl[2].isdigit():
num = int(spl[2])
if num not 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")
2022-09-05 06:20:30 +00:00
success(
"Successfully added email %s to alias %i"
% (spl[3], num)
)
2022-08-11 20:47:27 +00:00
return
else:
2022-09-05 06:20:30 +00:00
failure(
"Email already exists in alias %i: %s" % (num, spl[3])
)
2022-08-11 20:47:27 +00:00
return
else:
failure("Must be a number, not %s" % spl[2])
2022-07-21 12:39:43 +00:00
if spl[2] == "domain":
domain = spl[3]
if "@" in domain:
failure("Not a domain: %s" % domain)
return
2022-07-21 12:40:05 +00:00
if domain not in main.irc["_"]["domains"]:
2022-07-21 12:39:43 +00:00
main.irc["_"]["domains"].append(domain)
2022-09-05 06:20:30 +00:00
success(
"Successfully added domain %s to default config"
% domain
)
2022-07-21 12:39:43 +00:00
main.saveConf("irc")
else:
2022-09-05 06:20:30 +00:00
failure(
"Domain already exists in default config: %s"
% domain
)
2022-07-21 12:39:43 +00:00
return
2022-08-11 20:47:27 +00:00
2022-07-21 12:39:43 +00:00
elif spl[1] == "del":
if not spl[2].isdigit():
# failure("Must be a number, not %s" % spl[2])
if spl[2] == "domain":
domain = spl[3]
if domain in main.irc["_"]["domains"]:
main.irc["_"]["domains"].remove(domain)
2022-09-05 06:20:30 +00:00
success(
"Successfully removed domain %s to default config"
% domain
)
2022-07-21 12:39:43 +00:00
main.saveConf("irc")
else:
2022-09-05 06:20:30 +00:00
failure(
"Domain does not exist in default config: %s"
% domain
)
2022-07-21 12:39:43 +00:00
return
2022-07-21 12:39:41 +00:00
2021-08-25 07:47:54 +00:00
elif spl[1] == "del":
2022-07-21 12:40:05 +00:00
if num not in main.alias.keys():
2021-08-25 07:47:54 +00:00
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")
2022-09-05 06:20:30 +00:00
success(
"Successfully removed email %s from alias %i"
% (spl[3], num)
)
2021-08-25 07:47:54 +00:00
return
else:
2022-09-05 06:20:30 +00:00
failure(
"Email does not exist in alias %i: %s" % (spl[3], num)
)
2021-08-25 07:47:54 +00:00
return
2021-06-06 10:31:13 +00:00
elif length == 2:
if spl[1] == "list":
info(dump(main.alias))
return
else:
2022-07-21 12:39:43 +00:00
incUsage("email")
return
elif length == 3:
if spl[1] == "list":
if spl[2] == "domain":
2022-07-21 12:40:03 +00:00
filtered = {
2022-09-05 06:20:30 +00:00
f"{k}:{k2}": v2
for k, v in main.irc.items()
for k2, v2 in v.items()
if k2 == "domains"
2022-07-21 12:40:03 +00:00
}
2022-07-21 12:39:43 +00:00
info(dump(filtered))
return
else:
incUsage("email")
return
else:
incUsage("email")
2021-06-06 10:31:13 +00:00
return
else:
2022-07-21 12:39:43 +00:00
incUsage("email")
2021-06-06 10:31:13 +00:00
return
else:
incUsage(None)