From 5c4d34f5961e404dfa73382ceae5f4298bf873c0 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Tue, 13 Apr 2021 18:22:16 -0400 Subject: [PATCH 01/11] Create Dockerfile --- Dockerfile | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..be856a2 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.8-buster + +WORKDIR /Praxis + +COPY requirements.txt requirements.txt +RUN pip3 install -r requirements.txt + +COPY . . + +CMD [ "python3", "main.py"] \ No newline at end of file From 46de27aca858ecaa183c248d2502616e6ed61ae9 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Wed, 14 Apr 2021 02:45:37 -0400 Subject: [PATCH 02/11] updated readme --- Dockerfile | 2 +- README.md | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index be856a2..08421bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,4 @@ RUN pip3 install -r requirements.txt COPY . . -CMD [ "python3", "main.py"] \ No newline at end of file +#CMD [ "python3", "main.py"] #Uncomment to start with the Docker Container \ No newline at end of file diff --git a/README.md b/README.md index 17afa01..ea0f62d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,18 @@ A chatbot to help with live stream production and effects. ___ +# Docker: + +## Docker Info: + +Uncomment the following line in the **Dockerfile** to have **main.py** start with the Docker Container + +`#CMD [ "python3", "main.py"]` + +To start the bot with **User_Module** activated use this. + +`docker exec -ti praxis python3 main.py` + # Credentials: ## Credentials Setup: From cfd0b84872f0e0cd580d67956ad02cf85bce05d2 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 17:03:55 -0400 Subject: [PATCH 03/11] Docker Detection --- Dockerfile | 2 +- main.py | 11 +++++++---- user_module.py | 5 +++++ utilities_script.py | 6 ++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 08421bf..3f7084b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,4 +7,4 @@ RUN pip3 install -r requirements.txt COPY . . -#CMD [ "python3", "main.py"] #Uncomment to start with the Docker Container \ No newline at end of file +CMD [ "python3", "main.py"] #Uncomment to start with the Docker Container \ No newline at end of file diff --git a/main.py b/main.py index f9a47c4..e22f2e3 100644 --- a/main.py +++ b/main.py @@ -100,16 +100,19 @@ def thread_main(): thread_.start() if config.user_module == True: - thread_ = threading.Thread(target=user_module_init, args=(dbCert, None)) - threads.append(thread_) - thread_.start() + if utility.isRunningInDocker() == False: + config.user_module = False + thread_ = threading.Thread(target=user_module_init, args=(dbCert, None)) + threads.append(thread_) + thread_.start() print("---Post Thread Creation Test---") for t in threads: t.join() print("---Point of no return---") - input() + if utility.isRunningInDocker() == False: + input() diff --git a/user_module.py b/user_module.py index 7891130..3e7becc 100644 --- a/user_module.py +++ b/user_module.py @@ -9,6 +9,8 @@ from commands.command_base import AbstractCommand from cooldowns import Cooldown_Module +import utilities_script as utility + class User_Module(): def __init__(self): super().__init__() @@ -19,6 +21,9 @@ class User_Module(): def main(self): print("\nWaiting on User input...\n") inputLoop = True + if utility.isRunningInDocker() == False: + inputLoop = False + print("\nNo User's Input Allowed") while inputLoop: keyboardInput = input() message = UserMessage() diff --git a/utilities_script.py b/utilities_script.py index fa77b76..6bcf362 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -65,6 +65,12 @@ def contains_slur(input: str): print("<{ slur detected! }> ") return containsSlur +def isRunningInDocker(): + isD = os.getenv('ISDOCKER') + if isD is None: + return False + return isD == "cat" + def hard_shutdown(): current_system_pid = os.getpid() From b1c810e525cc0a0278d50c2b17e2c538c55bb2d6 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 17:28:13 -0400 Subject: [PATCH 04/11] fixed indentation --- utilities_script.py | 86 ++++++++++++++++++++++----------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/utilities_script.py b/utilities_script.py index 6bcf362..fdf5a81 100644 --- a/utilities_script.py +++ b/utilities_script.py @@ -14,11 +14,11 @@ clearScreen = lambda: os.system('cls' if os.name == 'nt' else 'clear') urlMatcher = re.compile("(https?:(/{1,3}|[a-z0-9%])|[a-z0-9.-]+[.](com|net|org|edu|gov|mil|aero|asia|biz|cat|coop|info|int|jobs|mobi|museum|name|post|pro|tel|travel|xxx|ac|ad|ae|af|ag|ai|al|am|an|ao|aq|ar|as|at|au|aw|ax|az|ba|bb|bd|be|bf|bg|bh|bi|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|cr|cs|cu|cv|cx|cy|cz|dd|de|dj|dk|dm|do|dz|ec|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gg|gh|gi|gl|gm|gn|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|im|in|io|iq|ir|is|it|je|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|me|mg|mh|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|mv|mw|mx|my|mz|na|nc|ne|nf|ng|ni|nl|no|np|nr|nu|nz|om|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|ps|pt|pw|py|qa|re|ro|rs|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|Ja|sk|sl|sm|sn|so|sr|ss|st|su|sv|sx|sy|sz|tc|td|tf|tg|th|tj|tk|tl|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw))") def contains_url(input: str): - containsURL = re.search(urlMatcher, input.lower()) is not None - return containsURL + containsURL = re.search(urlMatcher, input.lower()) is not None + return containsURL def get_args(text: str) -> list: - return text.split(" ") + return text.split(" ") def does_contain_OnlyNumbers(text): isJustNumbers = False @@ -51,19 +51,19 @@ def get_dir(selected_dir): return dir def contains_slur(input: str): - containsSlur: bool = False - parsedMessage = input.split(" ") - for word in parsedMessage: - for slur in config.slurList: - if word.lower() == slur: - containsSlur = True - break - if containsSlur: + containsSlur: bool = False + parsedMessage = input.split(" ") + for word in parsedMessage: + for slur in config.slurList: + if word.lower() == slur: + containsSlur = True break - if containsSlur: - print("<{ slur detected! }> ") - return containsSlur + break + + if containsSlur: + print("<{ slur detected! }> ") + return containsSlur def isRunningInDocker(): isD = os.getenv('ISDOCKER') @@ -72,45 +72,45 @@ def isRunningInDocker(): return isD == "cat" def hard_shutdown(): - current_system_pid = os.getpid() + current_system_pid = os.getpid() - ThisSystem = psutil.Process(current_system_pid) - ThisSystem.terminate() + ThisSystem = psutil.Process(current_system_pid) + ThisSystem.terminate() def restart_self(): - #current_system_pid = os.getpid() - #os.startfile("python C:/praxis/main.py") - #subprocess.run("python C:/praxis/main.py") - #subprocess.call("python main.py", shell=True) - if platform.system() == 'Windows': - os.system('start cmd /k python main.py') - hard_shutdown() - if platform.system() == 'Linux': - os.system('xfce4-terminal -e "python main.py"') - hard_shutdown() + #current_system_pid = os.getpid() + #os.startfile("python C:/praxis/main.py") + #subprocess.run("python C:/praxis/main.py") + #subprocess.call("python main.py", shell=True) + if platform.system() == 'Windows': + os.system('start cmd /k python main.py') + hard_shutdown() + if platform.system() == 'Linux': + os.system('xfce4-terminal -e "python main.py"') + hard_shutdown() - #os.system('python twitch_script.py') - #os.system('python discord_script.py') + #os.system('python twitch_script.py') + #os.system('python discord_script.py') def restart_target(): - pass + pass def launch_target(inputScript: str): - cmd = "start cmd /k python " + inputScript - os.system(cmd) + cmd = "start cmd /k python " + inputScript + os.system(cmd) def splashScreen(): - if not config.skip_splashScreenClear: - clearScreen() - art.tprint("----------",font="slant") - art.tprint("Praxis Bot",font="graffiti") - art.tprint("----------",font="slant") - print("-Maintained by Alex Orid, TheCuriousNerd.com\nFor help visit discord.gg/thecuriousnerd") - print("ver: " + config.praxisVersion_Alpha + config.praxisVersion_Delta + config.praxisVersion_Omega) - print("\n\n\n") - if not config.skip_splashScreenSleep: - time.sleep(3) + if not config.skip_splashScreenClear: + clearScreen() + art.tprint("----------",font="slant") + art.tprint("Praxis Bot",font="graffiti") + art.tprint("----------",font="slant") + print("-Maintained by Alex Orid, TheCuriousNerd.com\nFor help visit discord.gg/thecuriousnerd") + print("ver: " + config.praxisVersion_Alpha + config.praxisVersion_Delta + config.praxisVersion_Omega) + print("\n\n\n") + if not config.skip_splashScreenSleep: + time.sleep(3) if __name__ == "__main__": - splashScreen() \ No newline at end of file + splashScreen() \ No newline at end of file From c01418cebef5aed4818ffd9f954b2aaa5e038753 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 17:33:56 -0400 Subject: [PATCH 05/11] tts Docker Fix --- tts.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tts.py b/tts.py index 54790c0..116c990 100644 --- a/tts.py +++ b/tts.py @@ -6,13 +6,17 @@ import requests from gtts import gTTS from playsound import playsound +import utilities_script as utility import config streamLabsUrl = "https://streamlabs.com/polly/speak" def tts(inputText: str, *args): outpath = create_speech_file(inputText) - playsound(outpath) + if utility.isRunningInDocker() == False: + print("Docker Detected, skipping playsound()") + else: + playsound(outpath) def create_speech_gtts(input_text: str): From b7e20c56029e8d7b03736c38cf0553cae6cb0710 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 18:04:10 -0400 Subject: [PATCH 06/11] Fixed TTS Bugs Fixed Discord TTS Config Bug Fixed Docker TTS playsound() --- config.py | 2 +- discord_script.py | 8 +++++++- tts.py | 3 ++- user_module.py | 2 +- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index cd67c70..a30d345 100644 --- a/config.py +++ b/config.py @@ -30,8 +30,8 @@ block_DiscordChannelsMessaging = [""] # Blocks the ability to send messages to D blockAll_DiscordChannelsMessaging = False # Blocks the ability to send messages to Discord channels blockAll_DiscordPrivateMessaging = False # Private Messaging not yet implemented -selected_DiscordTTSChannels = ["431129571308339210"] autoEnabled_DiscordChannelsTTS = False +selected_DiscordTTSChannels = ["431129571308339210"] block_DiscordChannelsTTS = [""] # block supersedes the tts_enabled bool blockAll_DiscordChannelsTTS = False # blockAll supersedes the force bool and force list and tts_enabled bool force_DiscordChannelsTTS = [""] # force supersedes the block list diff --git a/discord_script.py b/discord_script.py index 28a212d..bba7c16 100644 --- a/discord_script.py +++ b/discord_script.py @@ -138,7 +138,13 @@ class Discord_Module(discord.Client): #print("isBlocked: " + str(isBlocked)) #print("isForced: " + str(isForced)) if (not await self.contains_slur(message)) and (await self.isTTS_URL_Enabled(message)): - if self.tts_enabled and not isBlocked and not config.blockAll_DiscordChannelsTTS or isForced or config.forceAll_DiscordChatChannelsTTS: + print(message.channel.id, message.channel.id, message.channel.id) + isMessageChannelInList = False + for TTS_C_id in config.selected_DiscordTTSChannels: + print(TTS_C_id) + if int(TTS_C_id) == int(message.channel.id): + isMessageChannelInList = True + if self.tts_enabled and (isMessageChannelInList) and not isBlocked and not config.blockAll_DiscordChannelsTTS or isForced or config.forceAll_DiscordChatChannelsTTS: if not message.content.startswith('!'): text_to_say: str = "%s says, %s" % (message.author.display_name, message.content) channel_text = "%s user msg" % message.channel diff --git a/tts.py b/tts.py index 116c990..6e026aa 100644 --- a/tts.py +++ b/tts.py @@ -13,9 +13,10 @@ streamLabsUrl = "https://streamlabs.com/polly/speak" def tts(inputText: str, *args): outpath = create_speech_file(inputText) - if utility.isRunningInDocker() == False: + if utility.isRunningInDocker() == True: print("Docker Detected, skipping playsound()") else: + print("Playing Sound...") playsound(outpath) diff --git a/user_module.py b/user_module.py index 3e7becc..823b2ce 100644 --- a/user_module.py +++ b/user_module.py @@ -21,7 +21,7 @@ class User_Module(): def main(self): print("\nWaiting on User input...\n") inputLoop = True - if utility.isRunningInDocker() == False: + if utility.isRunningInDocker() == True: inputLoop = False print("\nNo User's Input Allowed") while inputLoop: From 897f1c367f5ad4a8d4d513e04b60b356e4c995d1 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 18:43:17 -0400 Subject: [PATCH 07/11] Readme Update --- README.md | 7 ++----- main.py | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ea0f62d..6e82fda 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,10 @@ ___ ## Docker Info: -Uncomment the following line in the **Dockerfile** to have **main.py** start with the Docker Container +Currently to build the container you need to run the following command otherwise you get the error ***"TERM environment variable not set."*** -`#CMD [ "python3", "main.py"]` +`docker create -t -e ISDOCKER=cat --name praxis praxis` -To start the bot with **User_Module** activated use this. - -`docker exec -ti praxis python3 main.py` # Credentials: diff --git a/main.py b/main.py index e22f2e3..3040fcd 100644 --- a/main.py +++ b/main.py @@ -36,8 +36,9 @@ def twitch_module_init(dbCert, twitchCert): twitchModule_.tts_enabled = config.autoEnabled_TwitchChannelsTTS twitchModule_.whitelisted_users = config.whitelisted_TwitchPowerUsers + print("[TWITCH Module]>", "Loading Channels...") for twitchChannel in config.autoJoin_TwitchChannels: - print("joining channel function") + print("joining twitch channel:", twitchChannel) twitchModule_.join_channel(None, twitchChannel) def discord_module_init(dbCert, discordCert): From e34b3af255542cd67b142b4fd885a4ea109eb1a3 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 18:45:07 -0400 Subject: [PATCH 08/11] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 6e82fda..496b60b 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ ___ ## Docker Info: Currently to build the container you need to run the following command otherwise you get the error ***"TERM environment variable not set."*** +Docker Compose will also fail and result in the same error. `docker create -t -e ISDOCKER=cat --name praxis praxis` From c735dd8664e62af3cf50e6ea4f7f6d007ee6846d Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 18:52:08 -0400 Subject: [PATCH 09/11] Fix --- README.md | 6 ++---- main.py | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 496b60b..c448b9b 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,9 @@ ___ ## Docker Info: -Currently to build the container you need to run the following command otherwise you get the error ***"TERM environment variable not set."*** -Docker Compose will also fail and result in the same error. - -`docker create -t -e ISDOCKER=cat --name praxis praxis` +To start the bot with **User_Module** activated use this. +`docker exec -ti praxis python3 main.py` # Credentials: diff --git a/main.py b/main.py index 3040fcd..98c6f60 100644 --- a/main.py +++ b/main.py @@ -64,6 +64,8 @@ def user_module_init(dbCert, Empty): userModule_.main() def thread_main(): + if utility.isRunningInDocker() == True: + print("<[DOCKER Detected]>") if not config.skip_splashScreen: utility.splashScreen() global credentials_manager From 5959f44bf9ff0160cf12143d5cee3943b9f19348 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 19:09:01 -0400 Subject: [PATCH 10/11] Fixed Readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index c448b9b..30a4c54 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ ___ ## Docker Info: +Currently to build the container run the following command. + +`docker create -p 2501:2501 -e ISDOCKER=cat --name praxistest5 praxis` + To start the bot with **User_Module** activated use this. `docker exec -ti praxis python3 main.py` From a41b20e15cb71557701bde631115fbc689aece23 Mon Sep 17 00:00:00 2001 From: Alex Orid Date: Thu, 15 Apr 2021 19:33:07 -0400 Subject: [PATCH 11/11] Fixed Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 30a4c54..43acb28 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ ___ Currently to build the container run the following command. -`docker create -p 2501:2501 -e ISDOCKER=cat --name praxistest5 praxis` +`docker create -p 2501:2501 -e ISDOCKER=cat --name praxis praxis` To start the bot with **User_Module** activated use this.