Compare commits
2 Commits
49ab554494
...
41afb81df0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41afb81df0 | ||
|
|
642c3cde5d |
@ -1,4 +1,4 @@
|
||||
FROM python:3.10.0a7-alpine3.13
|
||||
FROM python:3.7.10-alpine3.12
|
||||
|
||||
WORKDIR /Praxis
|
||||
|
||||
|
||||
11
Dockerfile_standalone_lights
Normal file
11
Dockerfile_standalone_lights
Normal file
@ -0,0 +1,11 @@
|
||||
FROM python:3.7.10-alpine3.12
|
||||
|
||||
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_lights.py"]
|
||||
@ -2,6 +2,10 @@ from abc import ABCMeta
|
||||
|
||||
from channel_rewards.channelRewards_base import AbstractChannelRewards
|
||||
|
||||
from json import loads
|
||||
from urllib.parse import urlencode
|
||||
import requests
|
||||
|
||||
class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
"""
|
||||
this is the hydration reward.
|
||||
@ -14,8 +18,25 @@ class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
||||
self.isChannelRewardEnabled = True
|
||||
|
||||
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
||||
self.dothething(user, "16", "lights hydration")
|
||||
|
||||
return None
|
||||
|
||||
def dothething(self, username, light_group, command):
|
||||
# todo need to url-escape command and rest
|
||||
params = urlencode({'user_name': username, 'light_group': light_group, 'command': command})
|
||||
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:
|
||||
pass
|
||||
# todo send to logger and other relevent services
|
||||
else:
|
||||
# todo handle failed requests
|
||||
pass
|
||||
|
||||
def get_help(self):
|
||||
return self.help
|
||||
@ -12,6 +12,12 @@ services:
|
||||
- 6969:6969
|
||||
environment:
|
||||
- ISDOCKER=cat
|
||||
standalone_lights:
|
||||
image: standalone_lights
|
||||
ports:
|
||||
- 42069:42069
|
||||
environment:
|
||||
- ISDOCKER=cat
|
||||
standalone_twitchscript:
|
||||
image: standalone_twitchscript
|
||||
environment:
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
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_DiscordScript --tag standalone_discordscript .
|
||||
docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript .
|
||||
docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub .
|
||||
@ -22,6 +22,7 @@ def is_reward(reward_name, reward_type) -> bool:
|
||||
#global loadedRewards
|
||||
tempType = reward_type.replace('ChannelRewardsType.', '')
|
||||
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
||||
#print(loadedRewards[realTempType])
|
||||
|
||||
for reward in loadedRewards[realTempType]:
|
||||
print("found: ", reward, "type: ", type(reward))
|
||||
@ -38,13 +39,15 @@ def is_reward(reward_name, reward_type) -> bool:
|
||||
|
||||
def handle_reward(source, username, reward_name, reward_type, rewardPrompt, userInput, bonusData):
|
||||
#reward:AbstractChannelRewards = loadedRewards[reward_name]
|
||||
try:
|
||||
tempType = reward_type.replace('ChannelRewardsType.', '')
|
||||
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
||||
reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name]
|
||||
if reward is not None:
|
||||
reward_response = reward.do_ChannelReward(source, username, reward_name, rewardPrompt, userInput, bonusData)
|
||||
return flask.make_response("{\"message\":\"%s\"}" % reward_response, 200, {"Content-Type": "application/json"})
|
||||
|
||||
except:
|
||||
return "None"
|
||||
#print("Doing a reward")
|
||||
|
||||
|
||||
|
||||
283
standalone_lights.py
Normal file
283
standalone_lights.py
Normal file
@ -0,0 +1,283 @@
|
||||
from time import sleep
|
||||
import phue
|
||||
from phue import Bridge
|
||||
|
||||
import random
|
||||
import utilities_script as utilities
|
||||
|
||||
import credentials
|
||||
import config
|
||||
|
||||
import flask
|
||||
from flask import request
|
||||
|
||||
api = flask.Flask(__name__)
|
||||
# enable/disable this to get web pages of crashes returned
|
||||
api.config["DEBUG"] = True
|
||||
|
||||
|
||||
class Lights_Module():
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.bridge_:Bridge = Bridge('192.168.191.146')
|
||||
|
||||
def main(self):
|
||||
print("\nStarting up [Lights_Module]...")
|
||||
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")
|
||||
|
||||
self.bridge_.run_scene("Downstairs", "Stream")
|
||||
print("-[Lights_Module] Setup Complete")
|
||||
|
||||
def setLight():
|
||||
pass
|
||||
|
||||
def setLights():
|
||||
pass
|
||||
|
||||
def setGroup():
|
||||
pass
|
||||
|
||||
def setGroups():
|
||||
pass
|
||||
|
||||
def hydration(self):
|
||||
self.bridge_.run_scene("Downstairs", "hydration")
|
||||
#sleep(20)
|
||||
#self.bridge_.run_scene("Downstairs", "Stream")
|
||||
|
||||
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 = config.colorParse_maxDigits
|
||||
print("Searching for 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
|
||||
|
||||
|
||||
RGB_Lights = Lights_Module()
|
||||
|
||||
def init():
|
||||
RGB_Lights.main()
|
||||
|
||||
def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
||||
returnString = "None"
|
||||
print("about to do something ......")
|
||||
|
||||
#bot.return_message("\nRGB Command Detected!")
|
||||
tempFix = command + " " + rest
|
||||
|
||||
tempParsedMessage = tempFix.split(" ")
|
||||
sceneCommand = False
|
||||
if (len(tempParsedMessage)) > 2:
|
||||
print("RGB Command!")
|
||||
rgb_r = float(tempParsedMessage[1])
|
||||
rgb_g = float(tempParsedMessage[2])
|
||||
rgb_b = float(tempParsedMessage[3])
|
||||
xy_result = RGB_Lights.rgb_to_xy(rgb_r, rgb_g, rgb_b)
|
||||
print("got XY")
|
||||
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
||||
#bot.return_message("sent color to [Lights_Module]")
|
||||
else:
|
||||
if "stream" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.bridge_.run_scene("Downstairs", "Stream")
|
||||
elif "normal" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.bridge_.run_scene("Downstairs", "Bright")
|
||||
elif "haxor" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.bridge_.run_scene("Downstairs", "hacker vibes")
|
||||
elif "off" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.bridge_.set_group("Downstairs", "on", False)
|
||||
elif "on" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.bridge_.set_group("Downstairs", "on", True)
|
||||
elif "hydration" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.hydration()
|
||||
elif "ravemode" in tempParsedMessage:
|
||||
sceneCommand = True
|
||||
RGB_Lights.raveMode()
|
||||
else:
|
||||
#bot.return_message("Color Command!")
|
||||
xy_result = RGB_Lights.color_string_parser(tempParsedMessage)
|
||||
#bot.return_message("got XY")
|
||||
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
||||
#bot.return_message("sent color to [Lights_Module]")
|
||||
|
||||
if sceneCommand == True:
|
||||
print("Scene Command!")
|
||||
|
||||
returnString = user + " changed the light's color!"
|
||||
|
||||
return returnString
|
||||
|
||||
|
||||
|
||||
@api.route('/api/v1/exec_lights', methods=['GET'])
|
||||
def exec_lights():
|
||||
if 'user_name' not in request.args:
|
||||
user_name="User"
|
||||
else:
|
||||
user_name=request.args['user_name']
|
||||
if 'light_group' not in request.args:
|
||||
return flask.make_response('{\"text\":"Argument \'light_group\' not in request"}', 400)
|
||||
if 'command' not in request.args:
|
||||
return flask.make_response('{\"text\":"Argument \'scene_name\' not in request"}', 400)
|
||||
|
||||
print("about to do something ......")
|
||||
return do_light_command(user_name, request.args['light_group'], request.args['command'], request.args['rest'])
|
||||
|
||||
if __name__ == "__main__":
|
||||
init()
|
||||
api.run(host='0.0.0.0', port=42069)
|
||||
#testModule.raveMode()
|
||||
Loading…
Reference in New Issue
Block a user