Skip to content

Commit

Permalink
fix empty messages being able to be sent in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
detectiveren committed Apr 13, 2024
1 parent 13e6f7f commit a1424d8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion luna.py
Original file line number Diff line number Diff line change
@@ -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/
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a1424d8

Please sign in to comment.