master updates #41

Manually merged
alex_orid merged 177 commits from master into github-master 2021-05-13 21:11:10 +00:00
2 changed files with 60 additions and 3 deletions
Showing only changes of commit 6c485d6d2c - Show all commits

View 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()

View File

@ -36,8 +36,8 @@ class Twitch_Pubsub():
if token is not None: print("found token")
if refresh_token is not None: print("found refresh_token")
#print(token)
#print(refresh_token)
print(token)
print(refresh_token)
self.twitch.set_user_authentication(token, self.target_scope, refresh_token)
@ -51,7 +51,7 @@ class Twitch_Pubsub():
def next(self):
user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['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_2 = self.pubsub.listen_channel_points(user_id, self.callback_channelPoints)
input('press ENTER to close...')