multiple user ids for bot api
This commit is contained in:
1 parent
870118d5ab
commit
31d03bcb14
8 files changed
+59
-44
No files matched your search
@@ -151,7 +151,11 @@ export class BotManager {
|
||||
|
||||
console.log('[BOT] Message from', fromId, ':', text, 'payload:', payload);
|
||||
|
||||
if (this.settings.userId && fromId.toString() !== this.settings.userId.toString()) {
|
||||
const allowedIds = this.settings.userId
|
||||
.split(',')
|
||||
.map((id) => id.trim())
|
||||
.filter((id) => id.length > 0);
|
||||
if (allowedIds.length > 0 && !allowedIds.includes(fromId.toString())) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -152,15 +152,6 @@ export class TabManager {
|
||||
return this.callStatusCache.get(tabId) || CallStatus.Inactive;
|
||||
}
|
||||
|
||||
findBotPeerId(platform: Platform): number | null {
|
||||
for (const [tabId, tab] of this.tabs) {
|
||||
if (this.botTabIds.has(tabId) && tab.platform === platform && tab.peerId != null) {
|
||||
return tab.peerId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
getTabList(): TabListEntry[] {
|
||||
const result: TabListEntry[] = [];
|
||||
this.tabs.forEach((tab, tabId) => {
|
||||
|
||||
@@ -31,10 +31,12 @@ function parseCallStatus(msg: string): { tabId: string; status: CallStatus } | n
|
||||
};
|
||||
}
|
||||
|
||||
function extractCallLink(msg: string, prefix: string): string | null {
|
||||
const idx = msg.indexOf(prefix);
|
||||
if (idx === -1) return null;
|
||||
return msg.split(prefix)[1].trim();
|
||||
function extractTaggedCallLink(msg: string, platform: Platform): { tabId: string; link: string } | null {
|
||||
const tag = platform === Platform.Telemost ? 'Telemost' : 'VKCalls';
|
||||
const re = new RegExp('\\[BOT\\] ' + tag + '\\[([^\\]]*)\\]: call link:\\s*(.+)$');
|
||||
const match = msg.match(re);
|
||||
if (!match) return null;
|
||||
return { tabId: match[1].trim(), link: match[2].trim() };
|
||||
}
|
||||
|
||||
export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
@@ -97,8 +99,8 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
if (ac) ac.vk.kickDisconnected();
|
||||
}
|
||||
|
||||
handleBotCallLink(tabManager, msg, Platform.VK, '[BOT] VKCalls: call link:');
|
||||
handleBotCallLink(tabManager, msg, Platform.Telemost, '[BOT] Telemost: call link:');
|
||||
handleBotCallLink(tabManager, msg, Platform.VK);
|
||||
handleBotCallLink(tabManager, msg, Platform.Telemost);
|
||||
|
||||
const callStatus = parseCallStatus(msg);
|
||||
if (callStatus) {
|
||||
@@ -120,18 +122,16 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
return win;
|
||||
}
|
||||
|
||||
function handleBotCallLink(
|
||||
tabManager: TabManager,
|
||||
msg: string,
|
||||
platform: Platform,
|
||||
prefix: string,
|
||||
): void {
|
||||
const link = extractCallLink(msg, prefix);
|
||||
if (!link) return;
|
||||
console.log(`[MAIN] ${platform} call link captured:`, link);
|
||||
const peerId = tabManager.findBotPeerId(platform);
|
||||
if (peerId != null && tabManager.botManager) {
|
||||
console.log(`[MAIN] Sending ${platform} link to peer:`, peerId);
|
||||
tabManager.botManager.sendMessage(peerId, `Call created!\n ${link}`);
|
||||
function handleBotCallLink(tabManager: TabManager, msg: string, platform: Platform): void {
|
||||
const tagged = extractTaggedCallLink(msg, platform);
|
||||
if (!tagged) return;
|
||||
const tab = tabManager.getTab(tagged.tabId);
|
||||
if (!tab || tab.peerId == null) {
|
||||
console.log(`[MAIN] ${platform} call link captured but no peer for tab ${tagged.tabId}`);
|
||||
return;
|
||||
}
|
||||
console.log(`[MAIN] Sending ${platform} link to peer ${tab.peerId} (tab ${tagged.tabId}):`, tagged.link);
|
||||
if (tabManager.botManager) {
|
||||
tabManager.botManager.sendMessage(tab.peerId, `Call created!\n${tagged.link}`);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user