@kaikybrofc/omnizap-system 2.2.3 → 2.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.env.example CHANGED
@@ -427,6 +427,14 @@ STICKER_DATA_LIST_LIMIT=50
427
427
  STICKER_DATA_LIST_MAX_LIMIT=200
428
428
  STICKER_DATA_SCAN_MAX_FILES=10000
429
429
 
430
+ # Login web via WhatsApp -> Google
431
+ WHATSAPP_LOGIN_TRIGGER=iniciar
432
+ WHATSAPP_LOGIN_BASE_URL=https://omnizap.shop
433
+ WHATSAPP_LOGIN_PATH=/login/
434
+ WHATSAPP_LOGIN_LINK_SECRET=troque_por_um_segredo_forte
435
+ WHATSAPP_LOGIN_LINK_TTL_SECONDS=900
436
+ WHATSAPP_LOGIN_REQUIRE_SIGNATURE=true
437
+
430
438
  # Paths locais (legado/uso auxiliar)
431
439
  STORE_PATH=./temp
432
440
 
package/README.md CHANGED
@@ -51,91 +51,35 @@ Conteúdo incluído no snapshot:
51
51
  Atualização em cache: **30 minutos** por padrão (`README_SUMMARY_CACHE_SECONDS=1800`).
52
52
 
53
53
  <!-- README_SNAPSHOT:START -->
54
- ## OmniZap System Snapshot
55
-
56
- Atualizado em: **2026-02-28T01:11:03.592Z**
57
- Janela de atualização: **1800 segundos**
58
-
59
- ### Totais do sistema
60
- - Usuários (lid_map): **5.502**
61
- - Grupos: **116**
62
- - Packs: **295**
63
- - Stickers: **6.313**
64
- - Mensagens registradas: **438.964**
65
-
66
- ### Tipos de mensagem mais usados (amostra de 25.000 mensagens)
67
- 1. `texto` - **16.530**
68
- 2. `figurinha` - **4.262**
69
- 3. `reacao` - **1.619**
70
- 4. `imagem` - **1.326**
71
- 5. `outros` - **799**
72
- 6. `video` - **245**
73
- 7. `audio` - **213**
74
- 8. `documento` - **6**
75
-
76
- ### Comandos disponíveis
77
- - `/add @user`
78
- - `/addmode`
79
- - `/autorequests`
80
- - `/autosticker`
81
- - `/ban @user`
82
- - `/captcha`
83
- - `/cat`
84
- - `/catimg`
85
- - `/catprompt`
86
- - `/catprompt reset`
87
- - `/dado`
88
- - `/down @user`
89
- - `/farewell`
90
- - `/groups`
91
- - `/info`
92
- - `/invite`
93
- - `/join`
94
- - `/leave`
95
- - `/menu anime`
96
- - `/menu figurinhas`
97
- - `/menu ia`
98
- - `/menu midia`
99
- - `/menu quote`
100
- - `/menu stats`
101
- - `/menuadm`
102
- - `/metadata`
103
- - `/newgroup`
104
- - `/noticias`
105
- - `/nsfw`
106
- - `/pack add`
107
- - `/pack create "Meu Pack"`
108
- - `/pack list`
109
- - `/pack send`
110
- - `/ping`
111
- - `/play`
112
- - `/playvid`
113
- - `/prefix`
114
- - `/premium`
115
- - `/quote`
116
- - `/ranking`
117
- - `/rankingglobal`
118
- - `/requests`
119
- - `/revoke`
120
- - `/s`
121
- - `/semmsg`
122
- - `/setdesc`
123
- - `/setgroup`
124
- - `/setsubject`
125
- - `/st`
126
- - `/stb`
127
- - `/sticker`
128
- - `/stickertext`
129
- - `/stickertextblink`
130
- - `/stickertextwhite`
131
- - `/stw`
132
- - `/temp`
133
- - `/tiktok`
134
- - `/toimg`
135
- - `/up @user`
136
- - `/updaterequests`
137
- - `/user perfil`
138
- - `/welcome`
54
+ ### Snapshot do Sistema
55
+
56
+ > Atualizado em `2026-02-28T01:18:30.283Z` | cache `1800s`
57
+
58
+ | Métrica | Valor |
59
+ | --- | ---: |
60
+ | Usuários (lid_map) | 5.502 |
61
+ | Grupos | 116 |
62
+ | Packs | 295 |
63
+ | Stickers | 6.314 |
64
+ | Mensagens registradas | 438.975 |
65
+
66
+ #### Tipos de mensagem mais usados (amostra: 25.000)
67
+ | Tipo | Total |
68
+ | --- | ---: |
69
+ | `texto` | 16.526 |
70
+ | `figurinha` | 4.263 |
71
+ | `reacao` | 1.619 |
72
+ | `imagem` | 1.326 |
73
+ | `outros` | 800 |
74
+ | `video` | 245 |
75
+ | `audio` | 215 |
76
+ | `documento` | 6 |
77
+
78
+ <details><summary>Comandos disponíveis (62)</summary>
79
+
80
+ `/add` · `/addmode` · `/autorequests` · `/autosticker` · `/ban` · `/captcha` · `/cat` · `/catimg` · `/catprompt` · `/catprompt reset` · `/dado` · `/down` · `/farewell` · `/groups` · `/info` · `/invite` · `/join` · `/leave` · `/menu anime` · `/menu figurinhas` · `/menu ia` · `/menu midia` · `/menu quote` · `/menu stats` · `/menuadm` · `/metadata` · `/newgroup` · `/noticias` · `/nsfw` · `/pack add` · `/pack create` · `/pack list` · `/pack send` · `/ping` · `/play` · `/playvid` · `/prefix` · `/premium` · `/quote` · `/ranking` · `/rankingglobal` · `/requests` · `/revoke` · `/s` · `/semmsg` · `/setdesc` · `/setgroup` · `/setsubject` · `/st` · `/stb` · `/sticker` · `/stickertext` · `/stickertextblink` · `/stickertextwhite` · `/stw` · `/temp` · `/tiktok` · `/toimg` · `/up` · `/updaterequests` · `/user perfil` · `/welcome`
81
+
82
+ </details>
139
83
  <!-- README_SNAPSHOT:END -->
140
84
 
141
85
  ## Recursos principais
@@ -9,7 +9,7 @@ import { handleRankingCommand } from '../modules/statsModule/rankingCommand.js';
9
9
  import { handleGlobalRankingCommand } from '../modules/statsModule/globalRankingCommand.js';
10
10
  import { handleNoMessageCommand } from '../modules/statsModule/noMessageCommand.js';
11
11
  import { handlePingCommand } from '../modules/systemMetricsModule/pingCommand.js';
12
- import { extractMessageContent, getExpiration, isGroupJid, isSameJidUser, resolveBotJid } from '../config/baileysConfig.js';
12
+ import { extractMessageContent, getExpiration, getJidServer, getJidUser, isGroupJid, isSameJidUser, normalizeJid, resolveBotJid } from '../config/baileysConfig.js';
13
13
  import logger from '../utils/logger/loggerModule.js';
14
14
  import { handleAntiLink } from '../utils/antiLink/antiLinkModule.js';
15
15
  import { handleCatCommand, handleCatImageCommand, handleCatPromptCommand } from '../modules/aiModule/catCommand.js';
@@ -25,9 +25,125 @@ import { handleRpgPokemonCommand } from '../modules/rpgPokemonModule/rpgPokemonC
25
25
  import groupConfigStore from '../store/groupConfigStore.js';
26
26
  import { sendAndStore } from '../services/messagePersistenceService.js';
27
27
  import { resolveCaptchaByMessage } from '../services/captchaService.js';
28
+ import { extractSenderInfoFromMessage, resolveUserId } from '../services/lidMapService.js';
29
+ import { buildWhatsAppGoogleLoginUrl } from '../services/whatsappLoginLinkService.js';
28
30
 
29
31
  const DEFAULT_COMMAND_PREFIX = process.env.COMMAND_PREFIX || '/';
30
32
  const COMMAND_REACT_EMOJI = process.env.COMMAND_REACT_EMOJI || '🤖';
33
+ const START_LOGIN_TRIGGER = String(process.env.WHATSAPP_LOGIN_TRIGGER || 'iniciar')
34
+ .trim()
35
+ .toLowerCase() || 'iniciar';
36
+ const WHATSAPP_USER_SERVERS = new Set(['s.whatsapp.net', 'c.us', 'hosted']);
37
+ const WHATSAPP_LID_SERVERS = new Set(['lid', 'hosted.lid']);
38
+
39
+ const normalizeTriggerText = (value) =>
40
+ String(value || '')
41
+ .trim()
42
+ .toLowerCase()
43
+ .normalize('NFD')
44
+ .replace(/[\u0300-\u036f]/g, '');
45
+
46
+ const isStartLoginTrigger = (text) => normalizeTriggerText(text) === START_LOGIN_TRIGGER;
47
+
48
+ const resolveCanonicalWhatsAppJid = (...candidates) => {
49
+ for (const candidate of candidates) {
50
+ const normalized = normalizeJid(String(candidate || '').trim());
51
+ if (!normalized) continue;
52
+ const server = getJidServer(normalized);
53
+ if (!WHATSAPP_USER_SERVERS.has(server) && !WHATSAPP_LID_SERVERS.has(server)) continue;
54
+ const user = String(getJidUser(normalized) || '')
55
+ .split(':')[0]
56
+ .replace(/\D+/g, '');
57
+ if (!user) continue;
58
+ if (user.length < 10 || user.length > 15) continue;
59
+ return normalizeJid(`${user}@s.whatsapp.net`) || normalized;
60
+ }
61
+ return '';
62
+ };
63
+
64
+ const maybeHandleStartLoginMessage = async ({
65
+ sock,
66
+ messageInfo,
67
+ extractedText,
68
+ senderName,
69
+ senderJid,
70
+ remoteJid,
71
+ expirationMessage,
72
+ isMessageFromBot,
73
+ isGroupMessage,
74
+ }) => {
75
+ if (isMessageFromBot || !isStartLoginTrigger(extractedText)) return false;
76
+
77
+ if (isGroupMessage) {
78
+ await sendAndStore(
79
+ sock,
80
+ remoteJid,
81
+ {
82
+ text: 'Por seguranca, envie *iniciar* no privado do bot para receber seu link de login.',
83
+ },
84
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
85
+ );
86
+ return true;
87
+ }
88
+
89
+ const key = messageInfo?.key || {};
90
+ const senderInfo = extractSenderInfoFromMessage(messageInfo);
91
+ let canonicalUserId = resolveCanonicalWhatsAppJid(
92
+ senderInfo?.jid,
93
+ senderInfo?.lid,
94
+ senderInfo?.participantAlt,
95
+ key.participantAlt,
96
+ key.participant,
97
+ key.remoteJid,
98
+ senderJid,
99
+ );
100
+ try {
101
+ const resolvedUserId = await resolveUserId(senderInfo);
102
+ canonicalUserId = resolveCanonicalWhatsAppJid(resolvedUserId, canonicalUserId, senderInfo?.jid, senderInfo?.lid);
103
+ } catch (error) {
104
+ logger.warn('Falha ao resolver ID canonico para fluxo de login do WhatsApp.', {
105
+ error: error?.message,
106
+ });
107
+ }
108
+
109
+ const loginUrl = buildWhatsAppGoogleLoginUrl({ userId: canonicalUserId });
110
+ if (!loginUrl) {
111
+ logger.warn('Nao foi possivel montar link de login para mensagem "iniciar".', {
112
+ action: 'login_link_missing_user_phone',
113
+ remoteServer: getJidServer(key.remoteJid || ''),
114
+ participantServer: getJidServer(key.participant || ''),
115
+ participantAltServer: getJidServer(key.participantAlt || ''),
116
+ hasLid: Boolean(senderInfo?.lid),
117
+ hasJid: Boolean(senderInfo?.jid),
118
+ });
119
+ await sendAndStore(
120
+ sock,
121
+ remoteJid,
122
+ {
123
+ text: 'Nao consegui identificar seu numero de WhatsApp para o login. Tente novamente em alguns segundos.',
124
+ },
125
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
126
+ );
127
+ return true;
128
+ }
129
+
130
+ const safeName = String(senderName || '').trim();
131
+ const greeting = safeName ? `Oi, *${safeName}*!` : 'Oi!';
132
+ await sendAndStore(
133
+ sock,
134
+ remoteJid,
135
+ {
136
+ text:
137
+ `${greeting}\n\n` +
138
+ 'Para continuar no OmniZap, faca login com Google neste link:\n' +
139
+ `${loginUrl}\n\n` +
140
+ 'Seu numero do WhatsApp sera vinculado automaticamente a conta logada.',
141
+ },
142
+ { quoted: messageInfo, ephemeralExpiration: expirationMessage },
143
+ );
144
+
145
+ return true;
146
+ };
31
147
 
32
148
  /**
33
149
  * Resolve o prefixo de comandos.
@@ -111,6 +227,22 @@ export const handleMessages = async (update, sock) => {
111
227
  });
112
228
  }
113
229
 
230
+ const handledStartLogin = await maybeHandleStartLoginMessage({
231
+ sock,
232
+ messageInfo,
233
+ extractedText,
234
+ senderName,
235
+ senderJid,
236
+ remoteJid,
237
+ expirationMessage,
238
+ isMessageFromBot,
239
+ isGroupMessage,
240
+ });
241
+
242
+ if (handledStartLogin) {
243
+ continue;
244
+ }
245
+
114
246
  /**
115
247
  * Envia uma reação automática quando a mensagem começa com o prefixo de comando.
116
248
  * A falha no envio da reação não interrompe o processamento do comando.