list_chat_rooms.mjs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import Parse from 'parse/node.js';
  2. Parse.initialize('lami-ai');
  3. Parse.serverURL = 'https://server.sh-lami.com/parse';
  4. Parse.masterKey = process.env.PARSE_MASTER_KEY || '5s1gfOasPqx9JKsA';
  5. const CHAT = [0, 2, 6, 13, 14, 15, 16, 20, 22, 23, 29, 41, 78, 123, 141, 146, 213];
  6. const q = new Parse.Query('Message');
  7. q.containedIn('msgType', CHAT);
  8. q.notEqualTo('roomId', null);
  9. q.limit(1000);
  10. q.descending('timestamp');
  11. const msgs = await q.find({ useMasterKey: true });
  12. const byRoom = new Map();
  13. for (const m of msgs) {
  14. const roomId = m.get('roomId');
  15. if (!roomId) continue;
  16. if (!byRoom.has(roomId)) byRoom.set(roomId, { chat: 0, total: 0, samples: [] });
  17. const e = byRoom.get(roomId);
  18. e.chat++;
  19. const content = String(m.get('content') || '').slice(0, 100);
  20. const sender = m.get('senderName') || m.get('senderId') || '';
  21. const ts = m.get('timestamp');
  22. if (e.samples.length < 3) e.samples.push({ msgType: m.get('msgType'), sender, content, ts });
  23. }
  24. const qAll = new Parse.Query('Message');
  25. qAll.notEqualTo('roomId', null);
  26. qAll.limit(1000);
  27. const allMsgs = await qAll.find({ useMasterKey: true });
  28. for (const m of allMsgs) {
  29. const roomId = m.get('roomId');
  30. if (!roomId) continue;
  31. if (!byRoom.has(roomId)) byRoom.set(roomId, { chat: 0, total: 0, samples: [] });
  32. byRoom.get(roomId).total++;
  33. }
  34. const roomIds = [...byRoom.keys()];
  35. const gq = new Parse.Query('GroupChat');
  36. gq.containedIn('roomId', roomIds);
  37. gq.limit(500);
  38. const groups = await gq.find({ useMasterKey: true });
  39. const nameMap = new Map(groups.map((g) => [g.get('roomId'), g.get('name') || g.get('roomName') || '']));
  40. const rows = [...byRoom.entries()]
  41. .map(([roomId, v]) => ({ roomId, name: nameMap.get(roomId) || '(无名)', ...v }))
  42. .sort((a, b) => b.chat - a.chat);
  43. console.log('=== 有聊天记录的群 ===');
  44. const withChat = rows.filter((r) => r.chat > 0);
  45. console.log(`共 ${withChat.length} 个群有聊天消息\n`);
  46. for (const r of withChat.slice(0, 25)) {
  47. console.log('---');
  48. console.log(`群名: ${r.name}`);
  49. console.log(`roomId: ${r.roomId}`);
  50. console.log(`聊天 ${r.chat} 条 / 全部 ${r.total} 条`);
  51. for (const s of r.samples) {
  52. console.log(` [${s.msgType}] ${s.sender}: ${s.content}`);
  53. }
  54. }
  55. console.log('\n=== 只有撤回/系统消息、无聊天文字的群 (前10) ===');
  56. for (const r of rows.filter((x) => x.chat === 0 && x.total > 0).slice(0, 10)) {
  57. console.log(`${r.name || '(无名)'} | ${r.roomId} | 共 ${r.total} 条非聊天`);
  58. }