-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstreamer.py
More file actions
71 lines (57 loc) · 2.18 KB
/
Copy pathstreamer.py
File metadata and controls
71 lines (57 loc) · 2.18 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
import time
from rev import TranscriptApp
from twitch import TwitchApp
from oauth import OAuthApp
from config import CONFIG
from logs import Logger
from eventbus import eventbus, Events
class StreamerApp():
token = None
def __init__(self):
self.log = Logger("streamer")
if CONFIG.getboolean("streamer", "use_voice_input", fallback=True):
self.rev = TranscriptApp()
else:
self.rev = None
self.name = CONFIG.get("streamer", "name")
if CONFIG.getboolean("streamer", "send_to_twitch", fallback=True):
self.oauth = OAuthApp(CONFIG.get("streamer", "twitch_oauth_section"))
self.twitch = TwitchApp(self.name, self.name)
else:
self.oauth = None
self.twitch = None
eventbus.create_subscriber(
name="streamer",
event_types=[Events.STREAMER_LINE],
callback=self.on_streamer_line
)
def ensure_connected(self):
if self.rev and not self.rev.running:
self.rev.start()
if self.twitch and self.oauth:
if not self.twitch.running:
if self.token is None:
self.log.info("Waiting for Streamer Twitch token...")
self.token = self.oauth.get_token()
else:
self.log.info("Token received. Starting Twitch Server..")
self.twitch.start(self.token)
def shutdown(self):
if self.rev:
self.rev.shutdown()
if self.twitch and self.oauth:
self.twitch.shutdown()
self.oauth.shutdown()
def on_streamer_line(self, event):
text = event.data
# If we're sending to twitch, we don't need to call on_say since the
# message will come back through restream
if self.twitch:
self.twitch.say(text)
else:
msg = {
"author": self.name,
"text": text,
"sent": time.time()
}
eventbus.publish(Events.CHAT_MESSAGE, data=msg, source=event.source)