Merge pull request 'User-Module' (#17) from User-Module into master
Reviewed-on: #17
This commit is contained in:
commit
ee38f6288a
@ -14,6 +14,7 @@ class AbstractCommand(metaclass=ABCMeta):
|
|||||||
|
|
||||||
class CommandType(Enum):
|
class CommandType(Enum):
|
||||||
NONE = auto()
|
NONE = auto()
|
||||||
|
Praxis = auto()
|
||||||
TWITCH = auto()
|
TWITCH = auto()
|
||||||
DISCORD = auto()
|
DISCORD = auto()
|
||||||
|
|
||||||
|
|||||||
@ -14,16 +14,17 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
|||||||
command = "!lights"
|
command = "!lights"
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH)
|
super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis)
|
||||||
|
|
||||||
def do_command(self, bot, twitch_message):
|
def do_command(self, bot, user_message):
|
||||||
if bot.allow_rgbLightControl == True:
|
tempBool = True
|
||||||
|
if tempBool == True:
|
||||||
LightModule = lights_module.Lights_Module()
|
LightModule = lights_module.Lights_Module()
|
||||||
LightModule.main()
|
LightModule.main()
|
||||||
print("\nRGB Command Detected!")
|
print("\nRGB Command Detected!")
|
||||||
|
|
||||||
tempParsedMessage = twitch_message.text.split(" ")
|
tempParsedMessage = user_message.message.split(" ")
|
||||||
print("\nParsed Command! ", twitch_message.text)
|
print("\nParsed Command! ", user_message.message)
|
||||||
if (len(tempParsedMessage)) > 2:
|
if (len(tempParsedMessage)) > 2:
|
||||||
print("\nRGB Command!")
|
print("\nRGB Command!")
|
||||||
rgb_r = float(tempParsedMessage[1])
|
rgb_r = float(tempParsedMessage[1])
|
||||||
@ -36,9 +37,9 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
|||||||
else:
|
else:
|
||||||
if "stream" in tempParsedMessage:
|
if "stream" in tempParsedMessage:
|
||||||
LightModule.bridge_.run_scene("Downstairs", "Stream")
|
LightModule.bridge_.run_scene("Downstairs", "Stream")
|
||||||
elif ("normal" or "regular" or "bright" or "daylight") in tempParsedMessage:
|
elif "normal" in tempParsedMessage:
|
||||||
LightModule.bridge_.run_scene("Downstairs", "Bright")
|
LightModule.bridge_.run_scene("Downstairs", "Bright")
|
||||||
elif ("haxor") in tempParsedMessage:
|
elif "haxor" in tempParsedMessage:
|
||||||
LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
|
LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
|
||||||
elif "off" in tempParsedMessage:
|
elif "off" in tempParsedMessage:
|
||||||
LightModule.bridge_.set_group("Downstairs", "on", False)
|
LightModule.bridge_.set_group("Downstairs", "on", False)
|
||||||
@ -53,5 +54,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
|
|||||||
LightModule.bridge_.set_group(16, "xy", xy_result)
|
LightModule.bridge_.set_group(16, "xy", xy_result)
|
||||||
print("sent color")
|
print("sent color")
|
||||||
|
|
||||||
returnMessage = "@" + twitch_message.sender + " changed the light's color!"
|
returnMessage = "@" + user_message.user + " changed the light's color!"
|
||||||
bot.send_message(returnMessage)
|
bot.return_message(returnMessage)
|
||||||
57
commands/implemented/command_lights_rgb_color_twitch.py
Normal file
57
commands/implemented/command_lights_rgb_color_twitch.py
Normal 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" 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)
|
||||||
96
user_module.py
Normal file
96
user_module.py
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import config as config
|
||||||
|
import db
|
||||||
|
import tts
|
||||||
|
|
||||||
|
import credentials
|
||||||
|
|
||||||
|
import commands.loader as command_loader
|
||||||
|
from commands.command_base import AbstractCommand
|
||||||
|
|
||||||
|
from cooldowns import Cooldown_Module
|
||||||
|
|
||||||
|
class User_Module():
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.dbCredential: credentials.DB_Credential
|
||||||
|
self.commands = command_loader.load_commands_new(AbstractCommand.CommandType.Praxis)
|
||||||
|
self.MessageLog:list = []
|
||||||
|
|
||||||
|
def main(self):
|
||||||
|
print("\nWaiting on User input...")
|
||||||
|
inputLoop = True
|
||||||
|
while inputLoop:
|
||||||
|
keyboardInput = input()
|
||||||
|
message = UserMessage()
|
||||||
|
message.makeMessage(message=keyboardInput)
|
||||||
|
|
||||||
|
if "exit" in keyboardInput:
|
||||||
|
print("Quitting User Module Interface...")
|
||||||
|
inputLoop = False
|
||||||
|
break
|
||||||
|
|
||||||
|
self.parseInput(message)
|
||||||
|
|
||||||
|
def parseInput(self, message):
|
||||||
|
if self.isCommand(message) == True:
|
||||||
|
self.runCommand(message)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def isCommand(self, message):
|
||||||
|
isCommand = True
|
||||||
|
#MAKE THIS
|
||||||
|
return isCommand
|
||||||
|
|
||||||
|
def runCommand(self, message):
|
||||||
|
self.eval_commands(message)
|
||||||
|
|
||||||
|
def eval_commands(self, message):
|
||||||
|
# containsURL: bool = self.contains_url(message)
|
||||||
|
try:
|
||||||
|
#first_space_idx = message.text.index(' ')
|
||||||
|
|
||||||
|
# This fixes a error where if you send a command without arguments it fails because
|
||||||
|
# it cant find the substring.
|
||||||
|
if message.message.find(" ") != -1:
|
||||||
|
first_space_idx = message.message.index(' ')
|
||||||
|
else:
|
||||||
|
first_space_idx = -1
|
||||||
|
|
||||||
|
command_text = ' '
|
||||||
|
if first_space_idx > -1:
|
||||||
|
command_text = message.message[0:first_space_idx]
|
||||||
|
else:
|
||||||
|
command_text = message.message
|
||||||
|
|
||||||
|
command = self.commands[command_text]
|
||||||
|
if command is not None and command.command_type is AbstractCommand.CommandType.Praxis:
|
||||||
|
command.do_command(self, message)
|
||||||
|
except Exception as e:
|
||||||
|
# Undo the following for debug stuff
|
||||||
|
#print(e)
|
||||||
|
pass # we don't care
|
||||||
|
|
||||||
|
def return_message(self, returnedMessage):
|
||||||
|
print(returnedMessage)
|
||||||
|
|
||||||
|
def tts(self, message):
|
||||||
|
tts.tts(message)
|
||||||
|
|
||||||
|
class UserMessage():
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.user = "User"
|
||||||
|
self.message = ""
|
||||||
|
|
||||||
|
def makeMessage(self, user = "User", message = ""):
|
||||||
|
self.user = user
|
||||||
|
self.message = message
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
testModule = User_Module()
|
||||||
|
|
||||||
|
credentials_manager = credentials.Credentials_Module()
|
||||||
|
credentials_manager.load_credentials()
|
||||||
|
testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname)
|
||||||
|
testModule.main()
|
||||||
Loading…
Reference in New Issue
Block a user