-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
94 lines (73 loc) · 2.2 KB
/
main.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
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
import os
import json
import asyncio
import traceback
from bot import *
from controllers.controller import *
from controllers.minecraft_controller import *
from controllers.gba_poke_controller import *
__CREDS_FILENAME = os.path.join(os.getcwd(), "auth.json")
MAIN_MENU = """
0) Exit
1) Minecraft
2) GBA Pokemon
>>"""
MENU_CHOICES = (0, 1, 2)
async def get_controller(c: int) -> GameControllerType | None:
if c == 1:
return MinecraftController()
elif c == 2:
return GBAPokeController()
return None
def __ask_creds() -> dict | None:
if os.path.exists(__CREDS_FILENAME):
with open(__CREDS_FILENAME, "r") as fp:
j = json.load(fp)
return j
i = input("\nInsert Twitch App ID\n>>").lstrip().rstrip()
if not i:
raise ValueError("\nInvalid App ID...")
s = input("\nInsert Twitch App secret\n>>").lstrip().rstrip()
if not s:
raise ValueError("\nInvalid App secret...")
c = input("\nInsert Twitch channel name\n>>").lstrip().rstrip()
if not s:
raise ValueError("\nInvalid channel name...")
j = {"id": i, "secret": s, "channel": c}
with open(__CREDS_FILENAME, "w") as fp:
json.dump(j, fp, indent=4)
return j
async def __main() -> None:
try:
creds = __ask_creds()
if not creds:
raise ValueError("Invalid credentials")
c = 0
while True:
try:
c = int(input(MAIN_MENU).lstrip().rstrip())
if c not in MENU_CHOICES:
print("\nInvalid choice...")
continue
if c == 0:
print("Quitting...")
return
break
except KeyboardInterrupt:
break
except:
print("\nInvalid choice...")
controller = await get_controller(c)
bot = GameBotController(creds, controller=controller)
await bot.init_bot()
except:
traceback.print_exc()
print("Invalid Twitch API credentials!")
return
else:
await bot.run()
if __name__ == "__main__":
try:
asyncio.run(__main())
except:
traceback.print_exc()