Merge pull request 'lights-module' (#13) from lights-module into master

Reviewed-on: #13
This commit is contained in:
alex_orid 2021-04-09 17:19:55 +00:00
commit 0b697fa58c
6 changed files with 289 additions and 4 deletions

View File

@ -0,0 +1,57 @@
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 = "!lights"
def __init__(self):
super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH)
def do_command(self, bot, twitch_message):
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:
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)

View File

@ -11,7 +11,7 @@ test_module: bool = False
autoJoin_TwitchChannels = ["thecuriousnerd"] autoJoin_TwitchChannels = ["thecuriousnerd"]
whitelisted_TwitchPowerUsers = ["thecuriousnerd"] whitelisted_TwitchPowerUsers = ["thecuriousnerd"]
#Twitch Module Configs
block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels block_TwitchChannelsMessaging = [""] # Blocks the ability to send messages to twitch channels
blockAll_TwitchChatChannelsMessaging = False # 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 blockAll_TTS_URL_Twitch = True
autoEnabled_Twitch_rgbLightControl = False
#Discord Module Configs
block_DiscordChannelsMessaging = [""] # Blocks the ability to send messages to Discord channels block_DiscordChannelsMessaging = [""] # Blocks the ability to send messages to Discord channels
blockAll_DiscordChannelsMessaging = False # 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 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 blockAll_TTS_URL_Discord = True
autoEnabled_Discord_rgbLightControl = False
skip_splashScreen = False skip_splashScreen = False
skip_splashScreenClear = False skip_splashScreenClear = False

200
lights_module.py Normal file
View File

@ -0,0 +1,200 @@
from time import sleep
import phue
from phue import Bridge
import random
import utilities_script as utilities
import credentials
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....")
self.bridge_.connect()
self.bridge_.get_api()
light_list = self.bridge_.lights
group_list:list = []
groups = self.bridge_.get_group()
groupCount = 0
print("\n -Listing Lights...")
for l in light_list:
pass
#print(l.name)
print("\n -Counting Groups...")
for g in groups:
#print(g)
groupCount = int(g)
for gc in range(groupCount):
try:
#print("group n:" + str(gc))
group = self.bridge_.get_group(gc ,'name')
#print(group)
group_list.append(group)
#print(" --done adding")
except:
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
#xy_result = self.rgb_to_xy(0,0,1) #This will take an rgb value and make it xy
#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):
#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.1)
#for stuffz in self.bridge_.scenes:
#print(stuffz)
# This will set the group Downstairs to the Stream scene
#self.bridge_.run_scene("Downstairs", "Stream")
print("\n Setup Complete")
def setLight():
pass
def setLights():
pass
def setGroup():
pass
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
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]
def color_string_parser(self, message):
maxDigits = 4
print("trying to find color")
xy_color = [0, 0]
for text in message:
#print("testing word")
if "red" in text.lower():
xy_color = self.rgb_to_xy(1,0,0)
print("found: red")
if "blue" in text.lower():
print("found: blue")
xy_color = self.rgb_to_xy(0,0,1)
if "green" in text.lower():
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")
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)
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
if __name__ == "__main__":
testModule = Lights_Module()
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()
testModule.raveMode()

View File

@ -9,3 +9,4 @@ playsound
discord.py discord.py
psutil psutil
art art
phue

View File

@ -39,6 +39,8 @@ class Twitch_Module():
self.cooldownModule:Cooldown_Module = Cooldown_Module() self.cooldownModule:Cooldown_Module = Cooldown_Module()
self.cooldownModule.setupCooldown("twitchChat", 20, 32) self.cooldownModule.setupCooldown("twitchChat", 20, 32)
self.allow_rgbLightControl = config.autoEnabled_Twitch_rgbLightControl
def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str): def join_channel(self, credential: credentials.Twitch_Credential, channel_name:str):
channel_name = "#" + channel_name channel_name = "#" + channel_name
print("Connecting to Channel: " + channel_name + "...") print("Connecting to Channel: " + channel_name + "...")

View File

@ -13,14 +13,34 @@ 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))") 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 containsURL = re.search(urlMatcher, input.lower()) is not None
return containsURL return containsURL
def get_args(text: str) -> list: def get_args(text: str) -> list:
return text.split(" ") return text.split(" ")
def contains_slur(self, input: str): def does_contain_OnlyNumbers(text):
isJustNumbers = False
print("checking numbers")
try:
for x in range(10):
if str(x) in str(text):
isJustNumbers = True
else:
isJustNumbers = False
except:
pass
return isJustNumbers
def rescale_value(value, min, max):
print("trying Rescale")
returnValue = (value - min) / (max - min)
print("got ", returnValue)
return returnValue
def contains_slur(input: str):
containsSlur: bool = False containsSlur: bool = False
parsedMessage = input.split(" ") parsedMessage = input.split(" ")
for word in parsedMessage: for word in parsedMessage: