-
Notifications
You must be signed in to change notification settings - Fork 0
/
circa
executable file
·85 lines (73 loc) · 2.46 KB
/
circa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import argparse
import configparser
import getpass
import logging
import pathlib
import signal
import sys
from circa import Circa
circa = None
def sig(*args):
if circa:
circa.close()
logging.info("Exiting.")
print()
signal.signal(signal.SIGINT, sig)
signal.signal(signal.SIGTERM, sig)
def build_parser():
parser = argparse.ArgumentParser(prog="circa")
parser.add_argument("-s", "--server", metavar="HOST", help="Connect to HOST")
parser.add_argument("-p", "--port", default=6667,
help="Connect to port PORT (default: 6667)")
parser.add_argument("-n", "--nick", default="circa",
help="Set nick (default: circa)")
parser.add_argument("-u", "--username", default="circa",
help="Set username (default: circa)")
parser.add_argument("-r", "--realname", metavar="NAME", default="circa",
help="Set real name (ircname) (default: circa)")
parser.add_argument("-P", "--password", action="store_true",
help="Provide a password prompt")
parser.add_argument("-l", "--log", metavar="FILE", default="circa.log",
help="Log to a file (default: circa.log)")
parser.add_argument("-c", "--cmd", metavar="CHAR", default="\\",
help="Set the prefix for command characters (default: \\)")
parser.add_argument("-v", "--verbose", action="store_true",
help="Log messages more verbosely")
parser.add_argument("CONFIG", nargs="?", help="Configuration file")
return parser
def parse_args():
args = build_parser().parse_args()
conf = {
"cwd": pathlib.Path(sys.argv[0]).resolve().parent,
"server": args.server,
"port": int(args.port),
"nick": args.nick,
"username": args.username,
"realname": args.realname,
"log": args.log,
"prefix": args.cmd,
"verbose": args.verbose,
"linelimit": 5
}
if args.CONFIG:
with open(args.CONFIG) as f:
cp = configparser.ConfigParser(delimiters=("=",), allow_no_value=True)
cp.read_file(f)
conf.update(cp["server"])
conf["port"] = int(conf["port"])
conf.update(cp["bot"])
conf["channels"] = list(cp["channels"].keys())
conf["modules"] = list(cp["modules"].keys())
conf["admins"] = list(cp["admins"].keys())
conf["linelimit"] = int(conf["linelimit"])
logging.basicConfig(filename=conf["log"],
level=logging.DEBUG if conf["verbose"] else logging.INFO,
style="%", format="%(asctime)s %(levelname)s %(message)s")
if args.password and "password" not in conf:
conf["password"] = getpass.getpass()
return conf
if __name__ == "__main__":
conf = parse_args()
circa = Circa(conf)