Deleted Old Stuff & Added Try Blocks
This commit is contained in:
parent
3084740238
commit
5859a56441
47
main.py
47
main.py
@ -4,8 +4,6 @@
|
|||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import twitch_script
|
|
||||||
import discord_script
|
|
||||||
import test_module
|
import test_module
|
||||||
|
|
||||||
import user_module
|
import user_module
|
||||||
@ -17,8 +15,6 @@ import credentials
|
|||||||
|
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
twitchModule_: twitch_script.Twitch_Module
|
|
||||||
discordModule_: discord_script.Discord_Module
|
|
||||||
testModule_: test_module.Test_Module
|
testModule_: test_module.Test_Module
|
||||||
userModule_: user_module.User_Module
|
userModule_: user_module.User_Module
|
||||||
|
|
||||||
@ -28,31 +24,6 @@ def main(inputArg):
|
|||||||
args = utility.get_args(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):
|
def test_module_init(dbCert, Empty):
|
||||||
print("-init [TEST Module]")
|
print("-init [TEST Module]")
|
||||||
#testModule_.dbCredential = dbCert
|
#testModule_.dbCredential = dbCert
|
||||||
@ -69,15 +40,11 @@ def thread_main():
|
|||||||
if not config.skip_splashScreen:
|
if not config.skip_splashScreen:
|
||||||
utility.splashScreen()
|
utility.splashScreen()
|
||||||
global credentials_manager
|
global credentials_manager
|
||||||
global twitchModule_
|
|
||||||
global discordModule_
|
|
||||||
global testModule_
|
global testModule_
|
||||||
global userModule_
|
global userModule_
|
||||||
|
|
||||||
credentials_manager = credentials.Credentials_Module()
|
credentials_manager = credentials.Credentials_Module()
|
||||||
|
|
||||||
twitchModule_ = twitch_script.Twitch_Module()
|
|
||||||
discordModule_ = discord_script.Discord_Module()
|
|
||||||
testModule_ = test_module.Test_Module()
|
testModule_ = test_module.Test_Module()
|
||||||
userModule_ = user_module.User_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)
|
dbCert: credentials.DB_Credential = credentials_manager.find_Credential(credentials.DB_Credential, config.credentialsNickname)
|
||||||
|
|
||||||
threads = []
|
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:
|
if config.test_module == True:
|
||||||
thread_ = threading.Thread(target=test_module_init, args=(dbCert, None))
|
thread_ = threading.Thread(target=test_module_init, args=(dbCert, None))
|
||||||
thread_.daemon = True
|
thread_.daemon = True
|
||||||
|
|||||||
@ -76,11 +76,13 @@ class Discord_Module(discord.Client):
|
|||||||
|
|
||||||
async def eval_commands(self, message: discord.Message):
|
async def eval_commands(self, message: discord.Message):
|
||||||
command, rest = utility.parse_line(message.content)
|
command, rest = utility.parse_line(message.content)
|
||||||
|
try:
|
||||||
is_actionable = await self.is_command(command)
|
is_actionable = await self.is_command(command)
|
||||||
if is_actionable:
|
if is_actionable:
|
||||||
if self.cooldownModule.isCooldownActive("discordRateLimit") == False:
|
if self.cooldownModule.isCooldownActive("discordRateLimit") == False:
|
||||||
await self.exec_command(message, command, rest)
|
await self.exec_command(message, command, rest)
|
||||||
|
except:
|
||||||
|
print("something went wrong with a command")
|
||||||
|
|
||||||
async def is_command(self, word: str) -> bool:
|
async def is_command(self, word: str) -> bool:
|
||||||
# todo need to url-escape word
|
# todo need to url-escape word
|
||||||
|
|||||||
@ -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()
|
|
||||||
@ -96,10 +96,13 @@ class Twitch_Module():
|
|||||||
print("[#" + message.channel + "](" + message.sender + ")> " + message.text)
|
print("[#" + message.channel + "](" + message.sender + ")> " + message.text)
|
||||||
command, rest = utility.parse_line(message.text)
|
command, rest = utility.parse_line(message.text)
|
||||||
|
|
||||||
is_actionable = self.is_command(command)
|
try:
|
||||||
if is_actionable:
|
is_actionable = self.is_command(command)
|
||||||
if self.cooldownModule.isCooldownActive("twitchChat") == False:
|
if is_actionable:
|
||||||
self.exec_command(message ,command, rest)
|
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):
|
def isChannel_inConfigList(self, selectedChannel, selectedList):
|
||||||
# print(channel)
|
# print(channel)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user