Sasha commited on
Commit
03bc181
·
1 Parent(s): d931d22

feat: worker and chat_mod_worker now also sync roles to /api/log/roles on every message batch

Browse files
local_worker/chat_mod_worker.py CHANGED
@@ -233,16 +233,35 @@ def chat_sender():
233
 
234
  if messages:
235
  try:
 
236
  response = requests.post(url, json={"messages": messages}, headers=headers, timeout=5)
237
- if response.status_code == 200:
238
- pass # Success
239
- else:
240
  print(f"[Chat Sender] Failed to sync messages. API returned status {response.status_code}")
241
  except Exception as e:
242
  print(f"[Chat Sender] Network error sending messages: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
 
244
  time.sleep(3)
245
 
 
246
  def mod_action_sender():
247
  """Periodically sends accumulated mod actions to backend API"""
248
  headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
 
233
 
234
  if messages:
235
  try:
236
+ # 1. Send messages
237
  response = requests.post(url, json={"messages": messages}, headers=headers, timeout=5)
238
+ if response.status_code != 200:
 
 
239
  print(f"[Chat Sender] Failed to sync messages. API returned status {response.status_code}")
240
  except Exception as e:
241
  print(f"[Chat Sender] Network error sending messages: {e}")
242
+
243
+ try:
244
+ # 2. Send roles for users who have at least one badge
245
+ roles = [
246
+ {
247
+ "username": m["username"],
248
+ "displayName": m.get("displayName", m["username"]),
249
+ "isMod": m.get("isMod", False),
250
+ "isSub": m.get("isSub", False),
251
+ "isVip": m.get("isVip", False),
252
+ "timestamp": m.get("timestamp")
253
+ }
254
+ for m in messages
255
+ if m.get("isMod") or m.get("isSub") or m.get("isVip")
256
+ ]
257
+ if roles:
258
+ requests.post(f"{API_URL}/api/log/roles", json={"roles": roles}, headers=headers, timeout=5)
259
+ except Exception as e:
260
+ print(f"[Chat Sender] Network error sending roles: {e}")
261
 
262
  time.sleep(3)
263
 
264
+
265
  def mod_action_sender():
266
  """Periodically sends accumulated mod actions to backend API"""
267
  headers = {"x-api-key": API_KEY, "Content-Type": "application/json"}
local_worker/worker.py CHANGED
@@ -208,18 +208,37 @@ def chat_sender():
208
 
209
  if messages:
210
  try:
 
211
  url = f"{API_URL}/api/log/messages"
212
  response = requests.post(url, json={"messages": messages}, headers=headers, timeout=5)
213
- if response.status_code == 200:
214
- pass # Success
215
- else:
216
  print(f"[Chat Sender] Failed to sync messages. API returned status {response.status_code}")
217
  except Exception as e:
218
  print(f"[Chat Sender] Network error sending messages: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
219
 
220
  # Wait 5 seconds before next sync
221
  time.sleep(5)
222
 
 
223
  # =========================================================================
224
  # AUDIO TRANSCRIBER (WHISPER)
225
  # =========================================================================
 
208
 
209
  if messages:
210
  try:
211
+ # 1. Send messages
212
  url = f"{API_URL}/api/log/messages"
213
  response = requests.post(url, json={"messages": messages}, headers=headers, timeout=5)
214
+ if response.status_code != 200:
 
 
215
  print(f"[Chat Sender] Failed to sync messages. API returned status {response.status_code}")
216
  except Exception as e:
217
  print(f"[Chat Sender] Network error sending messages: {e}")
218
+
219
+ try:
220
+ # 2. Send roles for users who have at least one badge
221
+ roles = [
222
+ {
223
+ "username": m["username"],
224
+ "displayName": m.get("displayName", m["username"]),
225
+ "isMod": m.get("isMod", False),
226
+ "isSub": m.get("isSub", False),
227
+ "isVip": m.get("isVip", False),
228
+ "timestamp": m.get("timestamp")
229
+ }
230
+ for m in messages
231
+ if m.get("isMod") or m.get("isSub") or m.get("isVip")
232
+ ]
233
+ if roles:
234
+ requests.post(f"{API_URL}/api/log/roles", json={"roles": roles}, headers=headers, timeout=5)
235
+ except Exception as e:
236
+ print(f"[Chat Sender] Network error sending roles: {e}")
237
 
238
  # Wait 5 seconds before next sync
239
  time.sleep(5)
240
 
241
+
242
  # =========================================================================
243
  # AUDIO TRANSCRIBER (WHISPER)
244
  # =========================================================================