From 381882eda9ca43acbbd81131064a6b63b17cd49f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 14:17:24 -0400 Subject: [PATCH 01/15] group & light detection --- lights_module.py | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lights_module.py diff --git a/lights_module.py b/lights_module.py new file mode 100644 index 0000000..aa53036 --- /dev/null +++ b/lights_module.py @@ -0,0 +1,54 @@ +import phue +from phue import Bridge + +import credentials +import config + +class Lights_Modules(): + def __init__(self): + super().__init__() + + def main(self): + print("Starting up Lights_Modules....") + b = Bridge('192.168.191.146') + b.connect + + b.get_api() + + light_list = b.lights + group_list:list = [] + groups = b.get_group() + groupCount = 0 + + print("\n -Listing Lights...") + for l in light_list: + print(l.name) + print("\n -Counting Groups...") + for g in groups: + print(g) + groupCount = int(g) + + + for gc in range(groupCount): + try: + #print(gc) + group = b.get_group(gc ,'name') + print(group) + #group_list.append(group) + print(" --done adding") + except: + print(" --adding failed") + + + print("\n finished doing the thing") + + +if __name__ == "__main__": + testModule = Lights_Modules() + + credentials_manager = credentials.Credentials_Module() + credentials_manager.load_credentials() + #testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname) + #testModule.discordCredential = credentials_manager.find_Discord_Credential(config.credentialsNickname) + + testModule.main() \ No newline at end of file From 1c4d5d5b014682d747ce10fd3613c237bfa455d1 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 14:38:49 -0400 Subject: [PATCH 02/15] Basic Control --- lights_module.py | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/lights_module.py b/lights_module.py index aa53036..13c8811 100644 --- a/lights_module.py +++ b/lights_module.py @@ -31,7 +31,7 @@ class Lights_Modules(): for gc in range(groupCount): try: - #print(gc) + print("group n:" + str(gc)) group = b.get_group(gc ,'name') print(group) #group_list.append(group) @@ -39,8 +39,41 @@ class Lights_Modules(): except: print(" --adding failed") + #b.set_group(18, "bri", 254) #This is max Brightness + #b.set_group(18, "on", True) #This is will turn ON + xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy + b.set_group(18, "xy", xy_result) #This will make the lights in the group turn blue - print("\n finished doing the thing") + print("\n finished doing the things") + + + + def rgb_to_xy(self, red, green, blue): + """ conversion of RGB colors to CIE1931 XY colors + Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d + Args: + red (float): a number between 0.0 and 1.0 representing red in the RGB space + green (float): a number between 0.0 and 1.0 representing green in the RGB space + blue (float): a number between 0.0 and 1.0 representing blue in the RGB space + Returns: + xy (list): x and y + """ + # gamma correction + red = pow((red + 0.055) / (1.0 + 0.055), 2.4) if red > 0.04045 else (red / 12.92) + green = pow((green + 0.055) / (1.0 + 0.055), 2.4) if green > 0.04045 else (green / 12.92) + blue = pow((blue + 0.055) / (1.0 + 0.055), 2.4) if blue > 0.04045 else (blue / 12.92) + + # convert rgb to xyz + x = red * 0.649926 + green * 0.103455 + blue * 0.197109 + y = red * 0.234327 + green * 0.743075 + blue * 0.022598 + z = green * 0.053077 + blue * 1.035763 + + # convert xyz to xy + x = x / (x + y + z) + y = y / (x + y + z) + + # TODO check color gamut if known + return [x, y] if __name__ == "__main__": From e4f185678be421ac3b04642737f35c481760de5b Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 15:19:46 -0400 Subject: [PATCH 03/15] Added Rave Function --- lights_module.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lights_module.py b/lights_module.py index 13c8811..3e78f60 100644 --- a/lights_module.py +++ b/lights_module.py @@ -1,6 +1,9 @@ +from time import sleep import phue from phue import Bridge +import random + import credentials import config @@ -42,7 +45,16 @@ class Lights_Modules(): #b.set_group(18, "bri", 254) #This is max Brightness #b.set_group(18, "on", True) #This is will turn ON xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy - b.set_group(18, "xy", xy_result) #This will make the lights in the group turn blue + b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue + + # The Following will make a rave + for rave in range(2000): + 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 + b.set_group(16, "xy", xy_result) + sleep(0.5) print("\n finished doing the things") From 114b19373e7ebb1ffe02d4b951ccf41cdad879bb Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 15:51:38 -0400 Subject: [PATCH 04/15] Added Scenes & Started Twitch Command --- commands/implemented/command_light_color.py | 24 +++++++++++++++++++++ lights_module.py | 18 ++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 commands/implemented/command_light_color.py diff --git a/commands/implemented/command_light_color.py b/commands/implemented/command_light_color.py new file mode 100644 index 0000000..49d4d93 --- /dev/null +++ b/commands/implemented/command_light_color.py @@ -0,0 +1,24 @@ +from abc import ABCMeta + +from commands.command_base import AbstractCommand + +import random + +class CommandRoll(AbstractCommand, metaclass=ABCMeta): + """ + this is the roll command. + """ + command = "!color" + + def __init__(self): + super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) + + def do_command(self, bot, twitch_message): + tempParsedMessage = twitch_message.text.split(" ") + + rgb_r = float(tempParsedMessage[1]) + rgb_g = float(tempParsedMessage[2]) + rgb_b = float(tempParsedMessage[3]) + + diceRoll = "@" + twitch_message.sender + " changed the colors!" + bot.send_message(diceRoll) \ No newline at end of file diff --git a/lights_module.py b/lights_module.py index 3e78f60..c4350fe 100644 --- a/lights_module.py +++ b/lights_module.py @@ -7,7 +7,7 @@ import random import credentials import config -class Lights_Modules(): +class Lights_Module(): def __init__(self): super().__init__() @@ -48,13 +48,19 @@ class Lights_Modules(): b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue # The Following will make a rave - for rave in range(2000): + for rave in range(20): 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 - b.set_group(16, "xy", xy_result) - sleep(0.5) + #xy_result = self.rgb_to_xy(rgb_r, rgb_g, rgb_b) #This will take an rgb value and make it xy + #b.set_group(16, "xy", xy_result) + #sleep(0.1) + + #for stuffz in b.scenes: + #print(stuffz) + + # This will set the group Downstairs to the Stream scene + #b.run_scene("Downstairs", "Stream") print("\n finished doing the things") @@ -89,7 +95,7 @@ class Lights_Modules(): if __name__ == "__main__": - testModule = Lights_Modules() + testModule = Lights_Module() credentials_manager = credentials.Credentials_Module() credentials_manager.load_credentials() From 93c0e182ed7ed965286e17dc5de9cb850e6c5e34 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 16:37:30 -0400 Subject: [PATCH 05/15] Expanded Module & Twitch RGB Command --- commands/implemented/command_light_color.py | 24 -------- .../implemented/command_light_rgb_color.py | 39 +++++++++++++ lights_module.py | 56 +++++++++++++------ utilities_script.py | 10 ++++ 4 files changed, 88 insertions(+), 41 deletions(-) delete mode 100644 commands/implemented/command_light_color.py create mode 100644 commands/implemented/command_light_rgb_color.py diff --git a/commands/implemented/command_light_color.py b/commands/implemented/command_light_color.py deleted file mode 100644 index 49d4d93..0000000 --- a/commands/implemented/command_light_color.py +++ /dev/null @@ -1,24 +0,0 @@ -from abc import ABCMeta - -from commands.command_base import AbstractCommand - -import random - -class CommandRoll(AbstractCommand, metaclass=ABCMeta): - """ - this is the roll command. - """ - command = "!color" - - def __init__(self): - super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) - - def do_command(self, bot, twitch_message): - tempParsedMessage = twitch_message.text.split(" ") - - rgb_r = float(tempParsedMessage[1]) - rgb_g = float(tempParsedMessage[2]) - rgb_b = float(tempParsedMessage[3]) - - diceRoll = "@" + twitch_message.sender + " changed the colors!" - bot.send_message(diceRoll) \ No newline at end of file diff --git a/commands/implemented/command_light_rgb_color.py b/commands/implemented/command_light_rgb_color.py new file mode 100644 index 0000000..8177eae --- /dev/null +++ b/commands/implemented/command_light_rgb_color.py @@ -0,0 +1,39 @@ +from abc import ABCMeta +import lights_module + +from commands.command_base import AbstractCommand + +import random + +import utilities_script as utilities + +class CommandRoll(AbstractCommand, metaclass=ABCMeta): + """ + this is the roll command. + """ + command = "!rgb" + + def __init__(self): + super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) + + def do_command(self, bot, twitch_message): + LightModule = lights_module.Lights_Module() + LightModule.main() + + tempParsedMessage = twitch_message.text.split(" ") + + run_lightsCommand = False + if (utilities.does_contain_OnlyNumbers(tempParsedMessage[1]) & + utilities.does_contain_OnlyNumbers(tempParsedMessage[2]) & + utilities.does_contain_OnlyNumbers(tempParsedMessage[3])) == True: + rgb_r = float(tempParsedMessage[1]) + rgb_g = float(tempParsedMessage[2]) + rgb_b = float(tempParsedMessage[3]) + xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) + LightModule.bridge_.set_group(16, "xy", xy_result) + else: + xy_result = LightModule.color_string_parser(tempParsedMessage) + LightModule.bridge_.set_group(16, "xy", xy_result) + + returnMessage = "@" + twitch_message.sender + " changed the colors!" + bot.send_message(returnMessage) \ No newline at end of file diff --git a/lights_module.py b/lights_module.py index c4350fe..f7ddea6 100644 --- a/lights_module.py +++ b/lights_module.py @@ -10,17 +10,17 @@ import config class Lights_Module(): def __init__(self): super().__init__() + self.bridge_:Bridge = Bridge('192.168.191.146') def main(self): print("Starting up Lights_Modules....") - b = Bridge('192.168.191.146') - b.connect + self.b.connect - b.get_api() + self.b.get_api() - light_list = b.lights + light_list = self.b.lights group_list:list = [] - groups = b.get_group() + groups = self.b.get_group() groupCount = 0 print("\n -Listing Lights...") @@ -35,36 +35,46 @@ class Lights_Module(): for gc in range(groupCount): try: print("group n:" + str(gc)) - group = b.get_group(gc ,'name') + group = self.b.get_group(gc ,'name') print(group) #group_list.append(group) print(" --done adding") except: print(" --adding failed") - #b.set_group(18, "bri", 254) #This is max Brightness - #b.set_group(18, "on", True) #This is will turn ON - xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy - b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue + #self.b.set_group(18, "bri", 254) #This is max Brightness + #self.b.set_group(18, "on", True) #This is will turn ON + #xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy + #self.b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue # The Following will make a rave - for rave in range(20): - rgb_r = random.random() - rgb_g = random.random() - rgb_b = random.random() + #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 - #b.set_group(16, "xy", xy_result) + #self.b.set_group(16, "xy", xy_result) #sleep(0.1) #for stuffz in b.scenes: #print(stuffz) # This will set the group Downstairs to the Stream scene - #b.run_scene("Downstairs", "Stream") + #self.b.run_scene("Downstairs", "Stream") - print("\n finished doing the things") + print("\n Setup Complete") + def setLight(): + pass + def setLights(): + pass + + def setGroup(): + pass + + def setGroups(): + pass def rgb_to_xy(self, red, green, blue): """ conversion of RGB colors to CIE1931 XY colors @@ -93,6 +103,18 @@ class Lights_Module(): # TODO check color gamut if known return [x, y] + def color_string_parser(self, message): + xy_color = 0 + for text in message: + if "red" in message.lower(): + xy_color = self.rgb_to_xy(1,0,0) + if "blue" in message.lower(): + xy_color = self.rgb_to_xy(0,0,1) + if "green" in message.lower(): + xy_color = self.rgb_to_xy(0,1,0) + + return xy_color + if __name__ == "__main__": testModule = Lights_Module() diff --git a/utilities_script.py b/utilities_script.py index 91c7380..4ce9b16 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -20,6 +20,16 @@ def contains_url(self, input: str): def get_args(text: str) -> list: return text.split(" ") +def does_contain_OnlyNumbers(self, text): + isJustNumbers = False + for x in range(10): + if str(x) in text: + isJustNumbers = True + else: + isJustNumbers = False + + return isJustNumbers + def contains_slur(self, input: str): containsSlur: bool = False parsedMessage = input.split(" ") From 0e4d2455bb4e8da6c6469c55584ce45a217f20c8 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 16:39:59 -0400 Subject: [PATCH 06/15] Fixed Typo --- lights_module.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lights_module.py b/lights_module.py index f7ddea6..ebfa7b1 100644 --- a/lights_module.py +++ b/lights_module.py @@ -14,13 +14,13 @@ class Lights_Module(): def main(self): print("Starting up Lights_Modules....") - self.b.connect + self.bridge_.connect() - self.b.get_api() + self.bridge_.get_api() - light_list = self.b.lights + light_list = self.bridge_.lights group_list:list = [] - groups = self.b.get_group() + groups = self.bridge_.get_group() groupCount = 0 print("\n -Listing Lights...") @@ -35,17 +35,17 @@ class Lights_Module(): for gc in range(groupCount): try: print("group n:" + str(gc)) - group = self.b.get_group(gc ,'name') + group = self.bridge_.get_group(gc ,'name') print(group) #group_list.append(group) print(" --done adding") except: print(" --adding failed") - #self.b.set_group(18, "bri", 254) #This is max Brightness - #self.b.set_group(18, "on", True) #This is will turn ON + #self.bridge_.set_group(18, "bri", 254) #This is max Brightness + #self.bridge_.set_group(18, "on", True) #This is will turn ON #xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy - #self.b.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue + #self.bridge_.set_group(16, "xy", xy_result) #This will make the lights in the group turn blue # The Following will make a rave #for rave in range(10): @@ -53,14 +53,14 @@ class Lights_Module(): #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.b.set_group(16, "xy", xy_result) + #self.bridge_.set_group(16, "xy", xy_result) #sleep(0.1) - #for stuffz in b.scenes: + #for stuffz in .bridge_.scenes: #print(stuffz) # This will set the group Downstairs to the Stream scene - #self.b.run_scene("Downstairs", "Stream") + #self.bridge_.run_scene("Downstairs", "Stream") print("\n Setup Complete") From 8f60e00a6d046f92c1d1b16de54126676865bf90 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 16:43:05 -0400 Subject: [PATCH 07/15] Commented out stuff --- lights_module.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lights_module.py b/lights_module.py index ebfa7b1..c8f1176 100644 --- a/lights_module.py +++ b/lights_module.py @@ -25,22 +25,24 @@ class Lights_Module(): print("\n -Listing Lights...") for l in light_list: - print(l.name) + pass + #print(l.name) print("\n -Counting Groups...") for g in groups: - print(g) + #print(g) groupCount = int(g) for gc in range(groupCount): try: - print("group n:" + str(gc)) + #print("group n:" + str(gc)) group = self.bridge_.get_group(gc ,'name') - print(group) - #group_list.append(group) - print(" --done adding") + #print(group) + group_list.append(group) + #print(" --done adding") except: - print(" --adding failed") + pass + #print(" --adding failed") #self.bridge_.set_group(18, "bri", 254) #This is max Brightness #self.bridge_.set_group(18, "on", True) #This is will turn ON @@ -56,7 +58,7 @@ class Lights_Module(): #self.bridge_.set_group(16, "xy", xy_result) #sleep(0.1) - #for stuffz in .bridge_.scenes: + #for stuffz in self.bridge_.scenes: #print(stuffz) # This will set the group Downstairs to the Stream scene From b519a507025bec8fe03e58ec352bad8b820278da Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:24:37 -0400 Subject: [PATCH 08/15] Fixed Light Command Able to use RGB Values (0 to 1) ex: !lights 1 1 1 Able to use Colors ex: !lights red --- ..._rgb_color.py => command_lights_rgb_color.py} | 16 ++++++++++------ lights_module.py | 13 +++++++++---- utilities_script.py | 14 +++++++++----- 3 files changed, 28 insertions(+), 15 deletions(-) rename commands/implemented/{command_light_rgb_color.py => command_lights_rgb_color.py} (75%) diff --git a/commands/implemented/command_light_rgb_color.py b/commands/implemented/command_lights_rgb_color.py similarity index 75% rename from commands/implemented/command_light_rgb_color.py rename to commands/implemented/command_lights_rgb_color.py index 8177eae..aac049e 100644 --- a/commands/implemented/command_light_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -11,7 +11,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): """ this is the roll command. """ - command = "!rgb" + command = "!lights" def __init__(self): super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) @@ -19,21 +19,25 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): def do_command(self, bot, twitch_message): LightModule = lights_module.Lights_Module() LightModule.main() + print("\nRGB Command Detected!") tempParsedMessage = twitch_message.text.split(" ") - - run_lightsCommand = False - if (utilities.does_contain_OnlyNumbers(tempParsedMessage[1]) & - utilities.does_contain_OnlyNumbers(tempParsedMessage[2]) & - utilities.does_contain_OnlyNumbers(tempParsedMessage[3])) == True: + print("\nParsed Command! ", twitch_message.text) + if (len(tempParsedMessage)) > 2: + print("\nRGB Command!") rgb_r = float(tempParsedMessage[1]) rgb_g = float(tempParsedMessage[2]) rgb_b = float(tempParsedMessage[3]) xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) + print("got XY") LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") else: + print("\nColor Command!") xy_result = LightModule.color_string_parser(tempParsedMessage) + print("got XY") LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") returnMessage = "@" + twitch_message.sender + " changed the colors!" bot.send_message(returnMessage) \ No newline at end of file diff --git a/lights_module.py b/lights_module.py index c8f1176..261c51a 100644 --- a/lights_module.py +++ b/lights_module.py @@ -106,13 +106,18 @@ class Lights_Module(): return [x, y] def color_string_parser(self, message): - xy_color = 0 + print("trying to find color") + xy_color = [0, 0] for text in message: - if "red" in message.lower(): + print("testing word") + if "red" in text.lower(): xy_color = self.rgb_to_xy(1,0,0) - if "blue" in message.lower(): + print("found: red") + if "blue" in text.lower(): + print("found: blue") xy_color = self.rgb_to_xy(0,0,1) - if "green" in message.lower(): + if "green" in text.lower(): + print("found: green") xy_color = self.rgb_to_xy(0,1,0) return xy_color diff --git a/utilities_script.py b/utilities_script.py index 4ce9b16..e62dc9d 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -21,14 +21,18 @@ def get_args(text: str) -> list: return text.split(" ") def does_contain_OnlyNumbers(self, text): - isJustNumbers = False + isJustNumbers = False + print("checking numbers") + try: for x in range(10): - if str(x) in text: + if str(x) in str(text): isJustNumbers = True - else: - isJustNumbers = False + else: + isJustNumbers = False + except: + pass - return isJustNumbers + return isJustNumbers def contains_slur(self, input: str): containsSlur: bool = False From 435ef1521195d0992b896175b2dea42a6a14ad84 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:29:46 -0400 Subject: [PATCH 09/15] Changed Bot Response --- commands/implemented/command_lights_rgb_color.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index aac049e..4fb3a51 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -39,5 +39,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): LightModule.bridge_.set_group(16, "xy", xy_result) print("sent color") - returnMessage = "@" + twitch_message.sender + " changed the colors!" + returnMessage = "@" + twitch_message.sender + " changed the light's color!" bot.send_message(returnMessage) \ No newline at end of file From 7f1c99167229309275435ff80bf58273c354365f Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:30:15 -0400 Subject: [PATCH 10/15] Update requirements.txt --- requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 087181f..4045979 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ gTTS playsound discord.py psutil -art \ No newline at end of file +art +phue \ No newline at end of file From 1b317282c5e8b577cc26b09ac994fa0026fe76d0 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:36:55 -0400 Subject: [PATCH 11/15] Added RGB Config Controls --- .../implemented/command_lights_rgb_color.py | 45 ++++++++++--------- config.py | 7 ++- twitch_script.py | 2 + 3 files changed, 31 insertions(+), 23 deletions(-) diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index 4fb3a51..bc5b6d4 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -17,27 +17,28 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) def do_command(self, bot, twitch_message): - LightModule = lights_module.Lights_Module() - LightModule.main() - print("\nRGB Command Detected!") + if bot.allow_rgbLightControl == True: + LightModule = lights_module.Lights_Module() + LightModule.main() + print("\nRGB Command Detected!") - tempParsedMessage = twitch_message.text.split(" ") - print("\nParsed Command! ", twitch_message.text) - if (len(tempParsedMessage)) > 2: - print("\nRGB Command!") - rgb_r = float(tempParsedMessage[1]) - rgb_g = float(tempParsedMessage[2]) - rgb_b = float(tempParsedMessage[3]) - xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) - print("got XY") - LightModule.bridge_.set_group(16, "xy", xy_result) - print("sent color") - else: - print("\nColor Command!") - xy_result = LightModule.color_string_parser(tempParsedMessage) - print("got XY") - LightModule.bridge_.set_group(16, "xy", xy_result) - print("sent color") + tempParsedMessage = twitch_message.text.split(" ") + print("\nParsed Command! ", twitch_message.text) + if (len(tempParsedMessage)) > 2: + print("\nRGB Command!") + rgb_r = float(tempParsedMessage[1]) + rgb_g = float(tempParsedMessage[2]) + rgb_b = float(tempParsedMessage[3]) + xy_result = LightModule.rgb_to_xy(rgb_r, rgb_g, rgb_b) + print("got XY") + LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") + else: + print("\nColor Command!") + xy_result = LightModule.color_string_parser(tempParsedMessage) + print("got XY") + LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") - returnMessage = "@" + twitch_message.sender + " changed the light's color!" - bot.send_message(returnMessage) \ No newline at end of file + returnMessage = "@" + twitch_message.sender + " changed the light's color!" + bot.send_message(returnMessage) \ No newline at end of file diff --git a/config.py b/config.py index bce47c4..db465fd 100644 --- a/config.py +++ b/config.py @@ -11,7 +11,7 @@ test_module: bool = False autoJoin_TwitchChannels = ["thecuriousnerd"] whitelisted_TwitchPowerUsers = ["thecuriousnerd"] - +#Twitch Module Configs block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels blockAll_TwitchChatChannelsMessaging = False # Blocks the ability to send messages to twitch channels @@ -23,7 +23,9 @@ forceAll_TwitchChatChannelsTTS = False # forceAll supersedes the blockAll bool a blockAll_TTS_URL_Twitch = True +autoEnabled_Twitch_rgbLightControl = False +#Discord Module Configs block_DiscordChannelsMessaging = [""] # Blocks the ability to send messages to Discord channels blockAll_DiscordChannelsMessaging = False # Blocks the ability to send messages to Discord channels blockAll_DiscordPrivateMessaging = False # Private Messaging not yet implemented @@ -37,6 +39,9 @@ forceAll_DiscordChatChannelsTTS = False # forceAll supersedes the blockAll bool blockAll_TTS_URL_Discord = True +autoEnabled_Discord_rgbLightControl = False + + skip_splashScreen = False skip_splashScreenClear = False diff --git a/twitch_script.py b/twitch_script.py index 9e16e6a..2c886f0 100644 --- a/twitch_script.py +++ b/twitch_script.py @@ -39,6 +39,8 @@ class Twitch_Module(): self.cooldownModule:Cooldown_Module = Cooldown_Module() self.cooldownModule.setupCooldown("twitchChat", 20, 32) + self.allow_rgbLightControl = config.autoEnabled_Twitch_rgbLightControl + def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): channel_name = "#" + channel_name print("Connecting to Channel: " + channel_name + "...") From fb9d58a231cac370d17f8d0db516ede6c52d41a6 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:44:38 -0400 Subject: [PATCH 12/15] Commented Line --- lights_module.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lights_module.py b/lights_module.py index 261c51a..c966a59 100644 --- a/lights_module.py +++ b/lights_module.py @@ -109,7 +109,7 @@ class Lights_Module(): print("trying to find color") xy_color = [0, 0] for text in message: - print("testing word") + #print("testing word") if "red" in text.lower(): xy_color = self.rgb_to_xy(1,0,0) print("found: red") From 5ab2abc24249b2bc668f3aead721ef2638ffe617 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 17:55:28 -0400 Subject: [PATCH 13/15] Added rescale function --- utilities_script.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/utilities_script.py b/utilities_script.py index e62dc9d..c21075e 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -34,6 +34,9 @@ def does_contain_OnlyNumbers(self, text): return isJustNumbers +def rescale_value(self, value, min, max): + return (value - min) / (max - min) + def contains_slur(self, input: str): containsSlur: bool = False parsedMessage = input.split(" ") From 84b36622b3521d247d0c8d8de5496cd29ad8ce4e Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 7 Apr 2021 18:22:32 -0400 Subject: [PATCH 14/15] Fixed Utilities and Value Rescaling --- lights_module.py | 27 +++++++++++++++++++++++++++ utilities_script.py | 13 ++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/lights_module.py b/lights_module.py index c966a59..e5fe489 100644 --- a/lights_module.py +++ b/lights_module.py @@ -3,6 +3,7 @@ import phue from phue import Bridge import random +import utilities_script as utilities import credentials import config @@ -106,6 +107,7 @@ class Lights_Module(): return [x, y] def color_string_parser(self, message): + maxDigits = 4 print("trying to find color") xy_color = [0, 0] for text in message: @@ -120,6 +122,31 @@ class Lights_Module(): print("found: green") xy_color = self.rgb_to_xy(0,1,0) + + if "cyan" in text.lower(): + print("found: cyan") + xy_color = self.rgb_to_xy(0,1,1) + if "aquamarine" in text.lower(): + print("found: aquamarine") + xy_color = self.rgb_to_xy( + round(utilities.rescale_value(111,0,254),maxDigits), + round(utilities.rescale_value(218,0,254),maxDigits), + round(utilities.rescale_value(146,0,254),maxDigits)) + + if "turquoise" in text.lower(): + print("found: turquoise") + xy_color = self.rgb_to_xy( + round(utilities.rescale_value(172,0,254),maxDigits), + round(utilities.rescale_value(233,0,254),maxDigits), + round(utilities.rescale_value(232,0,254),maxDigits)) + + if "orange" in text.lower(): + print("found: orange") + xy_color = self.rgb_to_xy( + 1, + round(utilities.rescale_value(126,0,254),maxDigits), + 0) + return xy_color diff --git a/utilities_script.py b/utilities_script.py index c21075e..9abf53c 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -13,14 +13,14 @@ clearScreen = lambda: os.system('cls' if os.name == 'nt' else 'clear') urlMatcher = re.compile("(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))") -def contains_url(self, input: str): +def contains_url(input: str): containsURL = re.search(urlMatcher, input.lower()) is not None return containsURL def get_args(text: str) -> list: return text.split(" ") -def does_contain_OnlyNumbers(self, text): +def does_contain_OnlyNumbers(text): isJustNumbers = False print("checking numbers") try: @@ -34,10 +34,13 @@ def does_contain_OnlyNumbers(self, text): return isJustNumbers -def rescale_value(self, value, min, max): - return (value - min) / (max - min) +def rescale_value(value, min, max): + print("trying Rescale") + returnValue = (value - min) / (max - min) + print("got ", returnValue) + return returnValue -def contains_slur(self, input: str): +def contains_slur(input: str): containsSlur: bool = False parsedMessage = input.split(" ") for word in parsedMessage: From 505860fe5963d2767985e29e0eb705e43b3dbe74 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Fri, 9 Apr 2021 13:06:51 -0400 Subject: [PATCH 15/15] More Lights --- .../implemented/command_lights_rgb_color.py | 23 +++++++--- lights_module.py | 43 ++++++++++++++++++- 2 files changed, 59 insertions(+), 7 deletions(-) diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index bc5b6d4..4d743ee 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -34,11 +34,24 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): LightModule.bridge_.set_group(16, "xy", xy_result) print("sent color") else: - print("\nColor Command!") - xy_result = LightModule.color_string_parser(tempParsedMessage) - print("got XY") - LightModule.bridge_.set_group(16, "xy", xy_result) - print("sent color") + if "stream" in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "Stream") + elif ("normal" or "regular" or "bright" or "daylight") in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "Bright") + elif ("haxor") in tempParsedMessage: + LightModule.bridge_.run_scene("Downstairs", "hacker vibes") + elif "off" in tempParsedMessage: + LightModule.bridge_.set_group("Downstairs", "on", False) + elif "on" in tempParsedMessage: + LightModule.bridge_.set_group("Downstairs", "on", True) + elif "ravemode" in tempParsedMessage: + LightModule.raveMode() + else: + print("\nColor Command!") + xy_result = LightModule.color_string_parser(tempParsedMessage) + print("got XY") + LightModule.bridge_.set_group(16, "xy", xy_result) + print("sent color") returnMessage = "@" + twitch_message.sender + " changed the light's color!" bot.send_message(returnMessage) \ No newline at end of file diff --git a/lights_module.py b/lights_module.py index e5fe489..63a366b 100644 --- a/lights_module.py +++ b/lights_module.py @@ -79,6 +79,16 @@ class Lights_Module(): def setGroups(): pass + def raveMode(self): + for rave in range(30): + 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) + sleep(0.3) + self.bridge_.run_scene("Downstairs", "Stream") + def rgb_to_xy(self, red, green, blue): """ conversion of RGB colors to CIE1931 XY colors Formulas implemented from: https://gist.github.com/popcorn245/30afa0f98eea1c2fd34d @@ -122,6 +132,13 @@ class Lights_Module(): print("found: green") xy_color = self.rgb_to_xy(0,1,0) + if "yellow" in text.lower(): + print("found: yellow") + xy_color = self.rgb_to_xy( + 0.7, + 0.64, + 0) + if "cyan" in text.lower(): print("found: cyan") @@ -132,7 +149,6 @@ class Lights_Module(): round(utilities.rescale_value(111,0,254),maxDigits), round(utilities.rescale_value(218,0,254),maxDigits), round(utilities.rescale_value(146,0,254),maxDigits)) - if "turquoise" in text.lower(): print("found: turquoise") xy_color = self.rgb_to_xy( @@ -147,6 +163,28 @@ class Lights_Module(): round(utilities.rescale_value(126,0,254),maxDigits), 0) + + if "magenta" in text.lower(): + print("found: magenta") + xy_color = self.rgb_to_xy( + 1, + 0, + 1) + + if "purple" in text.lower(): + print("found: purple") + xy_color = self.rgb_to_xy( + round(utilities.rescale_value(159,0,254),maxDigits), + round(utilities.rescale_value(32,0,254),maxDigits), + round(utilities.rescale_value(239,0,254),maxDigits)) + + if "violet" in text.lower(): + print("found: violet") + xy_color = self.rgb_to_xy( + round(utilities.rescale_value(237,0,254),maxDigits), + round(utilities.rescale_value(129,0,254),maxDigits), + round(utilities.rescale_value(237,0,254),maxDigits)) + return xy_color @@ -158,4 +196,5 @@ if __name__ == "__main__": #testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname) #testModule.discordCredential = credentials_manager.find_Discord_Credential(config.credentialsNickname) - testModule.main() \ No newline at end of file + testModule.main() + testModule.raveMode() \ No newline at end of file