-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
106 lines (76 loc) · 2.33 KB
/
Copy pathmain.py
File metadata and controls
106 lines (76 loc) · 2.33 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python3
import asyncio
import json
import os
import signal
import sys
import threading
import urllib3
from auth import *
from ircd import *
from game import *
from webhook import *
from dotenv import load_dotenv
print("Loading SwiftRPG...")
load_dotenv()
config = {
"NICK": os.getenv("NICK"),
"PASSWORD": os.getenv("PASSWORD"),
"IRC_SERVER": os.getenv("IRC_SERVER"),
"PORT": int(os.getenv("PORT")),
"CHANNELS": json.loads(os.getenv("CHANNELS")),
"API_HOSTNAME": os.getenv("API_HOSTNAME"),
"CERTIFICATE_PATH": os.getenv("CERTIFICATE_PATH"),
"PRIVATE_KEY_PATH": os.getenv("PRIVATE_KEY_PATH"),
"WEBHOOK_LISTEN": os.getenv("WEBHOOK_LISTEN"),
"WEBHOOK_PORT": int(os.getenv("WEBHOOK_PORT")),
"WEBHOOK_PATH": os.getenv("WEBHOOK_PATH"),
"WEBHOOK_ADDRESS": os.getenv("WEBHOOK_ADDRESS"),
"SSL_VERIFY": bool(int(os.getenv("SSL_VERIFY"))),
"API_TOKEN": os.getenv("API_TOKEN"),
"CLIENT_ID": os.getenv("CLIENT_ID"),
"DEBUG": bool(int(os.getenv("DEBUG"))),
}
if not config["SSL_VERIFY"]:
urllib3.disable_warnings()
def irc(argv, game, auth):
print("Connecting to IRC... ({})".format(argv))
irc_process = IRC(config, game, auth)
irc_process.run()
def input_thread():
input_thread = threading.Thread(target=accept_input)
input_thread.daemon = True
input_thread.start()
return input_thread
def accept_input():
print("Accepting input...")
while True:
cmd = input("$ ")
# TODO: Add commands
if cmd == "exit":
exit(0)
def game_thread():
game = Game(config)
gaming_thread = threading.Thread(target=game.start)
gaming_thread.daemon = True
gaming_thread.start()
return gaming_thread, game
def irc_thread(config, game, auth):
irc = IRC(config, game, auth)
irc_thread = threading.Thread(target=irc.start)
irc_thread.daemon = True
irc_thread.start()
return irc_thread, irc
def main(argv):
auth = Auth()
gaming_thread, game = game_thread()
ircd_thread, irc = irc_thread(config, game, auth)
webhook_server = WebhookServer(config, game, irc)
webhook_server.run()
def handler(signum, frame):
exit(0)
if __name__ == "__main__":
signal.signal(signal.SIGINT, handler)
args = sys.argv[1:]
print("Launching main() with args: {}".format(args))
main(args)