From 5859a564415845ecba2e5832cad01c2d10b4d373 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Sat, 24 Apr 2021 01:25:32 -0400 Subject: [PATCH] Deleted Old Stuff & Added Try Blocks --- main.py | 47 -------------------------- standalone_discord_script.py | 12 ++++--- standalone_twitch_pubsub copy.py | 58 -------------------------------- standalone_twitch_script.py | 11 +++--- 4 files changed, 14 insertions(+), 114 deletions(-) delete mode 100644 standalone_twitch_pubsub copy.py diff --git a/main.py b/main.py index f4018cf..f0bb16e 100644 --- a/main.py +++ b/main.py @@ -4,8 +4,6 @@ import sys import time -import twitch_script -import discord_script import test_module import user_module @@ -17,8 +15,6 @@ import credentials import threading -twitchModule_: twitch_script.Twitch_Module -discordModule_: discord_script.Discord_Module testModule_: test_module.Test_Module userModule_: user_module.User_Module @@ -28,31 +24,6 @@ def main(inputArg): args = utility.get_args(inputArg) -def twitch_module_init(dbCert, twitchCert): - print("-init [TWITCH Module]") - twitchModule_.db_manager.setup_engine(dbCert) - twitchModule_.twitchCredential = twitchCert - - twitchModule_.tts_enabled = config.autoEnabled_TwitchChannelsTTS - twitchModule_.whitelisted_users = config.whitelisted_TwitchPowerUsers - - print("[TWITCH Module]>", "Loading Channels...") - for twitchChannel in config.autoJoin_TwitchChannels: - print("joining twitch channel:", twitchChannel) - twitchModule_.join_channel(None, twitchChannel) - -def discord_module_init(dbCert, discordCert): - print("-init [DISCORD Module]") - discordModule_.dbCredential = dbCert - discordModule_.discordCredential = discordCert - - discordModule_.tts_enabled = config.autoEnabled_DiscordChannelsTTS - - for ttsChannel in config.selected_DiscordTTSChannels: - discordModule_.selected_ttsChannels.append(int(ttsChannel)) - - discordModule_.main() - def test_module_init(dbCert, Empty): print("-init [TEST Module]") #testModule_.dbCredential = dbCert @@ -69,15 +40,11 @@ def thread_main(): if not config.skip_splashScreen: utility.splashScreen() global credentials_manager - global twitchModule_ - global discordModule_ global testModule_ global userModule_ credentials_manager = credentials.Credentials_Module() - twitchModule_ = twitch_script.Twitch_Module() - discordModule_ = discord_script.Discord_Module() testModule_ = test_module.Test_Module() userModule_ = user_module.User_Module() @@ -85,20 +52,6 @@ def thread_main(): dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, config.credentialsNickname) threads = [] - if config.twitch_module == True: - twitchCert: credentials.Twitch_Credential = credentials_manager.find_Twitch_Credential(config.credentialsNickname) - thread_ = threading.Thread(target=twitch_module_init, args=(dbCert, twitchCert)) - thread_.daemon = True - threads.append(thread_) - thread_.start() - - if config.discord_module == True: - discordCert: credentials.Discord_Credential = credentials_manager.find_Discord_Credential(config.credentialsNickname) - thread_ = threading.Thread(target=discord_module_init, args=(dbCert, discordCert)) - thread_.daemon = True - threads.append(thread_) - thread_.start() - if config.test_module == True: thread_ = threading.Thread(target=test_module_init, args=(dbCert, None)) thread_.daemon = True diff --git a/standalone_discord_script.py b/standalone_discord_script.py index c71a971..291a9b8 100644 --- a/standalone_discord_script.py +++ b/standalone_discord_script.py @@ -76,11 +76,13 @@ class Discord_Module(discord.Client): async def eval_commands(self, message: discord.Message): command, rest = utility.parse_line(message.content) - - is_actionable = await self.is_command(command) - if is_actionable: - if self.cooldownModule.isCooldownActive("discordRateLimit") == False: - await self.exec_command(message, command, rest) + try: + is_actionable = await self.is_command(command) + if is_actionable: + if self.cooldownModule.isCooldownActive("discordRateLimit") == False: + await self.exec_command(message, command, rest) + except: + print("something went wrong with a command") async def is_command(self, word: str) -> bool: # todo need to url-escape word diff --git a/standalone_twitch_pubsub copy.py b/standalone_twitch_pubsub copy.py deleted file mode 100644 index 152733c..0000000 --- a/standalone_twitch_pubsub copy.py +++ /dev/null @@ -1,58 +0,0 @@ -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("\nChannel Point Detection") - print('got callback for UUID ' + str(uuid)) - pprint(data) - -def callback_whisper(uuid: UUID, data: dict) -> None: - print("\nWhisper Detection") - 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, AuthScope.CHANNEL_MANAGE_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() \ No newline at end of file diff --git a/standalone_twitch_script.py b/standalone_twitch_script.py index 03eac64..aba70f0 100644 --- a/standalone_twitch_script.py +++ b/standalone_twitch_script.py @@ -96,10 +96,13 @@ class Twitch_Module(): print("[#" + message.channel + "](" + message.sender + ")> " + message.text) command, rest = utility.parse_line(message.text) - is_actionable = self.is_command(command) - if is_actionable: - if self.cooldownModule.isCooldownActive("twitchChat") == False: - self.exec_command(message ,command, rest) + try: + is_actionable = self.is_command(command) + if is_actionable: + if self.cooldownModule.isCooldownActive("twitchChat") == False: + self.exec_command(message ,command, rest) + except: + print("something went wrong with a command") def isChannel_inConfigList(self, selectedChannel, selectedList): # print(channel)