-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
45 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,50 @@ | ||
import fetch from 'node-fetch' | ||
import { format } from 'util' | ||
let handler = async (m, { text }) => { | ||
if (!/^https?:\/\//.test(text)) throw 'Ejemplo:\nhttps://pornhub.com' | ||
let _url = new URL(text) | ||
let url = global.API(_url.origin, _url.pathname, Object.fromEntries(_url.searchParams.entries()), 'APIKEY') | ||
let res = await fetch(url) | ||
if (res.headers.get('content-length') > 100 * 1024 * 1024 * 1024) { | ||
// delete res | ||
return m.reply(`Content-Length: ${res.headers.get('content-length')}`) | ||
} | ||
if (!/text|json/.test(res.headers.get('content-type'))) return conn.sendFile(m.chat, url, 'file', text, m) | ||
let txt = await res.buffer() | ||
try { | ||
txt = format(JSON.parse(txt + '')) | ||
} catch (e) { | ||
txt = txt + '' | ||
} finally { | ||
m.reply(txt.slice(0, 65536) + '') | ||
} | ||
|
||
let handler = async (m, { text, conn }) => { | ||
if (!/^https?:\/\//.test(text)) return conn.reply(m.chat, 'Ejemplo:\nhttps://pornhub.com', m) | ||
let _url = new URL(text) | ||
let url = global.API(_url.origin, _url.pathname, Object.fromEntries(_url.searchParams.entries()), 'APIKEY') | ||
let res = await fetch(url) | ||
if (res.headers.get('content-length') > 100 * 1024 * 1024 * 1024) { | ||
return m.reply(`Content-Length: ${res.headers.get('content-length')}`) | ||
} | ||
handler.help = ['fetch'].map(v => v + ' *<url>*') | ||
if (!/text|json/.test(res.headers.get('content-type'))) return conn.sendFile(m.chat, url, 'file', text, m) | ||
let txt = await res.buffer() | ||
try { | ||
txt = format(JSON.parse(txt + '')) | ||
} catch (e) { | ||
txt = txt + '' | ||
} finally { | ||
m.reply(txt.slice(0, 65536) + '') | ||
}} | ||
|
||
handler.help = ['fetch'].map(v => v + ' *( Link )*') | ||
handler.tags = ['owner'] | ||
handler.command = /^(fetch|get)$/i | ||
handler.command = ['fetch', 'get'] | ||
handler.rowner = true | ||
export default handler | ||
|
||
export default handler | ||
|
||
global.APIs = {} | ||
global.APIKeys = {} | ||
|
||
global.API = (name, path = "/", query = {}, apikeyqueryname) => | ||
(name in global.APIs ? global.APIs[name] : name) + | ||
path + | ||
(query || apikeyqueryname | ||
? "?" + | ||
new URLSearchParams( | ||
Object.entries({ | ||
...query, | ||
...(apikeyqueryname | ||
? { | ||
[apikeyqueryname]: | ||
global.APIKeys[ | ||
name in global.APIs ? global.APIs[name] : name | ||
], | ||
} | ||
: {}), | ||
}), | ||
) | ||
: ""); |