forked from ariffb25/stikerinbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch.js
27 lines (25 loc) · 931 Bytes
/
fetch.js
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
let fetch = require('node-fetch')
let util = require('util')
let handler = async (m, { text }) => {
if (!/^https?:\/\//.test(text)) throw 'Awali *URL* dengan http:// atau https://'
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
throw `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 = util.format(JSON.parse(txt+''))
} catch (e) {
txt = txt + ''
} finally {
m.reply(txt.slice(0, 65536) + '')
}
}
handler.help = ['fetch', 'get'].map(v => v + ' <url>')
handler.tags = ['internet']
handler.command = /^(fetch|get)$/i
module.exports = handler