post lol
This commit is contained in:
parent
31a633bda6
commit
7423f2ae3a
@ -77,7 +77,7 @@ export class tg extends EventEmitter {
|
||||
if(msg.length === 0 || msg.length > 2048)
|
||||
return false;
|
||||
const opts = {
|
||||
method: 'POST',
|
||||
method: "POST",
|
||||
body: {
|
||||
chat_id: chatid,
|
||||
text: msg,
|
||||
|
@ -3,11 +3,21 @@ import https from "https";
|
||||
import url from "url";
|
||||
|
||||
export default (a, options = {}, link = url.parse(a)) => new Promise((resolve, reject) => {
|
||||
(link.protocol === "https:"?https:http).get({...{
|
||||
options = {...{
|
||||
hostname: link.hostname,
|
||||
path: link.path,
|
||||
method: "GET"
|
||||
}, ...options}, (res, data = "") => res
|
||||
}, ...options};
|
||||
let body = "";
|
||||
if(options.method === "POST") {
|
||||
body = JSON.stringify(options.body);
|
||||
delete options.body;
|
||||
options.headers = {
|
||||
"Content-Type": "application/x-www-form-urlencoded",
|
||||
"Content-Length": Buffer.byteLength(body)
|
||||
}
|
||||
}
|
||||
const post = (link.protocol === "https:"?https:http).request(options, (res, data = "") => res
|
||||
.setEncoding("utf8")
|
||||
.on("data", chunk => data += chunk)
|
||||
.on("end", () => resolve({
|
||||
@ -16,4 +26,5 @@ export default (a, options = {}, link = url.parse(a)) => new Promise((resolve, r
|
||||
buffer: () => new Buffer.from(data)
|
||||
}))
|
||||
).on("error", err => reject(err));
|
||||
post.end(body);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user