This commit is contained in:
Flummi 2018-09-08 19:38:20 +02:00
parent 31a633bda6
commit 7423f2ae3a
2 changed files with 14 additions and 3 deletions

View File

@ -77,7 +77,7 @@ export class tg extends EventEmitter {
if(msg.length === 0 || msg.length > 2048) if(msg.length === 0 || msg.length > 2048)
return false; return false;
const opts = { const opts = {
method: 'POST', method: "POST",
body: { body: {
chat_id: chatid, chat_id: chatid,
text: msg, text: msg,

View File

@ -3,11 +3,21 @@ import https from "https";
import url from "url"; import url from "url";
export default (a, options = {}, link = url.parse(a)) => new Promise((resolve, reject) => { export default (a, options = {}, link = url.parse(a)) => new Promise((resolve, reject) => {
(link.protocol === "https:"?https:http).get({...{ options = {...{
hostname: link.hostname, hostname: link.hostname,
path: link.path, path: link.path,
method: "GET" 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") .setEncoding("utf8")
.on("data", chunk => data += chunk) .on("data", chunk => data += chunk)
.on("end", () => resolve({ .on("end", () => resolve({
@ -16,4 +26,5 @@ export default (a, options = {}, link = url.parse(a)) => new Promise((resolve, r
buffer: () => new Buffer.from(data) buffer: () => new Buffer.from(data)
})) }))
).on("error", err => reject(err)); ).on("error", err => reject(err));
post.end(body);
}); });