User-Module #17

Merged
alex_orid merged 6 commits from User-Module into master 2021-04-09 20:32:55 +00:00
9 changed files with 164 additions and 9 deletions

View File

@ -14,6 +14,7 @@ class AbstractCommand(metaclass=ABCMeta):
class CommandType(Enum):
NONE = auto()
Praxis = auto()
TWITCH = auto()
DISCORD = auto()

View File

@ -14,16 +14,17 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
command = "!lights"
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):
if bot.allow_rgbLightControl == True:
def do_command(self, bot, user_message):
tempBool = True
if tempBool == True:
LightModule = lights_module.Lights_Module()
LightModule.main()
print("\nRGB Command Detected!")
tempParsedMessage = twitch_message.text.split(" ")
print("\nParsed Command! ", twitch_message.text)
tempParsedMessage = user_message.message.split(" ")
print("\nParsed Command! ", user_message.message)
if (len(tempParsedMessage)) > 2:
print("\nRGB Command!")
rgb_r = float(tempParsedMessage[1])
@ -36,9 +37,9 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
else:
if "stream" in tempParsedMessage:
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")
elif ("haxor") in tempParsedMessage:
elif "haxor" in tempParsedMessage:
LightModule.bridge_.run_scene("Downstairs", "hacker vibes")
elif "off" in tempParsedMessage:
LightModule.bridge_.set_group("Downstairs", "on", False)
@ -53,5 +54,5 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta):
LightModule.bridge_.set_group(16, "xy", xy_result)
print("sent color")
returnMessage = "@" + twitch_message.sender + " changed the light's color!"
bot.send_message(returnMessage)
returnMessage = "@" + user_message.user + " changed the light's color!"
bot.return_message(returnMessage)

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" 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
View 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()