Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
AleXD0009 authored Sep 30, 2024
1 parent ce3a74f commit 4497199
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions plugins/owner-fetch.js
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
],
}
: {}),
}),
)
: "");

0 comments on commit 4497199

Please sign in to comment.