diff --git a/creator-app/bot-manager.js b/creator-app/bot-manager.js new file mode 100644 index 0000000..f35b6e3 --- /dev/null +++ b/creator-app/bot-manager.js @@ -0,0 +1,122 @@ +const fetch = require('node-fetch'); + +class BotManager { + constructor(settings, onCreateTab) { + this.settings = settings; + this.onCreateTab = onCreateTab; + this.baseUrl = 'https://api.vk.com/method'; + this.ts = null; + this.key = null; + this.server = null; + this.running = false; + } + async api(method, params = {}) { + params.v = '5.131'; + params.access_token = this.settings.token; + const url = new URL(`${this.baseUrl}/${method}`); + Object.keys(params).forEach(k => url.searchParams.set(k, params[k])); + const res = await fetch(url); + const data = await res.json(); + + if (data.error) { + throw new Error(data.error.error_msg || 'VK API error'); + } + return data.response; + } + + async getLongPollServer() { + const data = await this.api('groups.getLongPollServer', { group_id: parseInt(this.settings.groupId) }); + this.server = data.server; + this.key = data.key; + this.ts = data.ts; + return data; + } + + async start() { + this.running = true; + console.log('[BOT] Starting with settings:', this.settings); + + try { + await this.getLongPollServer(); + console.log('[BOT] LongPoll server:', this.server); + this.pollLoop(); + } catch (err) { + console.error('[BOT] Failed to start:', err.message); + } + } + + stop() { + this.running = false; + console.log('[BOT] Stopped'); + } + + async pollLoop() { + while (this.running) { + try { + const url = `${this.server}?act=a_check&key=${this.key}&ts=${this.ts}&wait=25`; + const res = await fetch(url); + const data = await res.json(); + + if (data.failed) { + console.log('[BOT] LongPoll failed, reconnecting...'); + await this.getLongPollServer(); + continue; + } + this.ts = data.ts; + for (const update of data.updates) { + await this.handleUpdate(update); + } + } catch (err) { + console.error('[BOT] Poll error:', err.message); + await new Promise(r => setTimeout(r, 1000)); + } + } + } + + async handleUpdate(update) { + if (update.type === 'message_new') { + const message = update.object.message; + const text = message.text || ''; + const fromId = message.from_id; + const peerId = message.peer_id; + + if (this.settings.userId && fromId.toString() !== this.settings.userId.toString()) { + return; + } + + console.log('[BOT] Message from', fromId, ':', text); + + if (text.startsWith('/vk')) { + const mode = text.includes('video') ? 'pion-video' : 'dc'; + console.log('[BOT] Creating VK tab with mode:', mode); + + this.onCreateTab({ mode: mode, peerId: peerId, platform: 'vk' }); + await this.sendMessage(peerId, 'Creating VK call (' + (mode === 'dc' ? 'DC' : 'Video') + ')...'); + } + + if (text.startsWith('/tm')) { + const mode = text.includes('video') ? 'pion-video' : 'dc'; + console.log('[BOT] Creating Telemost tab with mode:', mode); + + this.onCreateTab({ mode: mode, peerId: peerId, platform: 'telemost' }); + + await this.sendMessage(peerId, 'Creating Telemost call (' + (mode === 'dc' ? 'DC' : 'Video') + ')...'); + } + } + } + + async sendMessage(peerId, text) { + try { + await this.api('messages.send', { + peer_id: peerId, + message: text, + random_id: Math.floor(Math.random() * 1e9) + }); + console.log('[BOT] Sent message to', peerId); + } catch (err) { + console.error('[BOT] Send message error:', err.message); + } + } +} + +module.exports = BotManager; diff --git a/creator-app/index.html b/creator-app/index.html index 69a347d..6e4108e 100644 --- a/creator-app/index.html +++ b/creator-app/index.html @@ -4,13 +4,20 @@ -
-
+
+
+
+
+
+
+
+
Settings
+
Bot: Off
+
+ + + diff --git a/creator-app/main.js b/creator-app/main.js index 917398c..42e3df6 100644 --- a/creator-app/main.js +++ b/creator-app/main.js @@ -4,6 +4,7 @@ const path = require('path'); const fs = require('fs'); const TelemostAutoclick = require('./telemost-autoclick'); const VkAutoclick = require('./vk-autoclick'); +const BotManager = require('./bot-manager'); var hooksDir = app.isPackaged ? path.join(process.resourcesPath, 'hooks') @@ -16,6 +17,8 @@ var relayPath = app.isPackaged var tabs = new Map(); // tabId -> { relay, tunnelMode, platform, dcPort, pionPort } var nextPortBase = 10000; var mainWindow = null; +var botManager = null; +var botTabs = new Set(); function allocPorts() { var dc = nextPortBase; @@ -156,6 +159,39 @@ function createWindow() { var ac = autoclickers.get(wvContents.id); if (ac) ac.vk.kickDisconnected(); } + if (msg.indexOf('[BOT] VKCalls: call link:') !== -1) { + var link = msg.split('[BOT] VKCalls: call link:')[1].trim(); + console.log('[MAIN] VK call link captured:', link); + + var foundPeerId = null; + tabs.forEach(function(t, id) { + if (botTabs.has(id) && t.platform === 'vk') { + foundPeerId = t.peerId; + } + }); + + if (foundPeerId && botManager) { + console.log('[MAIN] Sending VK link to peer:', foundPeerId); + botManager.sendMessage(foundPeerId, 'Call created!\n ' + link); + } + } + + if (msg.indexOf('[BOT] Telemost: call link:') !== -1) { + var link = msg.split('[BOT] Telemost: call link:')[1].trim(); + console.log('[MAIN] Telemost call link captured:', link); + + var foundPeerId = null; + tabs.forEach(function(t, id) { + if (botTabs.has(id) && t.platform === 'telemost') { + foundPeerId = t.peerId; + } + }); + + if (foundPeerId && botManager) { + console.log('[MAIN] Sending Telemost link to peer:', foundPeerId); + botManager.sendMessage(foundPeerId, 'Call created!\n ' + link); + } + } }); wvContents.on('destroyed', function() { var ac = autoclickers.get(wvContents.id); @@ -169,12 +205,17 @@ ipcMain.handle('get-hook-code', function(e, tabId, url) { return loadHook(url, tab); }); +ipcMain.handle('get-call-creator-code', function(e, scriptFile) { + var filePath = path.join(__dirname, scriptFile || 'vk-call-creator.js'); + return fs.readFileSync(filePath, 'utf8'); +}); + ipcMain.handle('set-tunnel-mode', function(e, tabId, mode) { var tab = tabs.get(tabId); if (!tab) return; if (['dc', 'pion-video'].indexOf(mode) === -1) return; tab.tunnelMode = mode; - killRelay(tab); + if (tab.relay) killRelay(tab); setTimeout(function() { startRelay(tab); }, 500); }); @@ -189,6 +230,35 @@ ipcMain.handle('close-tab', function(e, tabId) { killRelay(tab); tabs.delete(tabId); } + botTabs.delete(tabId); +}); + +// Bot IPC +ipcMain.handle('start-bot', function(e, settings) { + if (botManager) { + botManager.stop(); + } + botManager = new BotManager(settings, function(tabConfig) { + if (!mainWindow || mainWindow.isDestroyed()) return; + + var tabId = 'bot-tab-' + Date.now(); + var ports = allocPorts(); + tabs.set(tabId, { relay: null, tunnelMode: tabConfig.mode, platform: tabConfig.platform || 'vk', dcPort: ports.dc, pionPort: ports.pion, peerId: tabConfig.peerId }); + botTabs.add(tabId); + + mainWindow.webContents.send('create-bot-tab', { tabId: tabId, mode: tabConfig.mode, peerId: tabConfig.peerId, platform: tabConfig.platform || 'vk' }); + console.log('[BOT] Created tab:', tabId, 'mode:', tabConfig.mode, 'platform:', tabConfig.platform, 'peerId:', tabConfig.peerId); + }); + botManager.start(); + return { success: true }; +}); + +ipcMain.handle('stop-bot', function() { + if (botManager) { + botManager.stop(); + botManager = null; + } + return { success: true }; }); app.whenReady().then(createWindow); diff --git a/creator-app/package-lock.json b/creator-app/package-lock.json index ea95947..3b8b2fe 100644 --- a/creator-app/package-lock.json +++ b/creator-app/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "whitelist-bypass-creator", "version": "0.1.7", + "dependencies": { + "node-fetch": "^2.7.0" + }, "devDependencies": { "electron": "^33.0.0", "electron-builder": "^25.0.0" @@ -2414,7 +2417,6 @@ "version": "0.1.13", "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", - "dev": true, "license": "MIT", "optional": true, "dependencies": { @@ -3135,7 +3137,7 @@ "version": "0.6.3", "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", - "dev": true, + "devOptional": true, "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3.0.0" @@ -3918,6 +3920,26 @@ "node": ">=10" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/node-gyp": { "version": "9.4.1", "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-9.4.1.tgz", @@ -4500,7 +4522,7 @@ "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true, + "devOptional": true, "license": "MIT" }, "node_modules/sanitize-filename": { @@ -4953,6 +4975,12 @@ "tmp": "^0.2.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, "node_modules/truncate-utf8-bytes": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz", @@ -5084,6 +5112,22 @@ "defaults": "^1.0.3" } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/creator-app/package.json b/creator-app/package.json index a3972bc..455b0fc 100644 --- a/creator-app/package.json +++ b/creator-app/package.json @@ -6,6 +6,9 @@ "start": "electron .", "build": "electron-builder" }, + "dependencies": { + "node-fetch": "^2.7.0" + }, "devDependencies": { "electron": "^33.0.0", "electron-builder": "^25.0.0" diff --git a/creator-app/preload.js b/creator-app/preload.js index 84af1b5..9062d2d 100644 --- a/creator-app/preload.js +++ b/creator-app/preload.js @@ -5,5 +5,9 @@ contextBridge.exposeInMainWorld('bridge', { getHookCode: function(tabId, url) { return ipcRenderer.invoke('get-hook-code', tabId, url); }, setTunnelMode: function(tabId, mode) { return ipcRenderer.invoke('set-tunnel-mode', tabId, mode); }, startRelay: function(tabId) { return ipcRenderer.invoke('start-relay', tabId); }, - closeTab: function(tabId) { return ipcRenderer.invoke('close-tab', tabId); } + closeTab: function(tabId) { return ipcRenderer.invoke('close-tab', tabId); }, + startBot: function(settings) { return ipcRenderer.invoke('start-bot', settings); }, + stopBot: function() { return ipcRenderer.invoke('stop-bot'); }, + onCreateBotTab: function(cb) { ipcRenderer.on('create-bot-tab', function(e, data) { cb(data); }); }, + getCallCreatorCode: function(scriptFile) { return ipcRenderer.invoke('get-call-creator-code', scriptFile); } }); diff --git a/creator-app/tm-call-creator.js b/creator-app/tm-call-creator.js new file mode 100644 index 0000000..83072c7 --- /dev/null +++ b/creator-app/tm-call-creator.js @@ -0,0 +1,48 @@ +(function() { + if (window.__tmCallCreatorStarted) return; + window.__tmCallCreatorStarted = true; + + const start = () => { + console.log("[BOT] Telemost: DOM ready..."); + + const waitAndClick = (fn) => { + if (fn()) return; + + const observer = new MutationObserver(() => { + if (fn()) observer.disconnect(); + }); + + observer.observe(document.body, { childList: true, subtree: true }); + }; + + waitAndClick(() => { + const btn = document.querySelector('[data-testid="create-call-button"]'); + + if (btn) { + btn.click(); + console.log("[BOT] Telemost: creating call..."); + + const check = setInterval(() => { + const url = location.href; + + if (url.includes('/j/')) { + console.log("[BOT] Telemost: call link:", url); + window.__CALL_LINK__ = url; + clearInterval(check); + } + }, 300); + + return true; + } + + return false; + }); + }; + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", start); + } else { + start(); + } + +})(); diff --git a/creator-app/vk-call-creator.js b/creator-app/vk-call-creator.js new file mode 100644 index 0000000..80825bb --- /dev/null +++ b/creator-app/vk-call-creator.js @@ -0,0 +1,82 @@ +(function() { + if (window.__callCreatorStarted) return; + window.__callCreatorStarted = true; + + const start = () => { + console.log("[BOT] VKCalls: DOM ready..."); + + const waitAndClick = (fn) => { + if (fn()) return; + + const observer = new MutationObserver(() => { + if (fn()) observer.disconnect(); + }); + + observer.observe(document.body, { childList: true, subtree: true }); + }; + + waitAndClick(() => { + const trigger = document.getElementById('call-menu-trigger'); + + if (trigger) { + trigger.click(); + console.log("[BOT] VKCalls: opened call menu"); + + waitAndClick(() => { + const el = [...document.querySelectorAll('span')] + .find(e => e.textContent.includes('Создать звонок по')); + + const btn = el?.closest('button, div'); + + if (btn) { + btn.click(); + console.log("[BOT] VKCalls: created call"); + + const origFetch = window.fetch; + window.fetch = async (...args) => { + const res = await origFetch(...args); + + try { + const clone = res.clone(); + const text = await clone.text(); + + if (text.includes("call_in_progress")) { + const json = JSON.parse(text); + const items = json?.response?.[1]?.items; + + if (items) { + for (const item of items) { + const join = item?.call_in_progress?.join_link; + if (join) { + const link = "https://vk.com/call/join/" + join; + + console.log("[BOT] VKCalls: call link:", link); + window.__CALL_LINK__ = link; + } + } + } + } + } catch (e) {} + + return res; + }; + + return true; + } + return false; + }); + + return true; + } + + return false; + }); + }; + + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", start); + } else { + start(); + } + +})();