working whispers
This commit is contained in:
parent
0602758bcb
commit
6c485d6d2c
57
standalone_twitch_pubsub copy.py
Normal file
57
standalone_twitch_pubsub copy.py
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
from twitchAPI.pubsub import PubSub
|
||||||
|
from twitchAPI.twitch import Twitch
|
||||||
|
from twitchAPI.types import AuthScope, AuthType
|
||||||
|
from twitchAPI.oauth import UserAuthenticator
|
||||||
|
from pprint import pprint
|
||||||
|
from uuid import UUID
|
||||||
|
|
||||||
|
import config
|
||||||
|
import commands.command_base
|
||||||
|
import credentials
|
||||||
|
|
||||||
|
credentials_manager = credentials.Credentials_Module()
|
||||||
|
credentials_manager.load_credentials()
|
||||||
|
twitchCredential = credentials_manager.find_Twitch_Credential(config.credentialsNickname)
|
||||||
|
|
||||||
|
def callback_channelPoints(self, uuid: UUID, data: dict) -> None:
|
||||||
|
print("Channel Point Redemption")
|
||||||
|
print('got callback for UUID ' + str(uuid))
|
||||||
|
pprint(data)
|
||||||
|
|
||||||
|
def callback_whisper(uuid: UUID, data: dict) -> None:
|
||||||
|
print('got callback for UUID ' + str(uuid))
|
||||||
|
pprint(data)
|
||||||
|
|
||||||
|
# setting up Authentication and getting your user id
|
||||||
|
twitch = Twitch(twitchCredential.pubsub_client_id, twitchCredential.pubsub_secret)
|
||||||
|
twitch.authenticate_app([])
|
||||||
|
# you can get your user auth token and user auth refresh token following the example in twitchAPI.oauth
|
||||||
|
|
||||||
|
target_scope = [AuthScope.WHISPERS_READ, AuthScope.CHANNEL_READ_REDEMPTIONS]
|
||||||
|
auth = UserAuthenticator(twitch, target_scope, force_verify=True)
|
||||||
|
token, refresh_token = auth.authenticate()
|
||||||
|
if token is not None: print("found token")
|
||||||
|
if refresh_token is not None: print("found refresh_token")
|
||||||
|
#print(token)
|
||||||
|
#print(refresh_token)
|
||||||
|
twitch.set_user_authentication(token, target_scope, refresh_token)
|
||||||
|
|
||||||
|
|
||||||
|
#twitch.set_user_authentication(twitchCredential.pubsub_AccessToken, target_scope, twitchCredential.pubsub_RefreshToken)
|
||||||
|
user_id = twitch.get_users(logins=['thecuriousnerd'])['data'][0]['id']
|
||||||
|
|
||||||
|
# starting up PubSub
|
||||||
|
pubsub = PubSub(twitch)
|
||||||
|
|
||||||
|
# you can either start listening before or after you started pubsub.
|
||||||
|
pubsub.ping_frequency = 30
|
||||||
|
pubsub.start()
|
||||||
|
|
||||||
|
#uuid1 = pubsub.listen_whispers(user_id, callback_whisper)
|
||||||
|
uuid2 = pubsub.listen_channel_points(user_id, callback_channelPoints)
|
||||||
|
|
||||||
|
input('press ENTER to close...')
|
||||||
|
# you do not need to unlisten to topics before stopping but you can listen and unlisten at any moment you want
|
||||||
|
#pubsub.unlisten(uuid1)
|
||||||
|
pubsub.unlisten(uuid2)
|
||||||
|
pubsub.stop()
|
||||||
@ -36,8 +36,8 @@ class Twitch_Pubsub():
|
|||||||
|
|
||||||
if token is not None: print("found token")
|
if token is not None: print("found token")
|
||||||
if refresh_token is not None: print("found refresh_token")
|
if refresh_token is not None: print("found refresh_token")
|
||||||
#print(token)
|
print(token)
|
||||||
#print(refresh_token)
|
print(refresh_token)
|
||||||
|
|
||||||
self.twitch.set_user_authentication(token, self.target_scope, refresh_token)
|
self.twitch.set_user_authentication(token, self.target_scope, refresh_token)
|
||||||
|
|
||||||
@ -51,7 +51,7 @@ class Twitch_Pubsub():
|
|||||||
def next(self):
|
def next(self):
|
||||||
user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id']
|
user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id']
|
||||||
if user_id is not None: print("found user_id")
|
if user_id is not None: print("found user_id")
|
||||||
#print(user_id)
|
print(user_id)
|
||||||
self.uuid_1 = self.pubsub.listen_whispers(user_id, self.callback_whisper)
|
self.uuid_1 = self.pubsub.listen_whispers(user_id, self.callback_whisper)
|
||||||
self.uuid_2 = self.pubsub.listen_channel_points(user_id, self.callback_channelPoints)
|
self.uuid_2 = self.pubsub.listen_channel_points(user_id, self.callback_channelPoints)
|
||||||
input('press ENTER to close...')
|
input('press ENTER to close...')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user