-
Notifications
You must be signed in to change notification settings - Fork 0
/
twitch-main.py
84 lines (73 loc) · 2.05 KB
/
twitch-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
import time
from scrap.util import read_config, wait_till_done, ScrapException, UserInput
from comm.serialcomm import SerialComm
from scrap.scrapinterface import ScrapInterface
from twitch.irc import IRC
conf_dict = read_config("conf.txt")
twitch_dict = read_config("conf-twitch.txt")
# create ScrapInterface
scrap = ScrapInterface(conf_dict)
armIRC = IRC(twitch_dict)
# attempt connection
if not armIRC.connect():
raise ValueError("could not connect to stream")
# for now, enter x and y coordinate to go to
# start user input thread
userInput = UserInput()
userInput.start()
while True:
# wait a little
time.sleep(0.2)
parse_inputs = []
twitch_inputs = armIRC.receiveMessages()
#print twitch_inputs
if isinstance(twitch_inputs, list):
for twitch_dict in twitch_inputs:
if twitch_dict != None:
parse_inputs.append(twitch_dict)
# read message; if None, received nothing
user_inp = userInput.returnMessage()
if user_inp == None:
pass
else:
if user_inp.lower().startswith("exit"):
break
parse_inputs.append(user_inp)
for parse_inp in parse_inputs:
try:
doneYet = False
isFromTwitch = False
# determine if twitch message
if isinstance(parse_inp,dict):
parse_inp = parse_inp['message']
isFromTwitch = True
inp = parse_inp.strip()
# do this if NOT from twitch
if inp.lower() == 'r':
wait_till_done(scrap.reset())
doneYet = True
if not doneYet:
comm,coords = inp.split()
coords = coords.strip().split(",")
if len(coords) < 2:
raise ValueError("use a comma to seperate coords")
# do this if NOT from twitch
if not isFromTwitch:
if comm == 's':
wait_till_done(scrap.set_coords(coords))
elif comm == 'sp':
wait_till_done(scrap.set_coords(coords,passive=True))
# do this if from twitch
else:
if comm == 's':
wait_till_done(scrap.set_coords(coords,passive=True))
elif comm == 'r':
wait_till_done(scrap.reset())
except ValueError,e:
print str(e)
except ScrapException,e:
print str(e)
else:
print 'done!'
scrap.stop()
time.sleep(0.25)