diff --git a/.gitignore b/.gitignore index 0b9935e..4349db9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ tts/ __pycache__/ credentials/ -.idea/ \ No newline at end of file +.idea/ +stream_sources/chyron.txt diff --git a/commands/command_base.py b/commands/command_base.py index 064b5c5..2eb2c0f 100644 --- a/commands/command_base.py +++ b/commands/command_base.py @@ -18,10 +18,11 @@ class AbstractCommand(metaclass=ABCMeta): TWITCH = auto() DISCORD = auto() - def __init__(self, command: str, n_args: int = 0, command_type=CommandType.NONE): + def __init__(self, command: str, n_args: int = 0, command_type=CommandType.NONE, helpText:list=["No Help"]): self.command = command self.n_args = n_args self.command_type = command_type + self.help = helpText # no touch! def get_args(self, text: str) -> list: @@ -31,6 +32,10 @@ class AbstractCommand(metaclass=ABCMeta): def get_command(self) -> str: return self.command + # no touch! + def get_help(self): + return self.help + @abstractmethod def do_command(self, bot, twitch_message): pass diff --git a/commands/implemented/command_chyron.py b/commands/implemented/command_chyron.py index 8aa0240..454f013 100644 --- a/commands/implemented/command_chyron.py +++ b/commands/implemented/command_chyron.py @@ -7,14 +7,16 @@ import random import utilities_script as utilities -class CommandRoll(AbstractCommand, metaclass=ABCMeta): +class CommandChyron(AbstractCommand, metaclass=ABCMeta): """ - this is the roll command. + this is the chyron command. """ command = "chyron" def __init__(self): - super().__init__(CommandRoll.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) + super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["The chyron string can be generated and updated with this command.", + "\nExample:","chyron update \"RIGHTNOW\""] def do_command(self, bot, user_message): tempBool = True @@ -22,7 +24,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): tempParsedMessage = user_message.message.split(" ") i = len(tempParsedMessage) - if i > 1: + if i > 2: if "update" in tempParsedMessage[1]: chyron = chyron_module.Chyron_Module() if i > 2: @@ -39,4 +41,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): chyron.updateChyronFile() returnMessage = "@" + user_message.user + " updated the chyron!" - bot.return_message(returnMessage) \ No newline at end of file + bot.return_message(returnMessage) + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_help.py b/commands/implemented/command_help.py new file mode 100644 index 0000000..4b665fc --- /dev/null +++ b/commands/implemented/command_help.py @@ -0,0 +1,35 @@ +from abc import ABCMeta +import help_module + +from commands.command_base import AbstractCommand + +import random + +import utilities_script as utilities + +class CommandChyron(AbstractCommand, metaclass=ABCMeta): + """ + this is the help command. + """ + command = "help" + + def __init__(self): + super().__init__(CommandChyron.command, n_args=5, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["This is a command to learn more about other commands.", + "\nExample:","help \"COMMAND\""] + + def do_command(self, bot, user_message): + tempBool = True + if tempBool == True: + tempParsedMessage = user_message.message.split(" ") + i = len(tempParsedMessage) + + if i > 1: + targetCommand = bot.commands[tempParsedMessage[1]] + helper = help_module.Help_Module_.help_command_response(targetCommand, help_module.help_command_responseType.fancy) + + returnMessage = helper.response + bot.return_message(returnMessage) + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_lights_rgb_color.py b/commands/implemented/command_lights_rgb_color.py index 243b98a..c53cbab 100644 --- a/commands/implemented/command_lights_rgb_color.py +++ b/commands/implemented/command_lights_rgb_color.py @@ -7,14 +7,16 @@ import random import utilities_script as utilities -class CommandRoll(AbstractCommand, metaclass=ABCMeta): +class CommandLights(AbstractCommand, metaclass=ABCMeta): """ - this is the roll command. + this is the lights command. """ command = "lights" def __init__(self): - super().__init__(CommandRoll.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis) + super().__init__(CommandLights.command, n_args=3, command_type=AbstractCommand.CommandType.Praxis) + self.help = ["This command allows you to modify the lights via the Lights_Module.", + "\nExample:","lights \"SCENE\"","lights \"COLOR\"","lights \"R G B\"","lights \"1 0.5 0\""] def do_command(self, bot, user_message): tempBool = True @@ -64,4 +66,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): print("Scene Command!") returnMessage = "@" + user_message.user + " changed the light's color!" - bot.return_message(returnMessage) \ No newline at end of file + bot.return_message(returnMessage) + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_lights_rgb_color_twitch.py b/commands/implemented/command_lights_rgb_color_twitch.py index a87ea3b..51025cb 100644 --- a/commands/implemented/command_lights_rgb_color_twitch.py +++ b/commands/implemented/command_lights_rgb_color_twitch.py @@ -7,14 +7,16 @@ import random import utilities_script as utilities -class CommandRoll(AbstractCommand, metaclass=ABCMeta): +class CommandLights(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) + super().__init__(CommandLights.command, n_args=3, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["This command allows you to modify the lights via the Lights_Module.", + "\nExample:","!lights \"SCENE\"","!lights \"COLOR\"","!lights \"R G B\"","!lights \"1 0.5 0\""] def do_command(self, bot, twitch_message): @@ -64,4 +66,7 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): print("Scene Command!") returnMessage = "@" + twitch_message.sender + " changed the light's color!" - bot.send_message(returnMessage) \ No newline at end of file + bot.send_message(returnMessage) + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_restartBot_discord.py b/commands/implemented/command_restartBot_discord.py index 49e38bd..17711cb 100644 --- a/commands/implemented/command_restartBot_discord.py +++ b/commands/implemented/command_restartBot_discord.py @@ -12,6 +12,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] async def do_command(self, bot, discord_message: discord.message): @@ -21,3 +23,6 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): response = str("Bot restarting...") await bot.send_message(discord_message, response) utilities.restart_self() + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_restartBot_twitch.py b/commands/implemented/command_restartBot_twitch.py index fea1299..01dfea1 100644 --- a/commands/implemented/command_restartBot_twitch.py +++ b/commands/implemented/command_restartBot_twitch.py @@ -9,6 +9,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] def do_command(self, bot, twitch_message): args = self.get_args(twitch_message.text) @@ -16,3 +18,5 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): bot.send_message("Bot restarting...") utilities.restart_self() + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_roll_discord.py b/commands/implemented/command_roll_discord.py index 47f4c69..17d8f59 100644 --- a/commands/implemented/command_roll_discord.py +++ b/commands/implemented/command_roll_discord.py @@ -18,6 +18,8 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] async def do_command(self, bot, discord_message: discord.Message): print("!roll Detected") @@ -173,3 +175,6 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): print(diceRoll) return diceRoll + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_roll_twitch.py b/commands/implemented/command_roll_twitch.py index 7f1549d..46c7256 100644 --- a/commands/implemented/command_roll_twitch.py +++ b/commands/implemented/command_roll_twitch.py @@ -12,6 +12,8 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandRoll.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] def do_command(self, bot, twitch_message): print("!roll Detected") @@ -166,3 +168,6 @@ class CommandRoll(AbstractCommand, metaclass=ABCMeta): print(diceRoll) return diceRoll + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_shutdownBot_discord.py b/commands/implemented/command_shutdownBot_discord.py index 588850f..6f9296e 100644 --- a/commands/implemented/command_shutdownBot_discord.py +++ b/commands/implemented/command_shutdownBot_discord.py @@ -12,6 +12,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.DISCORD) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] async def do_command(self, bot, discord_message: discord.message): @@ -21,3 +23,6 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): response = str("Bot shutting down...") await bot.send_message(discord_message, response) utilities.hard_shutdown() + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_shutdownBot_twitch.py b/commands/implemented/command_shutdownBot_twitch.py index 1cdcb4c..a8f39e8 100644 --- a/commands/implemented/command_shutdownBot_twitch.py +++ b/commands/implemented/command_shutdownBot_twitch.py @@ -9,6 +9,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=0, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] def do_command(self, bot, twitch_message): args = self.get_args(twitch_message.text) @@ -16,3 +18,5 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): bot.send_message("Bot shutting down...") utilities.hard_shutdown() + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_test_twitch.py b/commands/implemented/command_test_twitch.py index 1432e14..d35f8f8 100644 --- a/commands/implemented/command_test_twitch.py +++ b/commands/implemented/command_test_twitch.py @@ -11,7 +11,12 @@ class CommandTest(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTest.command, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] def do_command(self, bot, twitch_message): print("!test Detected") bot.send_message("testing acknowledged") + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_tts_discord.py b/commands/implemented/command_tts_discord.py index 9a359b2..974101f 100644 --- a/commands/implemented/command_tts_discord.py +++ b/commands/implemented/command_tts_discord.py @@ -10,6 +10,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=1, command_type=AbstractCommand.CommandType.DISCORD) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] async def do_command(self, bot, discord_message: discord.message): args = self.get_args(discord_message.content) @@ -28,3 +30,6 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): response = str("tts deactivated on %s" % discord_message.guild.name) await bot.send_message(discord_message, response) bot.tts_enabled = False + + def get_help(self): + return self.help \ No newline at end of file diff --git a/commands/implemented/command_tts_twitch.py b/commands/implemented/command_tts_twitch.py index 133d851..67229eb 100644 --- a/commands/implemented/command_tts_twitch.py +++ b/commands/implemented/command_tts_twitch.py @@ -9,6 +9,8 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): def __init__(self): super().__init__(CommandTTS.command, n_args=1, command_type=AbstractCommand.CommandType.TWITCH) + self.help = ["MISSING HELP ENTRY", + "\nExample:","command \"PARAM\""] def do_command(self, bot, twitch_message): args = self.get_args(twitch_message.text) @@ -20,3 +22,6 @@ class CommandTTS(AbstractCommand, metaclass=ABCMeta): if twitch_message.sender.lower() == twitch_message.channel: bot.send_message("tts deactivated on #%s" % twitch_message.channel) bot.tts_enabled = False + + def get_help(self): + return self.help \ No newline at end of file diff --git a/help_module.py b/help_module.py new file mode 100644 index 0000000..cb8747d --- /dev/null +++ b/help_module.py @@ -0,0 +1,73 @@ +from commands.command_base import AbstractCommand +from enum import Enum +import config as config +import db + +import commands.loader as command_loader + +import credentials + +class Help_Module(): + def __init__(self): + super().__init__() + #self.dbCredential: credentials.DB_Credential + + def main(self): + print("[Help Module]> help test") + + def help_command_response(self, command:AbstractCommand, responseType): + response = help_command_response() + response.setup(command, responseType) + response.makeResponse() + return response + +class help_command_responseType(Enum): + plain = 1 # One line response + fancy = 2 # Fancy formatted response + +class help_command_response(): + def __init__(self): + super().__init__() + self.command = None + self.commandName = "" + self.helpText = "" + self.response = "" + self.responseType = help_command_responseType.plain + self.blockDecor = "\n================================================================\n" + + def setup(self, command, responseType): + self.command = command + self.commandName = command.command + self.responseType = responseType + + def makeResponse(self): + if self.responseType == help_command_responseType.plain: + self.response_plain() + elif self.responseType == help_command_responseType.fancy: + self.response_fancy() + + def response_plain(self): + tempHelpText = "" + for line in self.command.help: + tempHelpText = tempHelpText + line + " " + self.response = "Command: " + self.commandName + " : " + self.helpText + return self.response + + def response_fancy(self): + tempHelpText = "" + for line in self.command.help: + tempHelpText = tempHelpText + line + "\n" + self.response = self.blockDecor + "Command: " + self.commandName + self.blockDecor + tempHelpText + self.blockDecor + return self.response + + + +Help_Module_ = Help_Module() + +if __name__ == "__main__": + testModule = Help_Module() + + #credentials_manager = credentials.Credentials_Module() + #credentials_manager.load_credentials() + #testModule.dbCredential = credentials_manager.find_DB_Credential(config.credentialsNickname) + testModule.main() \ No newline at end of file diff --git a/praxis-main.bat b/praxis-main.bat new file mode 100644 index 0000000..26ec40f --- /dev/null +++ b/praxis-main.bat @@ -0,0 +1,2 @@ +cd "c:\praxis" +python "c:/Praxis/main.py" \ No newline at end of file diff --git a/praxis-user.bat b/praxis-user.bat new file mode 100644 index 0000000..3ada4bb --- /dev/null +++ b/praxis-user.bat @@ -0,0 +1,2 @@ +cd "c:\praxis" +python "c:\praxis\user_module.py" \ No newline at end of file