From fae2cacb73166335944ab2273ea91c71dcb8a685 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 5 May 2021 13:15:01 -0400 Subject: [PATCH] Fixes & New Rewards --- .../implemented/ChannelReward_SuggestPoll.py | 87 +++++++++++++++++++ .../implemented/ChannelReward_TTS.py | 87 +++++++++++++++++++ .../ChannelReward_Workout_Pushups.py | 87 +++++++++++++++++++ .../ChannelReward_Workout_Situps.py | 87 +++++++++++++++++++ .../ChannelReward_Workout_Squats.py | 87 +++++++++++++++++++ chyron_module.py | 16 ++-- standalone_twitch_pubsub.py | 4 +- standalone_webSource.py | 8 +- 8 files changed, 449 insertions(+), 14 deletions(-) create mode 100644 channel_rewards/implemented/ChannelReward_SuggestPoll.py create mode 100644 channel_rewards/implemented/ChannelReward_TTS.py create mode 100644 channel_rewards/implemented/ChannelReward_Workout_Pushups.py create mode 100644 channel_rewards/implemented/ChannelReward_Workout_Situps.py create mode 100644 channel_rewards/implemented/ChannelReward_Workout_Squats.py diff --git a/channel_rewards/implemented/ChannelReward_SuggestPoll.py b/channel_rewards/implemented/ChannelReward_SuggestPoll.py new file mode 100644 index 0000000..932f737 --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_SuggestPoll.py @@ -0,0 +1,87 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +import random + +class ChannelReward_Suggest_Poll(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the Suggest a Poll reward. + """ + ChannelRewardName = "Suggest a Poll" + + def __init__(self): + super().__init__(ChannelReward_Suggest_Poll.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a TTS 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.send_Lights_Command, args=(user, 16, "!lights hydration", "")) + # thread_.daemon = True + # self.threads.append(thread_) + # thread_.start() + if self.is_ChannelReward_enabled: + prompt_ = self.get_Phrase("wants to run a poll about,") + thread_ = threading.Thread(target=self.send_TTS, args=("",user + prompt_ + userInput)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def send_Lights_Command(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_Phrase(self, defaultRewardPrompt, + phrases = ["wants to know other people's thoughts on,", "wants to gauge the room on the topic of,"]): + + phrases.append(defaultRewardPrompt) + totalPhrases = len(phrases) - 1 + targetPhrase = phrases[random.randint(0,totalPhrases)] + return targetPhrase + + def get_help(self): + return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_TTS.py b/channel_rewards/implemented/ChannelReward_TTS.py new file mode 100644 index 0000000..0255e85 --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_TTS.py @@ -0,0 +1,87 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +import random + +class ChannelReward_TTS_Message(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the TTS Message reward. + """ + ChannelRewardName = "Send a TTS Message" + + def __init__(self): + super().__init__(ChannelReward_TTS_Message.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a TTS 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.send_Lights_Command, args=(user, 16, "!lights hydration", "")) + # thread_.daemon = True + # self.threads.append(thread_) + # thread_.start() + if self.is_ChannelReward_enabled: + prompt_ = self.get_Phrase(rewardPrompt) + thread_ = threading.Thread(target=self.send_TTS, args=(user, userInput)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def send_Lights_Command(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_Phrase(self, defaultRewardPrompt, + phrases = [""]): + + phrases.append(defaultRewardPrompt) + totalPhrases = len(phrases) - 1 + targetPhrase = phrases[random.randint(0,totalPhrases)] + return targetPhrase + + def get_help(self): + return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_Workout_Pushups.py b/channel_rewards/implemented/ChannelReward_Workout_Pushups.py new file mode 100644 index 0000000..1a8d9be --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_Workout_Pushups.py @@ -0,0 +1,87 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +import random + +class ChannelReward_Workout_Pushups(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the Do 20 push-ups reward. + """ + ChannelRewardName = "Do 20 push-ups" + + def __init__(self): + super().__init__(ChannelReward_Workout_Pushups.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a Do 20 push-ups 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.send_Lights_Command, args=(user, 16, "!lights hydration", "")) + # thread_.daemon = True + # self.threads.append(thread_) + # thread_.start() + if self.is_ChannelReward_enabled: + prompt_ = self.get_Phrase(" wants The Curious Nerd, to do 20 pushups") + thread_ = threading.Thread(target=self.send_TTS, args=("", user + prompt_)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def send_Lights_Command(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_Phrase(self, defaultRewardPrompt, + phrases = [""]): + + phrases.append(defaultRewardPrompt) + totalPhrases = len(phrases) - 1 + targetPhrase = phrases[random.randint(0,totalPhrases)] + return targetPhrase + + def get_help(self): + return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_Workout_Situps.py b/channel_rewards/implemented/ChannelReward_Workout_Situps.py new file mode 100644 index 0000000..9cc08a2 --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_Workout_Situps.py @@ -0,0 +1,87 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +import random + +class ChannelReward_Workout_Situps(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the Do 20 sit-ups reward. + """ + ChannelRewardName = "Do 20 sit-ups" + + def __init__(self): + super().__init__(ChannelReward_Workout_Situps.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a Do 20 sit-ups 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.send_Lights_Command, args=(user, 16, "!lights hydration", "")) + # thread_.daemon = True + # self.threads.append(thread_) + # thread_.start() + if self.is_ChannelReward_enabled: + prompt_ = self.get_Phrase(" wants The Curious Nerd, to do 20 sit-ups") + thread_ = threading.Thread(target=self.send_TTS, args=("", user + prompt_)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def send_Lights_Command(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_Phrase(self, defaultRewardPrompt, + phrases = [""]): + + phrases.append(defaultRewardPrompt) + totalPhrases = len(phrases) - 1 + targetPhrase = phrases[random.randint(0,totalPhrases)] + return targetPhrase + + def get_help(self): + return self.help \ No newline at end of file diff --git a/channel_rewards/implemented/ChannelReward_Workout_Squats.py b/channel_rewards/implemented/ChannelReward_Workout_Squats.py new file mode 100644 index 0000000..a814870 --- /dev/null +++ b/channel_rewards/implemented/ChannelReward_Workout_Squats.py @@ -0,0 +1,87 @@ +from abc import ABCMeta + +from channel_rewards.channelRewards_base import AbstractChannelRewards + +from json import loads +from urllib.parse import urlencode +import requests + +import threading + +import random + +class ChannelReward_Workout_Squats(AbstractChannelRewards, metaclass=ABCMeta): + """ + this is the Do 20 squats reward. + """ + ChannelRewardName = "Do 20 squats" + + def __init__(self): + super().__init__(ChannelReward_Workout_Squats.ChannelRewardName, n_args=1, ChannelRewardType=AbstractChannelRewards.ChannelRewardsType.channelPoints) + self.help = ["This is a Do 20 squats 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.send_Lights_Command, args=(user, 16, "!lights hydration", "")) + # thread_.daemon = True + # self.threads.append(thread_) + # thread_.start() + if self.is_ChannelReward_enabled: + prompt_ = self.get_Phrase(" wants The Curious Nerd, to do 20 squats") + thread_ = threading.Thread(target=self.send_TTS, args=("", user + prompt_)) + thread_.daemon = True + self.threads.append(thread_) + thread_.start() + except: + pass + + return None + + def send_Lights_Command(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_Phrase(self, defaultRewardPrompt, + phrases = [""]): + + phrases.append(defaultRewardPrompt) + totalPhrases = len(phrases) - 1 + targetPhrase = phrases[random.randint(0,totalPhrases)] + return targetPhrase + + def get_help(self): + return self.help \ No newline at end of file diff --git a/chyron_module.py b/chyron_module.py index d91e0a1..7a79364 100644 --- a/chyron_module.py +++ b/chyron_module.py @@ -16,7 +16,7 @@ class Chyron_Module(): self.addItem( "WeekDays", "► Weekdays: ", - "Daily Streams @ 12pm Noon EST") + "Daily Dev Streams starting around 12pm Noon EST") self.addItem( "FriSat", "► Friday & Saturday: ", @@ -24,18 +24,18 @@ class Chyron_Module(): self.addItem( "Commands", "► Commands: ", - "!animal, !climateclock, !discord, !page, !roll") - self.addItem( - "Website", - "► Want to read about my various projects? visit: ", - "TheCuriousNerd.com") + "!animal, !climateclock, !discord, !lights, !roll") + #self.addItem( + # "Website", + # "► Want to read about my various projects? visit: ", + # "TheCuriousNerd.com") self.addItem( "Follow", "► ", - "If you like what you see, hit that follow button to see more!") + "If you like what you see and want more, hit the follow button to see more!") self.addItem( "Discord", - "► Want to join our discord? type \" !d \" in chat to get the link or visit: ", + "► Need help with Praxis Bot or one of our other projects? (or for memes) Join our discord! Type: \" !d \" in chat to get the link or visit: ", "discord.io/thecuriousnerd") def chyron_stringUpdater(self): diff --git a/standalone_twitch_pubsub.py b/standalone_twitch_pubsub.py index 47ca812..ba1a1b2 100644 --- a/standalone_twitch_pubsub.py +++ b/standalone_twitch_pubsub.py @@ -161,8 +161,8 @@ class Twitch_Pubsub(): is_actionable = self.is_reward(rewardName, rewardType) if is_actionable: praxis_logger_obj.log("Trying to do the thing") - if self.cooldownModule.isCooldownActive("twitchpubsub") == False: - self.exec_reward(sender, rewardName, rewardType, rewardPrompt, userInput, raw_data) + #if self.cooldownModule.isCooldownActive("twitchpubsub") == False: + self.exec_reward(sender, rewardName, rewardType, rewardPrompt, userInput, raw_data) except: print("something went wrong with a reward") diff --git a/standalone_webSource.py b/standalone_webSource.py index c5f052a..13f17b4 100644 --- a/standalone_webSource.py +++ b/standalone_webSource.py @@ -35,13 +35,13 @@ def textSource_chyron(): return tempModule.getChyronFile() @api.route('/text//') -def textSource_tempText(filename): - print("trying file: ", filename) +def textSource_tempText(file_name): + print("trying file: ", file_name) tempModule = tempText_Module.tempText_Module() - return tempModule.getTempTextFile(filename) + return tempModule.getTempTextFile(file_name) @api.route('/timer//') -def textSource_timers(filename): +def textSource_timers(timer_name): #print("trying file: ", filename) #tempModule = tempText_Module.tempText_Module() #tempModule.getTempTextFile(filename)