File size: 4,547 Bytes
f29c287
90a4922
f29c287
bd18039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f29c287
bd18039
f29c287
bd18039
f29c287
90a4922
bd18039
 
f29c287
bd18039
 
90a4922
f29c287
90a4922
bd18039
90a4922
 
 
 
bd18039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f29c287
90a4922
bd18039
 
 
f29c287
bd18039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f29c287
bd18039
 
 
 
 
 
 
 
 
 
 
 
 
 
f29c287
bd18039
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
const axios = require('axios');
const cheerio = require('cheerio');

const userAgents = [
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',
    'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
    'Mozilla/5.0 (iPhone; CPU iPhone OS 17_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Mobile/15E148 Safari/604.1'
];

const getHeaders = () => ({
    'User-Agent': userAgents[Math.floor(Math.random() * userAgents.length)],
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'DNT': '1',
    'Connection': 'keep-alive',
    'Upgrade-Insecure-Requests': '1'
});

/**
 * UPLINK_PRIMARY: DuckDuckGo Lite
 */
const tryDDG = async (query) => {
    try {
        const response = await axios.get(`https://duckduckgo.com/lite/?q=${encodeURIComponent(query)}`, {
            headers: getHeaders(),
            timeout: 5000
        });
        if (response.data.includes('Unfortunately, bots use DuckDuckGo too')) return null;
        
        const $ = cheerio.load(response.data);
        const results = [];
        $('a.result-link').each((i, el) => {
            if (i >= 3) return false;
            const title = $(el).text().trim();
            let url = $(el).attr('href');
            if (url && title) {
                if (url.startsWith('//')) url = 'https:' + url;
                results.push({ url, title, snippet: "Verified DDG Uplink." });
            }
        });
        return results.length > 0 ? results : null;
    } catch (e) { return null; }
};

/**
 * UPLINK_SECONDARY: Ask.com (Highly Leniency)
 */
const tryAsk = async (query) => {
    try {
        const response = await axios.get(`https://www.ask.com/web?q=${encodeURIComponent(query)}`, {
            headers: getHeaders(),
            timeout: 5000
        });
        const $ = cheerio.load(response.data);
        const results = [];
        $('.PartialSearchResults-item').each((i, el) => {
            if (i >= 3) return false;
            const title = $(el).find('.PartialSearchResults-item-title').text().trim();
            const url = $(el).find('.PartialSearchResults-item-title a').attr('href');
            const snippet = $(el).find('.PartialSearchResults-item-abstract').text().trim();
            if (title && url) {
                results.push({ url, title, snippet: snippet || "Live data packet." });
            }
        });
        return results.length > 0 ? results : null;
    } catch (e) { return null; }
};

/**
 * UPLINK_TERTIARY: Bing (Mobile Interface)
 */
const tryBing = async (query) => {
    try {
        const response = await axios.get(`https://www.bing.com/search?q=${encodeURIComponent(query)}`, {
            headers: getHeaders(),
            timeout: 5000
        });
        const $ = cheerio.load(response.data);
        const results = [];
        $('.b_algo').each((i, el) => {
            if (i >= 3) return false;
            const title = $(el).find('h2').text().trim();
            const url = $(el).find('a').attr('href');
            if (title && url && url.startsWith('http')) {
                results.push({ url, title, snippet: "Bing Neural Link." });
            }
        });
        return results.length > 0 ? results : null;
    } catch (e) { return null; }
};

/**
 * FREE_UNLIMITED_SEARCH
 * Multi-Sector pivoting to ensure data retrieval.
 */
exports.searchWeb = async (query) => {
    console.log(`[Neural_Search] Initiating multi-sector scan for: ${query}`);
    
    // Try DDG first
    let results = await tryDDG(query);
    
    // If DDG fails, pivot to Ask
    if (!results) {
        console.log("[Neural_Search] Primary sector (DDG) shielded. Pivoting to Ask.com...");
        results = await tryAsk(query);
    }

    // If Ask fails, pivot to Bing
    if (!results) {
        console.log("[Neural_Search] Secondary sector (Ask) offline. Pivoting to Bing...");
        results = await tryBing(query);
    }

    if (!results || results.length === 0) {
        return "[SEARCH_OFFLINE]: All web sectors are temporarily shielded by bot protection. The collective is unable to establish a live link at this millisecond.";
    }

    return results.map(r => `SOURCE: ${r.url}\nTITLE: ${r.title}\nINFO: ${r.snippet}`).join('\n\n');
};