-
Notifications
You must be signed in to change notification settings - Fork 0
/
cowbot.py
executable file
·43 lines (37 loc) · 1.3 KB
/
cowbot.py
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
import configparser
import sys
from cowbot.bot import Bot
from cowbot.game import Game
def main():
config_file = "config.cfg"
config = configparser.ConfigParser()
try:
config.read_file(open(config_file, "r"))
except FileNotFoundError as e:
print(f"Configuration file '{config_file}' does not exist")
sys.exit(1)
try:
cfg = config['config']
except KeyError as e:
print(f"Configuration section '[{e.args[0]}]' not defined in {config_file}")
sys.exit(1)
try:
Game.speed = cfg.getint('speed')
except KeyError as e:
print(f"Configuration parameter '{e.args[0]}' not defined in {config_file}. Usually this should be set to 1")
sys.exit(1)
except ValueError as e:
print(f"Configuration parameter 'speed' must be a number")
sys.exit(1)
try:
bot = Bot(cfg['channel'], cfg['nickname'], cfg['realname'], cfg['server'], cfg.getint('port'), cfg['password'], cfg['admin']) #type: ignore
except KeyError as e:
print(f"Configuration parameter '{e.args[0]}' not defined in {config_file}")
sys.exit(1)
except ValueError as e:
print(f"Configuration parameter 'port' must be a number")
sys.exit(1)
bot.debug_start()
bot.start()
if __name__ == "__main__":
main()