diff --git a/credential_templates/credential_template_twitch.json b/credential_templates/credential_template_twitch.json index c889bf2..707ce23 100644 --- a/credential_templates/credential_template_twitch.json +++ b/credential_templates/credential_template_twitch.json @@ -2,5 +2,7 @@ "username": "something", "helix": "Helix Client ID", "oauth": "token", - "v5_client": "Client ID" + "v5_client": "Client ID", + "pubsub client id": "", + "pubsub secret": "" } \ No newline at end of file diff --git a/credentials.py b/credentials.py index 2b20dba..206686d 100644 --- a/credentials.py +++ b/credentials.py @@ -14,12 +14,14 @@ class Twitch_Credential(): # Helix ID = https://dev.twitch.tv/console/apps # Oauth = https://twitchapps.com/tmi/ # V5 Client ID = https://twitchtokengenerator.com/ - def __init__(self, username, helix, oauth, v5_client): + def __init__(self, username, helix, oauth, v5_client, pubsub_client_id, pubsub_secret): # super().__init__() self.username = username self.helix = helix self.oauth = oauth self.v5_client = v5_client + self.pubsub_client_id = pubsub_client_id + self.pubsub_secret = pubsub_secret class Discord_Credential(): diff --git a/standalone_twitch_pubsub.py b/standalone_twitch_pubsub.py index c00dc9b..24fe2a6 100644 --- a/standalone_twitch_pubsub.py +++ b/standalone_twitch_pubsub.py @@ -1,15 +1,38 @@ import credentials import config -import utilities_script as utility + +import twitchAPI +from twitchAPI.pubsub import PubSub +from twitchAPI.twitch import Twitch +from twitchAPI.types import AuthScope +from pprint import pprint +from uuid import UUID + class Twitch_Pubsub(): def __init__(self): super().__init__() - self.twitchCredential: credentials.Twitch_Credential + self.credential : credentials.Twitch_Credential() + self.twitch : Twitch() + self.pubsub: PubSub() - def main(self): - pass + def setup(self): + self.twitch.authenticate_app([]) + self.twitch.set_user_authentication('my_user_auth_token', [AuthScope.WHISPERS_READ], 'my_user_auth_refresh_token') + + def start(self): + self.pubsub = PubSub(self.twitch) + self.pubsub.start() + + def next(self): + user_id = self.twitch.get_users(logins=['my_username'])['data'][0]['id'] + uuid = self.pubsub.listen_whispers(user_id, self.callback_whisper) + input('press ENTER to close...') + + def callback_whisper(self, uuid: UUID, data: dict) -> None: + print('got callback for UUID ' + str(uuid)) + pprint(data) if __name__ == "__main__": @@ -17,7 +40,9 @@ if __name__ == "__main__": credentials_manager = credentials.Credentials_Module() credentials_manager.load_credentials() - testModule.twitchCredential = credentials_manager.find_Twitch_Credential(config.credentialsNickname) - #testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname) + testModule.credential = credentials_manager.find_Twitch_Credential(config.credentialsNickname) + testModule.twitch = Twitch(testModule.credential.pubsub_client_id, testModule.credential.pubsub_secret) - testModule.main() \ No newline at end of file + + testModule.setup() + testModule.start() \ No newline at end of file