From 95a3189b36c1b57df41fe85c53c4a61606fdcb36 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 28 Apr 2021 15:01:24 -0400 Subject: [PATCH 1/5] initial commit --- Dockerfile_standalone_command | 2 +- Dockerfile_standalone_tts_core | 11 ++++ .../implemented/ChannelReward_Hydration.py | 21 +++++- .../implemented/ChannelReward_RubiksCube.py | 44 +++++++++++++ chyron_module.py | 2 +- commands/implemented/Command_lights_v2.py | 21 +++++- config.py | 4 ++ docker-compose.yaml | 8 +++ makedockerimages.bat | 1 + standalone_lights.py | 17 ++++- standalone_tts_core.py | 52 +++++++++++++++ standalone_tts_speaker.py | 64 +++++++++++++++++++ 12 files changed, 239 insertions(+), 8 deletions(-) create mode 100644 Dockerfile_standalone_tts_core create mode 100644 channel_rewards/implemented/ChannelReward_RubiksCube.py create mode 100644 standalone_tts_core.py create mode 100644 standalone_tts_speaker.py diff --git a/Dockerfile_standalone_command b/Dockerfile_standalone_command index 2d131c3..a35a33b 100644 --- a/Dockerfile_standalone_command +++ b/Dockerfile_standalone_command @@ -8,4 +8,4 @@ RUN pip3 install -r requirements_sa_command.txt COPY . . -CMD [ "python3", "standalone_command.py"] \ No newline at end of file +CMD [ "python3", "standalone_tts_core.py"] \ No newline at end of file diff --git a/Dockerfile_standalone_tts_core b/Dockerfile_standalone_tts_core new file mode 100644 index 0000000..2d131c3 --- /dev/null +++ b/Dockerfile_standalone_tts_core @@ -0,0 +1,11 @@ +FROM python:3.10.0a7-alpine3.13 + +WORKDIR /Praxis + +COPY requirements_sa_command.txt requirements_sa_command.txt +RUN apk add --update gcc libc-dev linux-headers && rm -rf /var/cache/apk/* +RUN pip3 install -r requirements_sa_command.txt + +COPY . . + +CMD [ "python3", "standalone_command.py"] \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_Hydration.py b/channel_rewards/implemented/ChannelReward_Hydration.py index 974a0e4..409620d 100644 --- a/channel_rewards/implemented/ChannelReward_Hydration.py +++ b/channel_rewards/implemented/ChannelReward_Hydration.py @@ -6,14 +6,14 @@ from json import loads from urllib.parse import urlencode import requests -class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta): +class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): """ this is the hydration reward. """ ChannelRewardName = "Hydrate" def __init__(self): - super().__init__(ChannelReward_Hydration_v2.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + super().__init__(ChannelReward_Hydration.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) self.help = ["This is a hydration channel point reward."] self.isChannelRewardEnabled = True @@ -21,6 +21,7 @@ class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta): #print("sending:",user, 16, "!lights hydration") self.dothething(user, 16, "!lights hydration", "") + self.send_TTS(user, rewardPrompt) return None def dothething(self, username, light_group, command, rest): @@ -40,5 +41,21 @@ class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta): # todo handle failed requests pass + def send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + def get_help(self): return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_RubiksCube.py b/channel_rewards/implemented/ChannelReward_RubiksCube.py new file mode 100644 index 0000000..11b397e --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_RubiksCube.py @@ -0,0 +1,44 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the hydration reward. + """ + ChannelRewardName = "Solve a Rubiks Cube" + + def __init__(self): + super().__init__(ChannelReward_RubiksCube.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a rubiks cube reward."] + self.isChannelRewardEnabled = True + + def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): + + #print("sending:",user, 16, "!lights hydration") + self.dothething(user, 16, "!lights rubikscube", "") + return None + + def dothething(self, username, light_group, command, rest): + # todo need to url-escape command and rest + params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) + #standalone_lights + url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + + def get_help(self): + return self.help \ No newline at end of file diff --git a/chyron_module.py b/chyron_module.py index 1eed58a..d91e0a1 100644 --- a/chyron_module.py +++ b/chyron_module.py @@ -24,7 +24,7 @@ class Chyron_Module(): self.addItem( "Commands", "► Commands: ", - "!animal, !climateclock, !discord, !lights, !page, !roll") + "!animal, !climateclock, !discord, !page, !roll") self.addItem( "Website", "► Want to read about my various projects? visit: ", diff --git a/commands/implemented/Command_lights_v2.py b/commands/implemented/Command_lights_v2.py index d5173f4..1aff57a 100644 --- a/commands/implemented/Command_lights_v2.py +++ b/commands/implemented/Command_lights_v2.py @@ -6,6 +6,13 @@ from json import loads from urllib.parse import urlencode import requests +import config + +import os +import praxis_logging +praxis_logger_obj = praxis_logging.praxis_logger() +praxis_logger_obj.init(os.path.basename(__file__)) +praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__)) class Command_lights_v2(AbstractCommand, metaclass=ABCMeta): """ @@ -21,9 +28,19 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta): def do_command(self, source = AbstractCommand.CommandSource.default, user = "User", command = "", rest = "", bonusData = None): returnString = "" - print("\n Command>: " + command + rest) + praxis_logger_obj.log("\n Command>: " + command + rest) + isTwitch = False - returnString = self.dothething(user, 16, command, rest) + if source is not None and source == AbstractCommand.CommandSource.Twitch: + for user_ in config.allowedCommandsList_TwitchPowerUsers: + if user_.lower() == user.lower(): + praxis_logger_obj.log(user_) + praxis_logger_obj.log(user) + returnString = self.dothething(user, 16, command, rest) + isTwitch = True + + if isTwitch == False: + returnString = self.dothething(user, 16, command, rest) return returnString diff --git a/config.py b/config.py index ac98bb8..e0562d9 100644 --- a/config.py +++ b/config.py @@ -80,6 +80,10 @@ dbStrategy = DBStrategy.SQLite #TTS Configs + +is_tts_Speaker_Enabled = False +is_tts_URL_Blocked = True + class Speaker(Enum): GOOGLE_TEXT_TO_SPEECH = 1 STREAMLABS_API = 2 diff --git a/docker-compose.yaml b/docker-compose.yaml index 73c3fe5..b99d496 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -24,6 +24,14 @@ services: - 42069:42069 environment: - ISDOCKER=cat + standalone_tts_core: + image: standalone_tts_core + volumes: + - "./:/Praxis/" + ports: + - 60809:60809 + environment: + - ISDOCKER=cat standalone_twitchscript: image: standalone_twitchscript volumes: diff --git a/makedockerimages.bat b/makedockerimages.bat index fc288bc..bc89705 100644 --- a/makedockerimages.bat +++ b/makedockerimages.bat @@ -1,6 +1,7 @@ docker build --file Dockerfile_standalone_command --tag standalone_command . docker build --file Dockerfile_standalone_channelRewards --tag standalone_channelrewards . docker build --file Dockerfile_standalone_lights --tag standalone_lights . +docker build --file Dockerfile_standalone_tts_core --tag standalone_tts_core . docker build --file Dockerfile_standalone_DiscordScript --tag standalone_discordscript . docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript . docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub . \ No newline at end of file diff --git a/standalone_lights.py b/standalone_lights.py index cca6f73..f237f8f 100644 --- a/standalone_lights.py +++ b/standalone_lights.py @@ -94,10 +94,20 @@ class Lights_Module(): def setGroups(): pass + def rubiksCube(self): + for rave in range(10): + rgb_r = random.random() + rgb_g = random.random() + rgb_b = random.random() + xy_result = self.rgb_to_xy(rgb_r, rgb_g, rgb_b) #This will take an rgb value and make it xy + self.bridge_.set_group(16, "xy", xy_result, transitiontime=0.2) + sleep(0.25) + self.bridge_.run_scene("Downstairs", "Stream") + def hydration(self): self.bridge_.run_scene("Downstairs", "hydration") - #sleep(20) - #self.bridge_.run_scene("Downstairs", "Stream") + sleep(20) + self.bridge_.run_scene("Downstairs", "Stream") def raveMode(self): for rave in range(30): @@ -250,6 +260,9 @@ def do_lights_command(user="", lightGroup="all", command = "", rest = ""): elif "on" in tempParsedMessage: sceneCommand = True RGB_Lights.bridge_.set_group("Downstairs", "on", True) + elif "rubikscube" in tempParsedMessage: + sceneCommand = True + RGB_Lights.rubiksCube() elif "hydration" in tempParsedMessage: sceneCommand = True RGB_Lights.hydration() diff --git a/standalone_tts_core.py b/standalone_tts_core.py new file mode 100644 index 0000000..19e0210 --- /dev/null +++ b/standalone_tts_core.py @@ -0,0 +1,52 @@ +import flask +from flask import request + +from json import loads +from urllib.parse import urlencode + +import requests + +import os +import praxis_logging +praxis_logger_obj = praxis_logging.praxis_logger() +praxis_logger_obj.init(os.path.basename(__file__)) +praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__)) + +api = flask.Flask(__name__) +# enable/disable this to get web pages of crashes returned +api.config["DEBUG"] = True + +def init(): + praxis_logger_obj.log("init stuff") + +def send_text(tts_sender, tts_text): + + #Play Audio File + params = urlencode({'tts_sender': tts_sender, 'tts_text': tts_text}) + + url = "http://localhost:93986/api/v1/tts/speech?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + pass + else: + # todo handle failed requests + pass + + return flask.make_response('', 200) + +@api.route('/api/v1/tts/send_text', methods=['GET']) +def tts_send_text(): + if 'tts_sender' not in request.args: + tts_sender = "" + if 'tts_text' not in request.args: + return flask.make_response('{\"text\":"Argument \'tts_text\' not in request"}', 400) + + return send_text(request.args['tts_sender'], request.args['tts_text']) + +if __name__ == '__main__': + init() + api.run(host='0.0.0.0', port=60809) \ No newline at end of file diff --git a/standalone_tts_speaker.py b/standalone_tts_speaker.py new file mode 100644 index 0000000..9907f1c --- /dev/null +++ b/standalone_tts_speaker.py @@ -0,0 +1,64 @@ +import flask +from flask import request + +import tts + +import config +import utilities_script as utility + +import os +import praxis_logging +praxis_logger_obj = praxis_logging.praxis_logger() +praxis_logger_obj.init(os.path.basename(__file__)) +praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__)) + +api = flask.Flask(__name__) +# enable/disable this to get web pages of crashes returned +api.config["DEBUG"] = True + +def init(): + praxis_logger_obj.log("init stuff") + +def isTTS_URL_Check(message): + isNotBlocked = True + is_ttsEnabled = config.is_tts_Speaker_Enabled + is_tts_URL_Allowed = not config.is_tts_URL_Blocked + has_URL = False + if utility.contains_url(message): + has_URL = True + + if is_tts_URL_Allowed: + if has_URL: + has_URL = False + if has_URL: + isNotBlocked = False + if not is_ttsEnabled: + isNotBlocked = False + + return isNotBlocked + +def try_TTS(tts_sender, tts_text): + text_to_say: str = "%s says, %s" % (tts_sender, tts_text) + + if tts_sender is None: + text_to_say = tts_text + + if isTTS_URL_Check(tts_text): + if not utility.contains_slur(tts_sender): + if not utility.contains_slur(text_to_say): + tts.tts(text_to_say) + + return flask.make_response('', 200) + +@api.route('/api/v1/tts/speech', methods=['GET']) +def tts_speech(): + if 'tts_sender' not in request.args: + tts_sender = "" + if 'tts_text' not in request.args: + return flask.make_response('{\"text\":"Argument \'tts_text\' not in request"}', 400) + + return try_TTS(request.args['tts_text']) + +if __name__ == '__main__': + init() + api.run(host='0.0.0.0', port=93986) \ No newline at end of file From 2ba271c4a3b3de6dad06625b6ddef71ca0ff8860 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 28 Apr 2021 16:32:08 -0400 Subject: [PATCH 2/5] typo --- Dockerfile_standalone_command | 2 +- Dockerfile_standalone_tts_core | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile_standalone_command b/Dockerfile_standalone_command index a35a33b..2d131c3 100644 --- a/Dockerfile_standalone_command +++ b/Dockerfile_standalone_command @@ -8,4 +8,4 @@ RUN pip3 install -r requirements_sa_command.txt COPY . . -CMD [ "python3", "standalone_tts_core.py"] \ No newline at end of file +CMD [ "python3", "standalone_command.py"] \ No newline at end of file diff --git a/Dockerfile_standalone_tts_core b/Dockerfile_standalone_tts_core index 2d131c3..a35a33b 100644 --- a/Dockerfile_standalone_tts_core +++ b/Dockerfile_standalone_tts_core @@ -8,4 +8,4 @@ RUN pip3 install -r requirements_sa_command.txt COPY . . -CMD [ "python3", "standalone_command.py"] \ No newline at end of file +CMD [ "python3", "standalone_tts_core.py"] \ No newline at end of file From 56416acf775e4de5b4562a856b3c976a8e64062c Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 28 Apr 2021 22:45:55 -0400 Subject: [PATCH 3/5] Fixes --- .../implemented/ChannelReward_Hydration.py | 19 +++++++++++++++++-- .../implemented/ChannelReward_RubiksCube.py | 16 ++++++++++++++++ commands/implemented/Command_lights_v2.py | 2 +- standalone_lights.py | 2 +- standalone_tts_core.py | 18 ++++++++++-------- standalone_tts_speaker.py | 16 ++++++++++------ 6 files changed, 55 insertions(+), 18 deletions(-) diff --git a/channel_rewards/implemented/ChannelReward_Hydration.py b/channel_rewards/implemented/ChannelReward_Hydration.py index 409620d..c7d20ab 100644 --- a/channel_rewards/implemented/ChannelReward_Hydration.py +++ b/channel_rewards/implemented/ChannelReward_Hydration.py @@ -6,6 +6,8 @@ from json import loads from urllib.parse import urlencode import requests +import threading + class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): """ this is the hydration reward. @@ -16,12 +18,25 @@ class ChannelReward_Hydration(AbstractChannelRewards, metaclass=ABCMeta): super().__init__(ChannelReward_Hydration.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) self.help = ["This is a hydration channel point reward."] self.isChannelRewardEnabled = True + self.threads = [] def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): #print("sending:",user, 16, "!lights hydration") - self.dothething(user, 16, "!lights hydration", "") - self.send_TTS(user, rewardPrompt) + try: + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.send_TTS, args=(user, rewardPrompt)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + return None def dothething(self, username, light_group, command, rest): diff --git a/channel_rewards/implemented/ChannelReward_RubiksCube.py b/channel_rewards/implemented/ChannelReward_RubiksCube.py index 11b397e..b7ca673 100644 --- a/channel_rewards/implemented/ChannelReward_RubiksCube.py +++ b/channel_rewards/implemented/ChannelReward_RubiksCube.py @@ -40,5 +40,21 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): # todo handle failed requests pass + def send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + def get_help(self): return self.help \ No newline at end of file diff --git a/commands/implemented/Command_lights_v2.py b/commands/implemented/Command_lights_v2.py index 1aff57a..78bb382 100644 --- a/commands/implemented/Command_lights_v2.py +++ b/commands/implemented/Command_lights_v2.py @@ -37,7 +37,7 @@ class Command_lights_v2(AbstractCommand, metaclass=ABCMeta): praxis_logger_obj.log(user_) praxis_logger_obj.log(user) returnString = self.dothething(user, 16, command, rest) - isTwitch = True + isTwitch = True if isTwitch == False: returnString = self.dothething(user, 16, command, rest) diff --git a/standalone_lights.py b/standalone_lights.py index f237f8f..dc47ab6 100644 --- a/standalone_lights.py +++ b/standalone_lights.py @@ -106,7 +106,7 @@ class Lights_Module(): def hydration(self): self.bridge_.run_scene("Downstairs", "hydration") - sleep(20) + sleep(4) self.bridge_.run_scene("Downstairs", "Stream") def raveMode(self): diff --git a/standalone_tts_core.py b/standalone_tts_core.py index 19e0210..7a051bf 100644 --- a/standalone_tts_core.py +++ b/standalone_tts_core.py @@ -21,21 +21,22 @@ def init(): def send_text(tts_sender, tts_text): - #Play Audio File + #Play Text params = urlencode({'tts_sender': tts_sender, 'tts_text': tts_text}) - url = "http://localhost:93986/api/v1/tts/speech?%s" % params + url = "http://192.168.191.208:40085/api/v1/tts/speech?%s" % params resp = requests.get(url) if resp.status_code == 200: print("Got the following message: %s" % resp.text) data = loads(resp.text) - msg = data['message'] - if msg is not None: - pass - else: + #msg = data['message'] + #if msg is not None: + #pass + #else: # todo handle failed requests - pass + #pass + #return None return flask.make_response('', 200) @api.route('/api/v1/tts/send_text', methods=['GET']) @@ -48,5 +49,6 @@ def tts_send_text(): return send_text(request.args['tts_sender'], request.args['tts_text']) if __name__ == '__main__': - init() + #send_text("","Blah Blah Blah") + #init() api.run(host='0.0.0.0', port=60809) \ No newline at end of file diff --git a/standalone_tts_speaker.py b/standalone_tts_speaker.py index 9907f1c..c7c1103 100644 --- a/standalone_tts_speaker.py +++ b/standalone_tts_speaker.py @@ -35,18 +35,20 @@ def isTTS_URL_Check(message): if not is_ttsEnabled: isNotBlocked = False - return isNotBlocked + return not isNotBlocked def try_TTS(tts_sender, tts_text): text_to_say: str = "%s says, %s" % (tts_sender, tts_text) - if tts_sender is None: + #tts.tts(str(text_to_say)) + #tts.tts(str(tts_text)) + if tts_sender == "": text_to_say = tts_text if isTTS_URL_Check(tts_text): if not utility.contains_slur(tts_sender): if not utility.contains_slur(text_to_say): - tts.tts(text_to_say) + tts.tts(str(text_to_say)) return flask.make_response('', 200) @@ -54,11 +56,13 @@ def try_TTS(tts_sender, tts_text): def tts_speech(): if 'tts_sender' not in request.args: tts_sender = "" + else: + tts_sender = request.args['tts_sender'] if 'tts_text' not in request.args: return flask.make_response('{\"text\":"Argument \'tts_text\' not in request"}', 400) - return try_TTS(request.args['tts_text']) + return try_TTS(tts_sender, request.args['tts_text']) if __name__ == '__main__': - init() - api.run(host='0.0.0.0', port=93986) \ No newline at end of file + #init() + api.run(host='0.0.0.0', port=40085) \ No newline at end of file From fa376abad6d2297339f845082477505acc6d7968 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 28 Apr 2021 22:49:44 -0400 Subject: [PATCH 4/5] Update ChannelReward_RubiksCube.py --- .../implemented/ChannelReward_RubiksCube.py | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/channel_rewards/implemented/ChannelReward_RubiksCube.py b/channel_rewards/implemented/ChannelReward_RubiksCube.py index b7ca673..17ab4f9 100644 --- a/channel_rewards/implemented/ChannelReward_RubiksCube.py +++ b/channel_rewards/implemented/ChannelReward_RubiksCube.py @@ -6,6 +6,8 @@ from json import loads from urllib.parse import urlencode import requests +import threading + class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): """ this is the hydration reward. @@ -16,11 +18,26 @@ class ChannelReward_RubiksCube(AbstractChannelRewards, metaclass=ABCMeta): super().__init__(ChannelReward_RubiksCube.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) self.help = ["This is a rubiks cube reward."] self.isChannelRewardEnabled = True + self.threads = [] def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): - #print("sending:",user, 16, "!lights hydration") - self.dothething(user, 16, "!lights rubikscube", "") + #self.dothething(user, 16, "!lights rubikscube", "") + + try: + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights rubikscube", "")) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.send_TTS, args=(user, rewardPrompt)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + return None def dothething(self, username, light_group, command, rest): From 0c12cffc530846de0aad3a8a9a6d08583d4198c6 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 29 Apr 2021 11:36:10 -0400 Subject: [PATCH 5/5] extra --- .../implemented/ChannelReward_twitchBits.py | 76 +++++++++++++++++++ .../implemented/ChannelReward_twitchSubs.py | 76 +++++++++++++++++++ standalone_tts_speaker.py | 2 +- 3 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 channel_rewards/implemented/ChannelReward_twitchBits.py create mode 100644 channel_rewards/implemented/ChannelReward_twitchSubs.py diff --git a/channel_rewards/implemented/ChannelReward_twitchBits.py b/channel_rewards/implemented/ChannelReward_twitchBits.py new file mode 100644 index 0000000..ca85a4b --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_twitchBits.py @@ -0,0 +1,76 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +class ChannelReward_TwitchBits(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the hydration reward. + """ + ChannelRewardName = "TwitchBits" + + def __init__(self): + super().__init__(ChannelReward_TwitchBits.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.twitch_bits) + self.help = ["This is a hydration channel point reward."] + self.isChannelRewardEnabled = True + self.threads = [] + + def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): + + #print("sending:",user, 16, "!lights hydration") + try: + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.send_TTS, args=(user, rewardPrompt)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def dothething(self, username, light_group, command, rest): + # todo need to url-escape command and rest + params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) + #standalone_lights + url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + + def send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + + def get_help(self): + return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_twitchSubs.py b/channel_rewards/implemented/ChannelReward_twitchSubs.py new file mode 100644 index 0000000..a1dcbb9 --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_twitchSubs.py @@ -0,0 +1,76 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +class ChannelReward_TwitchSubs(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the TwitchSubs reward. + """ + ChannelRewardName = "TwitchSub" + + def __init__(self): + super().__init__(ChannelReward_TwitchSubs.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.twitch_subs) + self.help = ["This is a hydration channel point reward."] + self.isChannelRewardEnabled = True + self.threads = [] + + def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None): + + #print("sending:",user, 16, "!lights hydration") + try: + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.dothething, args=(user, 16, "!lights hydration", "")) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + if self.is_ChannelReward_enabled: + thread_ = threading.Thread(target=self.send_TTS, args=(user, rewardPrompt)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def dothething(self, username, light_group, command, rest): + # todo need to url-escape command and rest + params = urlencode({'user_name': username, 'light_group': light_group, 'command': command, 'rest':rest}) + #standalone_lights + url = "http://standalone_lights:42069/api/v1/exec_lights?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + + def send_TTS(self, username, message): + params = urlencode({'tts_sender': username, 'tts_text': message}) + #standalone_tts_core + url = "http://standalone_tts_core:60809/api/v1/tts/send_text?%s" % params + resp = requests.get(url) + if resp.status_code == 200: + print("Got the following message: %s" % resp.text) + data = loads(resp.text) + msg = data['message'] + if msg is not None: + return msg + # todo send to logger and other relevent services + else: + # todo handle failed requests + pass + + def get_help(self): + return self.help \ No newline at end of file diff --git a/standalone_tts_speaker.py b/standalone_tts_speaker.py index c7c1103..5458671 100644 --- a/standalone_tts_speaker.py +++ b/standalone_tts_speaker.py @@ -14,7 +14,7 @@ praxis_logger_obj.log("\n -Starting Logs: " + os.path.basename(__file__)) api = flask.Flask(__name__) # enable/disable this to get web pages of crashes returned -api.config["DEBUG"] = True +api.config["DEBUG"] = False def init(): praxis_logger_obj.log("init stuff")