From a1424d8ab8c9469f38ea7754e4e66974e3fbcad9 Mon Sep 17 00:00:00 2001 From: DetectivEren <55319774+detectiveren@users.noreply.github.com> Date: Sat, 13 Apr 2024 15:30:54 +0100 Subject: [PATCH] fix empty messages being able to be sent in chat --- luna.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/luna.py b/luna.py index 228b434..acfefce 100644 --- a/luna.py +++ b/luna.py @@ -1,6 +1,7 @@ import flet as ft import settings from cryptography.fernet import Fernet +from time import sleep # Resources used to develop the app https://flet.dev/docs/tutorials/python-realtime-chat/#getting-started-with-flet # For info on how to deal with keyboard events https://flet.dev/docs/guides/python/keyboard-shortcuts/ @@ -289,6 +290,7 @@ def sendLunaBOTMessage(response): # Send the response from lunaBOT into chat print(f"LOG (Message Type: lunaChatMessage) (lunaBOT): {lunaBOTResponse} (requested by {lunaUsername.value})") def sendClick(e): + emptyMsg = False # lunaChat.controls.append(ft.Text(newMessage.value)) # Appends the message sent by the user with open('./config/bannedWords.txt') as readBannedWords: bannedWords = readBannedWords.readlines() # Read all the usernames from the textfile into the list @@ -319,9 +321,17 @@ def standardMessage(): # lunaMessageType="lunaVideoMessage", lunaKey=key)) elif message.strip() in bannedWords: lunaBOT("banned_word_sent") + elif message.strip() == "": + newMessage.error_text = "MESSAGE CANNOT BE EMPTY" + newMessage.value = "" # Reset the message value + newMessage.update() # Update the message box + sleep(5) # Wait 5 seconds before changing the message box back to normal + newMessage.error_text = "" # Clear out the error text + emptyMsg = True else: standardMessage() - print(f"LOG (Message Type: lunaChatMessage) ({lunaUsername.value}): {newMessage.value}") + if not emptyMsg: # If the message was not empty + print(f"LOG (Message Type: lunaChatMessage) ({lunaUsername.value}): {newMessage.value}") # Log the chat messages to the terminal newMessage.value = "" # Resets the value page.update() # Updates the page