60 lines
No EOL
1.2 KiB
JavaScript
60 lines
No EOL
1.2 KiB
JavaScript
function first2k(string){
|
|
var sp = string.split("");
|
|
var end = [];
|
|
for(i=0;i<2000;i++){
|
|
if(sp[i] != undefined){
|
|
end.push(sp[i]);
|
|
}
|
|
}
|
|
return end.join("");
|
|
}
|
|
|
|
function stringify(res){
|
|
var end;
|
|
if(typeof(res) == "object"){
|
|
end = JSON.stringify(res);
|
|
} else{
|
|
end = res.toString();
|
|
}
|
|
return end;
|
|
}
|
|
|
|
module.exports = {
|
|
api: {
|
|
name: "post",
|
|
description: "Sends a POST request to URL provided through arguments and sends response.",
|
|
options: [
|
|
{
|
|
name: "url",
|
|
description: "URL to request.",
|
|
type: 3,
|
|
required: true
|
|
},
|
|
{
|
|
name: "body",
|
|
description: "The data to POST.",
|
|
type: 3,
|
|
required: false
|
|
},
|
|
{
|
|
name: "headers",
|
|
description: "The headers to use.",
|
|
type: 3,
|
|
required: false
|
|
}
|
|
]
|
|
},
|
|
run: (int, client, index) => {
|
|
const axios = require("axios").default;
|
|
int.reply("Sending a POST request to " + int.options.getString("url"));
|
|
try{
|
|
axios.request({method: "POST", url: int.options.getString("url"), data: int.options.getString("body"), headers: JSON.parse(int.options.getString("headers"))}).then(res => {
|
|
int.followUp(first2k(stringify(res.data)));
|
|
}).catch(e => {
|
|
int.followUp("Error: " + e.stack);
|
|
});
|
|
} catch(e){
|
|
int.followUp("Error: " + e.stack);
|
|
}
|
|
}
|
|
} |