Lights API Commands
This commit is contained in:
parent
642c3cde5d
commit
41afb81df0
@ -1,4 +1,4 @@
|
|||||||
FROM python:3.10.0a7-alpine3.13
|
FROM python:3.7.10-alpine3.12
|
||||||
|
|
||||||
WORKDIR /Praxis
|
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 channel_rewards.channelRewards_base import AbstractChannelRewards
|
||||||
|
|
||||||
|
from json import loads
|
||||||
|
from urllib.parse import urlencode
|
||||||
|
import requests
|
||||||
|
|
||||||
class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
||||||
"""
|
"""
|
||||||
this is the hydration reward.
|
this is the hydration reward.
|
||||||
@ -14,8 +18,25 @@ class ChannelReward_Hydration_v2(AbstractChannelRewards, metaclass=ABCMeta):
|
|||||||
self.isChannelRewardEnabled = True
|
self.isChannelRewardEnabled = True
|
||||||
|
|
||||||
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
def do_ChannelReward(self, source = AbstractChannelRewards.ChannelRewardsSource.default, user = "User", rewardName = "", rewardPrompt = "", userInput = "", bonusData = None):
|
||||||
|
self.dothething(user, "16", "lights hydration")
|
||||||
|
|
||||||
return None
|
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):
|
def get_help(self):
|
||||||
return self.help
|
return self.help
|
||||||
@ -12,6 +12,12 @@ services:
|
|||||||
- 6969:6969
|
- 6969:6969
|
||||||
environment:
|
environment:
|
||||||
- ISDOCKER=cat
|
- ISDOCKER=cat
|
||||||
|
standalone_lights:
|
||||||
|
image: standalone_lights
|
||||||
|
ports:
|
||||||
|
- 42069:42069
|
||||||
|
environment:
|
||||||
|
- ISDOCKER=cat
|
||||||
standalone_twitchscript:
|
standalone_twitchscript:
|
||||||
image: standalone_twitchscript
|
image: standalone_twitchscript
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
docker build --file Dockerfile_standalone_command --tag standalone_command .
|
docker build --file Dockerfile_standalone_command --tag standalone_command .
|
||||||
docker build --file Dockerfile_standalone_channelRewards --tag standalone_channelrewards .
|
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_DiscordScript --tag standalone_discordscript .
|
||||||
docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript .
|
docker build --file Dockerfile_standalone_TwitchScript --tag standalone_twitchscript .
|
||||||
docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub .
|
docker build --file Dockerfile_standalone_Twitch_Pubsub --tag standalone_twitch_pubsub .
|
||||||
@ -22,9 +22,10 @@ def is_reward(reward_name, reward_type) -> bool:
|
|||||||
#global loadedRewards
|
#global loadedRewards
|
||||||
tempType = reward_type.replace('ChannelRewardsType.', '')
|
tempType = reward_type.replace('ChannelRewardsType.', '')
|
||||||
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
||||||
|
#print(loadedRewards[realTempType])
|
||||||
|
|
||||||
for reward in loadedRewards[realTempType]:
|
for reward in loadedRewards[realTempType]:
|
||||||
print("found: ",reward,"type: ",type(reward))
|
print("found: ", reward, "type: ", type(reward))
|
||||||
if reward_name == reward:
|
if reward_name == reward:
|
||||||
print("Equal")
|
print("Equal")
|
||||||
return True
|
return True
|
||||||
@ -38,13 +39,15 @@ def is_reward(reward_name, reward_type) -> bool:
|
|||||||
|
|
||||||
def handle_reward(source, username, reward_name, reward_type, rewardPrompt, userInput, bonusData):
|
def handle_reward(source, username, reward_name, reward_type, rewardPrompt, userInput, bonusData):
|
||||||
#reward:AbstractChannelRewards = loadedRewards[reward_name]
|
#reward:AbstractChannelRewards = loadedRewards[reward_name]
|
||||||
|
try:
|
||||||
tempType = reward_type.replace('ChannelRewardsType.', '')
|
tempType = reward_type.replace('ChannelRewardsType.', '')
|
||||||
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
realTempType = AbstractChannelRewards.ChannelRewardsType.__dict__[tempType]
|
||||||
reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name]
|
reward:AbstractChannelRewards = loadedRewards[realTempType][reward_name]
|
||||||
if reward is not None:
|
if reward is not None:
|
||||||
reward_response = reward.do_ChannelReward(source, username, reward_name, rewardPrompt, userInput, bonusData)
|
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"})
|
return flask.make_response("{\"message\":\"%s\"}" % reward_response, 200, {"Content-Type": "application/json"})
|
||||||
|
except:
|
||||||
|
return "None"
|
||||||
#print("Doing a reward")
|
#print("Doing a reward")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -73,6 +73,7 @@ class Lights_Module():
|
|||||||
# This will set the group Downstairs to the Stream scene
|
# This will set the group Downstairs to the Stream scene
|
||||||
#self.bridge_.run_scene("Downstairs", "Stream")
|
#self.bridge_.run_scene("Downstairs", "Stream")
|
||||||
|
|
||||||
|
self.bridge_.run_scene("Downstairs", "Stream")
|
||||||
print("-[Lights_Module] Setup Complete")
|
print("-[Lights_Module] Setup Complete")
|
||||||
|
|
||||||
def setLight():
|
def setLight():
|
||||||
@ -87,6 +88,11 @@ class Lights_Module():
|
|||||||
def setGroups():
|
def setGroups():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def hydration(self):
|
||||||
|
self.bridge_.run_scene("Downstairs", "hydration")
|
||||||
|
#sleep(20)
|
||||||
|
#self.bridge_.run_scene("Downstairs", "Stream")
|
||||||
|
|
||||||
def raveMode(self):
|
def raveMode(self):
|
||||||
for rave in range(30):
|
for rave in range(30):
|
||||||
rgb_r = random.random()
|
rgb_r = random.random()
|
||||||
@ -202,22 +208,21 @@ def init():
|
|||||||
RGB_Lights.main()
|
RGB_Lights.main()
|
||||||
|
|
||||||
def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
||||||
returnString = ""
|
returnString = "None"
|
||||||
|
print("about to do something ......")
|
||||||
|
|
||||||
tempBool = True
|
|
||||||
if tempBool == True:
|
|
||||||
#bot.return_message("\nRGB Command Detected!")
|
#bot.return_message("\nRGB Command Detected!")
|
||||||
tempFix = command + " " + rest
|
tempFix = command + " " + rest
|
||||||
|
|
||||||
tempParsedMessage = tempFix.split(" ")
|
tempParsedMessage = tempFix.split(" ")
|
||||||
sceneCommand = False
|
sceneCommand = False
|
||||||
if (len(tempParsedMessage)) > 2:
|
if (len(tempParsedMessage)) > 2:
|
||||||
#bot.return_message("RGB Command!")
|
print("RGB Command!")
|
||||||
rgb_r = float(tempParsedMessage[1])
|
rgb_r = float(tempParsedMessage[1])
|
||||||
rgb_g = float(tempParsedMessage[2])
|
rgb_g = float(tempParsedMessage[2])
|
||||||
rgb_b = float(tempParsedMessage[3])
|
rgb_b = float(tempParsedMessage[3])
|
||||||
xy_result = RGB_Lights.rgb_to_xy(rgb_r, rgb_g, rgb_b)
|
xy_result = RGB_Lights.rgb_to_xy(rgb_r, rgb_g, rgb_b)
|
||||||
#bot.return_message("got XY")
|
print("got XY")
|
||||||
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
||||||
#bot.return_message("sent color to [Lights_Module]")
|
#bot.return_message("sent color to [Lights_Module]")
|
||||||
else:
|
else:
|
||||||
@ -236,6 +241,9 @@ def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
|||||||
elif "on" in tempParsedMessage:
|
elif "on" in tempParsedMessage:
|
||||||
sceneCommand = True
|
sceneCommand = True
|
||||||
RGB_Lights.bridge_.set_group("Downstairs", "on", True)
|
RGB_Lights.bridge_.set_group("Downstairs", "on", True)
|
||||||
|
elif "hydration" in tempParsedMessage:
|
||||||
|
sceneCommand = True
|
||||||
|
RGB_Lights.hydration()
|
||||||
elif "ravemode" in tempParsedMessage:
|
elif "ravemode" in tempParsedMessage:
|
||||||
sceneCommand = True
|
sceneCommand = True
|
||||||
RGB_Lights.raveMode()
|
RGB_Lights.raveMode()
|
||||||
@ -246,8 +254,8 @@ def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
|||||||
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
RGB_Lights.bridge_.set_group(16, "xy", xy_result)
|
||||||
#bot.return_message("sent color to [Lights_Module]")
|
#bot.return_message("sent color to [Lights_Module]")
|
||||||
|
|
||||||
#if sceneCommand == True:
|
if sceneCommand == True:
|
||||||
#bot.return_message("Scene Command!")
|
print("Scene Command!")
|
||||||
|
|
||||||
returnString = user + " changed the light's color!"
|
returnString = user + " changed the light's color!"
|
||||||
|
|
||||||
@ -256,7 +264,7 @@ def do_light_command(user="", lightGroup="all", command = "", rest = ""):
|
|||||||
|
|
||||||
|
|
||||||
@api.route('/api/v1/exec_lights', methods=['GET'])
|
@api.route('/api/v1/exec_lights', methods=['GET'])
|
||||||
def exec_command():
|
def exec_lights():
|
||||||
if 'user_name' not in request.args:
|
if 'user_name' not in request.args:
|
||||||
user_name="User"
|
user_name="User"
|
||||||
else:
|
else:
|
||||||
@ -266,9 +274,10 @@ def exec_command():
|
|||||||
if 'command' not in request.args:
|
if 'command' not in request.args:
|
||||||
return flask.make_response('{\"text\":"Argument \'scene_name\' not in request"}', 400)
|
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'])
|
return do_light_command(user_name, request.args['light_group'], request.args['command'], request.args['rest'])
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
init()
|
init()
|
||||||
|
api.run(host='0.0.0.0', port=42069)
|
||||||
#testModule.raveMode()
|
#testModule.raveMode()
|
||||||
Loading…
Reference in New Issue
Block a user