Update app.py
Browse files
app.py
CHANGED
@@ -53,13 +53,15 @@ UNICODE_DIGITS = {i: f"{i}\uFE0Fโฃ" for i in range(10)}
|
|
53 |
UNICODE_FONTS = [
|
54 |
("Normal", lambda x: x),
|
55 |
("Bold", lambda x: "".join(chr(ord(c) + 0x1D400 - 0x41) if 'A' <= c <= 'Z' else chr(ord(c) + 0x1D41A - 0x61) if 'a' <= c <= 'z' else c for c in x)),
|
56 |
-
# ... (other font styles remain the same)
|
57 |
]
|
58 |
|
59 |
server_running = False
|
60 |
server_task = None
|
61 |
|
62 |
def get_node_name():
|
|
|
|
|
|
|
63 |
parser = argparse.ArgumentParser(description='Start a chat node with a specific name')
|
64 |
parser.add_argument('--node-name', type=str, default=None)
|
65 |
parser.add_argument('--port', type=int, default=8501)
|
@@ -67,12 +69,19 @@ def get_node_name():
|
|
67 |
return args.node_name or f"node-{uuid.uuid4().hex[:8]}", args.port
|
68 |
|
69 |
def save_chat_entry(username, message):
|
|
|
|
|
|
|
|
|
70 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
71 |
entry = f"[{timestamp}] {username}: {message}"
|
72 |
with open(CHAT_FILE, 'a') as f:
|
73 |
f.write(f"{entry}\n")
|
74 |
|
75 |
def load_chat():
|
|
|
|
|
|
|
76 |
if not os.path.exists(CHAT_FILE):
|
77 |
with open(CHAT_FILE, 'w') as f:
|
78 |
f.write(f"# {START_ROOM} Chat\n\nWelcome to the cosmic hub - start chatting! ๐ค\n")
|
@@ -82,6 +91,9 @@ def load_chat():
|
|
82 |
return "\n".join(f"{i+1}. {line}" for i, line in enumerate(lines) if line.strip())
|
83 |
|
84 |
def get_user_list(chat_content):
|
|
|
|
|
|
|
85 |
users = set()
|
86 |
for line in chat_content.split('\n'):
|
87 |
if line.strip() and ': ' in line:
|
@@ -90,38 +102,50 @@ def get_user_list(chat_content):
|
|
90 |
return sorted(list(users))
|
91 |
|
92 |
def has_joined_before(client_id, chat_content):
|
|
|
|
|
|
|
93 |
return any(f"Client-{client_id} has joined" in line for line in chat_content.split('\n'))
|
94 |
|
95 |
def get_message_suggestions(chat_content, prefix):
|
|
|
|
|
|
|
96 |
lines = chat_content.split('\n')
|
97 |
messages = [line.split(': ', 1)[1] for line in lines if ': ' in line and line.strip()]
|
98 |
return [msg for msg in messages if msg.lower().startswith(prefix.lower())][:5]
|
99 |
|
100 |
def load_quotes(source="famous"):
|
|
|
|
|
|
|
101 |
famous_quotes = [
|
102 |
"The true sign of intelligence is not knowledge but imagination. โ Albert Einstein",
|
103 |
-
# ... (other quotes remain the same)
|
104 |
]
|
105 |
custom_quotes = [
|
106 |
"Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew.",
|
107 |
-
# ... (other custom quotes remain the same)
|
108 |
]
|
109 |
return famous_quotes if source == "famous" else custom_quotes
|
110 |
|
111 |
def save_vote(file, item, user_hash, username, comment=""):
|
|
|
|
|
|
|
112 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
113 |
entry = f"[{timestamp}] {user_hash} voted for {item}"
|
114 |
with open(file, 'a') as f:
|
115 |
f.write(f"{entry}\n")
|
116 |
with open(HISTORY_FILE, "a") as f:
|
117 |
f.write(f"- {timestamp} - User {user_hash} voted for {item}\n")
|
118 |
-
# Add a new chat entry for the upvote
|
119 |
chat_message = f"{username} upvoted: \"{item}\""
|
120 |
if comment:
|
121 |
chat_message += f" - {comment}"
|
122 |
save_chat_entry(username, chat_message)
|
123 |
|
124 |
def load_votes(file):
|
|
|
|
|
|
|
125 |
if not os.path.exists(file):
|
126 |
with open(file, 'w') as f:
|
127 |
f.write("# Vote Tally\n\nNo votes yet - get clicking! ๐ฑ๏ธ\n")
|
@@ -140,11 +164,17 @@ def load_votes(file):
|
|
140 |
return votes
|
141 |
|
142 |
def generate_user_hash():
|
|
|
|
|
|
|
143 |
if 'user_hash' not in st.session_state:
|
144 |
st.session_state.user_hash = hashlib.md5(str(random.getrandbits(128)).encode()).hexdigest()[:8]
|
145 |
return st.session_state.user_hash
|
146 |
|
147 |
def save_pasted_image(image_data):
|
|
|
|
|
|
|
148 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
149 |
filename = f"paste_{timestamp}.png"
|
150 |
filepath = os.path.join('./', filename)
|
@@ -156,16 +186,25 @@ def save_pasted_image(image_data):
|
|
156 |
return filename
|
157 |
|
158 |
def get_video_html(video_path, width="100%"):
|
|
|
|
|
|
|
159 |
video_url = f"data:video/mp4;base64,{base64.b64encode(open(video_path, 'rb').read()).decode()}"
|
160 |
return f'<video width="{width}" controls autoplay muted loop><source src="{video_url}" type="video/mp4">Your browser does not support the video tag.</video>'
|
161 |
|
162 |
def get_audio_html(audio_path, width="100%"):
|
|
|
|
|
|
|
163 |
audio_url = f"data:audio/mpeg;base64,{base64.b64encode(open(audio_path, 'rb').read()).decode()}"
|
164 |
return f'<audio controls style="width: {width};"><source src="{audio_url}" type="audio/mpeg">Your browser does not support the audio element.</audio>'
|
165 |
|
166 |
active_connections = {}
|
167 |
|
168 |
async def websocket_handler(websocket, path):
|
|
|
|
|
|
|
169 |
try:
|
170 |
client_id = str(uuid.uuid4())
|
171 |
room_id = "chat"
|
@@ -187,6 +226,9 @@ async def websocket_handler(websocket, path):
|
|
187 |
del active_connections[room_id][client_id]
|
188 |
|
189 |
async def broadcast_message(message, room_id):
|
|
|
|
|
|
|
190 |
if room_id in active_connections:
|
191 |
disconnected = []
|
192 |
for client_id, ws in active_connections[room_id].items():
|
@@ -198,6 +240,9 @@ async def broadcast_message(message, room_id):
|
|
198 |
del active_connections[room_id][client_id]
|
199 |
|
200 |
async def run_websocket_server():
|
|
|
|
|
|
|
201 |
global server_running, server_task
|
202 |
if not server_running:
|
203 |
server = await websockets.serve(websocket_handler, '0.0.0.0', 8765)
|
@@ -205,6 +250,10 @@ async def run_websocket_server():
|
|
205 |
await server.wait_closed()
|
206 |
|
207 |
def create_streamlit_interface():
|
|
|
|
|
|
|
|
|
208 |
# Dynamic title based on username
|
209 |
if 'username' in st.session_state:
|
210 |
dynamic_title = f"๐ค๐ง MMO {st.session_state.username}๐๐ฌ"
|
@@ -243,6 +292,8 @@ def create_streamlit_interface():
|
|
243 |
st.session_state.quote_source = "famous"
|
244 |
if 'pasted_image_data' not in st.session_state:
|
245 |
st.session_state.pasted_image_data = None
|
|
|
|
|
246 |
|
247 |
# JavaScript component for image paste
|
248 |
paste_component = components.html(
|
@@ -279,7 +330,7 @@ def create_streamlit_interface():
|
|
279 |
filename = save_pasted_image(pasted_image)
|
280 |
if filename:
|
281 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
282 |
-
st.session_state.pasted_image_data = None
|
283 |
st.rerun()
|
284 |
|
285 |
# Chat section
|
@@ -294,14 +345,14 @@ def create_streamlit_interface():
|
|
294 |
with col2:
|
295 |
vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
|
296 |
if st.button(f"๐ {vote_count}", key=f"chat_vote_{i}"):
|
297 |
-
comment = st.session_state.
|
298 |
save_vote(QUOTE_VOTES_FILE, line.split('. ')[1] if '. ' in line else line, generate_user_hash(), st.session_state.username, comment)
|
299 |
-
if
|
300 |
-
filename = save_pasted_image(
|
301 |
if filename:
|
302 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
303 |
st.session_state.pasted_image_data = None
|
304 |
-
st.session_state.
|
305 |
st.rerun()
|
306 |
|
307 |
# Username change dropdown
|
@@ -312,15 +363,15 @@ def create_streamlit_interface():
|
|
312 |
st.rerun()
|
313 |
|
314 |
# Message input
|
315 |
-
message = st.text_input(f"Message as {st.session_state.username}", key="message_input")
|
316 |
if st.button("Send ๐", key="send_button") and message.strip():
|
317 |
save_chat_entry(st.session_state.username, message)
|
318 |
-
st.session_state.
|
319 |
-
if st.session_state.get('pasted_image_data'):
|
320 |
filename = save_pasted_image(st.session_state.pasted_image_data)
|
321 |
if filename:
|
322 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
323 |
st.session_state.pasted_image_data = None
|
|
|
324 |
st.rerun()
|
325 |
|
326 |
# Media section with upload and delete
|
@@ -338,7 +389,7 @@ def create_streamlit_interface():
|
|
338 |
media_votes = load_votes(MEDIA_VOTES_FILE)
|
339 |
for idx, media_file in enumerate(media_files):
|
340 |
vote_count = media_votes.get(media_file, 0)
|
341 |
-
if vote_count > 0:
|
342 |
with cols[idx % 3]:
|
343 |
if media_file.endswith(('.png', '.jpg')):
|
344 |
st.image(media_file, use_container_width=True)
|
@@ -349,14 +400,14 @@ def create_streamlit_interface():
|
|
349 |
col1, col2 = st.columns(2)
|
350 |
with col1:
|
351 |
if st.button(f"๐ {vote_count}", key=f"media_vote_{idx}"):
|
352 |
-
comment = st.session_state.
|
353 |
save_vote(MEDIA_VOTES_FILE, media_file, generate_user_hash(), st.session_state.username, comment)
|
354 |
-
if st.session_state.
|
355 |
filename = save_pasted_image(st.session_state.pasted_image_data)
|
356 |
if filename:
|
357 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
358 |
st.session_state.pasted_image_data = None
|
359 |
-
st.session_state.
|
360 |
st.rerun()
|
361 |
with col2:
|
362 |
if st.button("๐๏ธ", key=f"media_delete_{idx}"):
|
@@ -380,10 +431,13 @@ def create_streamlit_interface():
|
|
380 |
chat_votes = load_votes(QUOTE_VOTES_FILE)
|
381 |
media_votes = load_votes(MEDIA_VOTES_FILE)
|
382 |
for item, count in {**chat_votes, **media_votes}.items():
|
383 |
-
if count > 0:
|
384 |
st.sidebar.write(f"{item}: {count} votes")
|
385 |
|
386 |
async def main():
|
|
|
|
|
|
|
387 |
global NODE_NAME, server_task
|
388 |
NODE_NAME, port = get_node_name()
|
389 |
if server_task is None:
|
|
|
53 |
UNICODE_FONTS = [
|
54 |
("Normal", lambda x: x),
|
55 |
("Bold", lambda x: "".join(chr(ord(c) + 0x1D400 - 0x41) if 'A' <= c <= 'Z' else chr(ord(c) + 0x1D41A - 0x61) if 'a' <= c <= 'z' else c for c in x)),
|
|
|
56 |
]
|
57 |
|
58 |
server_running = False
|
59 |
server_task = None
|
60 |
|
61 |
def get_node_name():
|
62 |
+
"""๐ - Naming Node with Code - Spins a name, oh so bold!"""
|
63 |
+
action = "๐ - Naming Node with Code - Spins a name, oh so bold!"
|
64 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
65 |
parser = argparse.ArgumentParser(description='Start a chat node with a specific name')
|
66 |
parser.add_argument('--node-name', type=str, default=None)
|
67 |
parser.add_argument('--port', type=int, default=8501)
|
|
|
69 |
return args.node_name or f"node-{uuid.uuid4().hex[:8]}", args.port
|
70 |
|
71 |
def save_chat_entry(username, message):
|
72 |
+
"""๐ - Chat Snap Trap - Logs your yap, no cap! โ๏ธ๐ง """
|
73 |
+
action = "๐ - Chat Snap Trap - Logs your yap, no cap! โ๏ธ๐ง " # Double rhyme bonus!
|
74 |
+
with open(CHAT_FILE, 'a') as f:
|
75 |
+
f.write(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] {username}: {action}\n")
|
76 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
77 |
entry = f"[{timestamp}] {username}: {message}"
|
78 |
with open(CHAT_FILE, 'a') as f:
|
79 |
f.write(f"{entry}\n")
|
80 |
|
81 |
def load_chat():
|
82 |
+
"""๐ - Chat Fetch Quest - Grabs the log, no jest!"""
|
83 |
+
action = "๐ - Chat Fetch Quest - Grabs the log, no jest!"
|
84 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
85 |
if not os.path.exists(CHAT_FILE):
|
86 |
with open(CHAT_FILE, 'w') as f:
|
87 |
f.write(f"# {START_ROOM} Chat\n\nWelcome to the cosmic hub - start chatting! ๐ค\n")
|
|
|
91 |
return "\n".join(f"{i+1}. {line}" for i, line in enumerate(lines) if line.strip())
|
92 |
|
93 |
def get_user_list(chat_content):
|
94 |
+
"""๐ฅ - Crew Clue Brew - Spots whoโs who in the crew!"""
|
95 |
+
action = "๐ฅ - Crew Clue Brew - Spots whoโs who in the crew!"
|
96 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
97 |
users = set()
|
98 |
for line in chat_content.split('\n'):
|
99 |
if line.strip() and ': ' in line:
|
|
|
102 |
return sorted(list(users))
|
103 |
|
104 |
def has_joined_before(client_id, chat_content):
|
105 |
+
"""๐ช - Join Check Trek - Sees whoโs back, no wreck!"""
|
106 |
+
action = "๐ช - Join Check Trek - Sees whoโs back, no wreck!"
|
107 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
108 |
return any(f"Client-{client_id} has joined" in line for line in chat_content.split('\n'))
|
109 |
|
110 |
def get_message_suggestions(chat_content, prefix):
|
111 |
+
"""๐ - Suggest Jest Chest - Finds old quips, the best!"""
|
112 |
+
action = "๐ - Suggest Jest Chest - Finds old quips, the best!"
|
113 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
114 |
lines = chat_content.split('\n')
|
115 |
messages = [line.split(': ', 1)[1] for line in lines if ': ' in line and line.strip()]
|
116 |
return [msg for msg in messages if msg.lower().startswith(prefix.lower())][:5]
|
117 |
|
118 |
def load_quotes(source="famous"):
|
119 |
+
"""๐ - Quote Tote Note - Wise words float, we gloat!"""
|
120 |
+
action = "๐ - Quote Tote Note - Wise words float, we gloat!"
|
121 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
122 |
famous_quotes = [
|
123 |
"The true sign of intelligence is not knowledge but imagination. โ Albert Einstein",
|
|
|
124 |
]
|
125 |
custom_quotes = [
|
126 |
"Every age unfolds a new lesson. Life's chapters evolve, each teaching us anew.",
|
|
|
127 |
]
|
128 |
return famous_quotes if source == "famous" else custom_quotes
|
129 |
|
130 |
def save_vote(file, item, user_hash, username, comment=""):
|
131 |
+
"""๐ - Vote Note Float - Cheers rise, we gloat!"""
|
132 |
+
action = "๐ - Vote Note Float - Cheers rise, we gloat!"
|
133 |
+
save_chat_entry(username, action)
|
134 |
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
135 |
entry = f"[{timestamp}] {user_hash} voted for {item}"
|
136 |
with open(file, 'a') as f:
|
137 |
f.write(f"{entry}\n")
|
138 |
with open(HISTORY_FILE, "a") as f:
|
139 |
f.write(f"- {timestamp} - User {user_hash} voted for {item}\n")
|
|
|
140 |
chat_message = f"{username} upvoted: \"{item}\""
|
141 |
if comment:
|
142 |
chat_message += f" - {comment}"
|
143 |
save_chat_entry(username, chat_message)
|
144 |
|
145 |
def load_votes(file):
|
146 |
+
"""๐ - Tally Rally Call - Counts the cheers, no stall!"""
|
147 |
+
action = "๐ - Tally Rally Call - Counts the cheers, no stall!"
|
148 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
149 |
if not os.path.exists(file):
|
150 |
with open(file, 'w') as f:
|
151 |
f.write("# Vote Tally\n\nNo votes yet - get clicking! ๐ฑ๏ธ\n")
|
|
|
164 |
return votes
|
165 |
|
166 |
def generate_user_hash():
|
167 |
+
"""๐ - Hash Dash Bash - Crafts a code, so brash!"""
|
168 |
+
action = "๐ - Hash Dash Bash - Crafts a code, so brash!"
|
169 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
170 |
if 'user_hash' not in st.session_state:
|
171 |
st.session_state.user_hash = hashlib.md5(str(random.getrandbits(128)).encode()).hexdigest()[:8]
|
172 |
return st.session_state.user_hash
|
173 |
|
174 |
def save_pasted_image(image_data):
|
175 |
+
"""๐ธ - Snap Cap Trap - Saves your pic, no flap!"""
|
176 |
+
action = "๐ธ - Snap Cap Trap - Saves your pic, no flap!"
|
177 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
178 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
179 |
filename = f"paste_{timestamp}.png"
|
180 |
filepath = os.path.join('./', filename)
|
|
|
186 |
return filename
|
187 |
|
188 |
def get_video_html(video_path, width="100%"):
|
189 |
+
"""๐ฅ - Reel Deal Steal - Plays your flick, so real!"""
|
190 |
+
action = "๐ฅ - Reel Deal Steal - Plays your flick, so real!"
|
191 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
192 |
video_url = f"data:video/mp4;base64,{base64.b64encode(open(video_path, 'rb').read()).decode()}"
|
193 |
return f'<video width="{width}" controls autoplay muted loop><source src="{video_url}" type="video/mp4">Your browser does not support the video tag.</video>'
|
194 |
|
195 |
def get_audio_html(audio_path, width="100%"):
|
196 |
+
"""๐ถ - Tune Moon Boom - Drops a beat, so groom!"""
|
197 |
+
action = "๐ถ - Tune Moon Boom - Drops a beat, so groom!"
|
198 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
199 |
audio_url = f"data:audio/mpeg;base64,{base64.b64encode(open(audio_path, 'rb').read()).decode()}"
|
200 |
return f'<audio controls style="width: {width};"><source src="{audio_url}" type="audio/mpeg">Your browser does not support the audio element.</audio>'
|
201 |
|
202 |
active_connections = {}
|
203 |
|
204 |
async def websocket_handler(websocket, path):
|
205 |
+
"""๐ - Web Sock Jock - Links the chat, no block!"""
|
206 |
+
action = "๐ - Web Sock Jock - Links the chat, no block!"
|
207 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
208 |
try:
|
209 |
client_id = str(uuid.uuid4())
|
210 |
room_id = "chat"
|
|
|
226 |
del active_connections[room_id][client_id]
|
227 |
|
228 |
async def broadcast_message(message, room_id):
|
229 |
+
"""๐ข - Shout Out Bout - Blasts the word, no doubt!"""
|
230 |
+
action = "๐ข - Shout Out Bout - Blasts the word, no doubt!"
|
231 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
232 |
if room_id in active_connections:
|
233 |
disconnected = []
|
234 |
for client_id, ws in active_connections[room_id].items():
|
|
|
240 |
del active_connections[room_id][client_id]
|
241 |
|
242 |
async def run_websocket_server():
|
243 |
+
"""๐ฅ๏ธ - Server Ferver Verve - Spins the web, with nerve!"""
|
244 |
+
action = "๐ฅ๏ธ - Server Ferver Verve - Spins the web, with nerve!"
|
245 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
246 |
global server_running, server_task
|
247 |
if not server_running:
|
248 |
server = await websockets.serve(websocket_handler, '0.0.0.0', 8765)
|
|
|
250 |
await server.wait_closed()
|
251 |
|
252 |
def create_streamlit_interface():
|
253 |
+
"""๐จ - UI Brew Crew - Builds the view, so new!"""
|
254 |
+
action = "๐จ - UI Brew Crew - Builds the view, so new!"
|
255 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
256 |
+
|
257 |
# Dynamic title based on username
|
258 |
if 'username' in st.session_state:
|
259 |
dynamic_title = f"๐ค๐ง MMO {st.session_state.username}๐๐ฌ"
|
|
|
292 |
st.session_state.quote_source = "famous"
|
293 |
if 'pasted_image_data' not in st.session_state:
|
294 |
st.session_state.pasted_image_data = None
|
295 |
+
if 'message_text' not in st.session_state:
|
296 |
+
st.session_state.message_text = ""
|
297 |
|
298 |
# JavaScript component for image paste
|
299 |
paste_component = components.html(
|
|
|
330 |
filename = save_pasted_image(pasted_image)
|
331 |
if filename:
|
332 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
333 |
+
st.session_state.pasted_image_data = None
|
334 |
st.rerun()
|
335 |
|
336 |
# Chat section
|
|
|
345 |
with col2:
|
346 |
vote_count = chat_votes.get(line.split('. ')[1] if '. ' in line else line, 0)
|
347 |
if st.button(f"๐ {vote_count}", key=f"chat_vote_{i}"):
|
348 |
+
comment = st.session_state.message_text
|
349 |
save_vote(QUOTE_VOTES_FILE, line.split('. ')[1] if '. ' in line else line, generate_user_hash(), st.session_state.username, comment)
|
350 |
+
if st.session_state.pasted_image_data:
|
351 |
+
filename = save_pasted_image(st.session_state.pasted_image_data)
|
352 |
if filename:
|
353 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
354 |
st.session_state.pasted_image_data = None
|
355 |
+
st.session_state.message_text = ''
|
356 |
st.rerun()
|
357 |
|
358 |
# Username change dropdown
|
|
|
363 |
st.rerun()
|
364 |
|
365 |
# Message input
|
366 |
+
message = st.text_input(f"Message as {st.session_state.username}", key="message_input", value=st.session_state.message_text, on_change=lambda: st.session_state.update(message_text=st.session_state.message_input))
|
367 |
if st.button("Send ๐", key="send_button") and message.strip():
|
368 |
save_chat_entry(st.session_state.username, message)
|
369 |
+
if st.session_state.pasted_image_data:
|
|
|
370 |
filename = save_pasted_image(st.session_state.pasted_image_data)
|
371 |
if filename:
|
372 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
373 |
st.session_state.pasted_image_data = None
|
374 |
+
st.session_state.message_text = ''
|
375 |
st.rerun()
|
376 |
|
377 |
# Media section with upload and delete
|
|
|
389 |
media_votes = load_votes(MEDIA_VOTES_FILE)
|
390 |
for idx, media_file in enumerate(media_files):
|
391 |
vote_count = media_votes.get(media_file, 0)
|
392 |
+
if vote_count > 0:
|
393 |
with cols[idx % 3]:
|
394 |
if media_file.endswith(('.png', '.jpg')):
|
395 |
st.image(media_file, use_container_width=True)
|
|
|
400 |
col1, col2 = st.columns(2)
|
401 |
with col1:
|
402 |
if st.button(f"๐ {vote_count}", key=f"media_vote_{idx}"):
|
403 |
+
comment = st.session_state.message_text
|
404 |
save_vote(MEDIA_VOTES_FILE, media_file, generate_user_hash(), st.session_state.username, comment)
|
405 |
+
if st.session_state.pasted_image_data:
|
406 |
filename = save_pasted_image(st.session_state.pasted_image_data)
|
407 |
if filename:
|
408 |
save_chat_entry(st.session_state.username, f"Pasted image: {filename}")
|
409 |
st.session_state.pasted_image_data = None
|
410 |
+
st.session_state.message_text = ''
|
411 |
st.rerun()
|
412 |
with col2:
|
413 |
if st.button("๐๏ธ", key=f"media_delete_{idx}"):
|
|
|
431 |
chat_votes = load_votes(QUOTE_VOTES_FILE)
|
432 |
media_votes = load_votes(MEDIA_VOTES_FILE)
|
433 |
for item, count in {**chat_votes, **media_votes}.items():
|
434 |
+
if count > 0:
|
435 |
st.sidebar.write(f"{item}: {count} votes")
|
436 |
|
437 |
async def main():
|
438 |
+
"""๐ฎ - Game Fame Claim - Starts the fun, no shame!"""
|
439 |
+
action = "๐ฎ - Game Fame Claim - Starts the fun, no shame!"
|
440 |
+
save_chat_entry(st.session_state.get('username', 'System ๐'), action)
|
441 |
global NODE_NAME, server_task
|
442 |
NODE_NAME, port = get_node_name()
|
443 |
if server_task is None:
|