def start(self):
# Standard REST API:
# This is use to get channel_id from a channel_name,
# and the OAuth token needed for Websocket requests
self.twitch = pytwitcherapi.TwitchSession()
self.twitch_login()
self.access_token = self.twitch.token['access_token']
try:
self.channel_id
except AttributeError:
self.channel_id = self.get_channel_id()
self._write_config('channel_id', self.channel_id)
if self.first_run:
# First run was a success, we don't need to wait 45 seconds for user login
# Set first_run param to 0 (== False)
self._write_config('first_run', '0')
# Websocket / PubSub:
# This is use to get Twitch's Bits information stream
if self.verbose:
websocket.enableTrace(True)
self.twitch.ws = websocket.WebSocketApp(
self.ws_host,
on_message=self.on_message,
on_error=self.on_error,
on_close=lambda _: self.log.info("Terminating...")
)
self.cm = ConsoleMini(db_filepath=self.db_filepath, log=self.log)
self.twitch.ws.on_open = self.on_open
self.twitch.ws.run_forever()
评论列表
文章目录