83 lines
1.8 KiB
JavaScript
83 lines
1.8 KiB
JavaScript
const fs = require('fs');
|
|
|
|
const Markup = require('telegraf/markup');
|
|
const Extra = require('telegraf/extra');
|
|
|
|
const request = require('request');
|
|
|
|
//=== TOOL FUNCTIONS
|
|
|
|
//=== MAIN MODULE CONFIG
|
|
|
|
module.exports = function(url, cmds){
|
|
this.url = url;
|
|
|
|
return {
|
|
name : "APIreq",
|
|
version : 0.1,
|
|
requirements : {
|
|
gps: false,
|
|
},
|
|
text : [
|
|
{
|
|
trigger : cmds,
|
|
requirements : (bot,event,message)=>{
|
|
return new Promise((resolve, reject)=>{
|
|
return resolve(200);
|
|
});
|
|
},
|
|
action : (bot,event,message)=>{
|
|
|
|
let options = {
|
|
url: this.url,
|
|
qs:{
|
|
chat_id:message.chat.id,
|
|
user_id: message.from.id,
|
|
user_name: message.from.name,
|
|
message: message.text,
|
|
args: message.text_arg,
|
|
}
|
|
};
|
|
return new Promise((resolve,reject)=>{
|
|
return request(options, function (err, response, body) {
|
|
if (err) {
|
|
//bot.error(err);
|
|
return reject(err);
|
|
}
|
|
|
|
if (response.statusCode != 200 ){
|
|
//bot.error(response.statusCode);
|
|
return reject(500);//response.statusCode);
|
|
}
|
|
var resp = JSON.parse(body)
|
|
if(resp.reply==undefined || resp.reply=='')
|
|
resp.reply = "BeepBoop";
|
|
event.reply(resp.reply).catch(err=>bot.error(err));
|
|
return resolve(200);
|
|
|
|
});
|
|
});
|
|
}
|
|
},
|
|
],
|
|
reply : [],
|
|
regex : [],
|
|
media : [],
|
|
callback : [],
|
|
inline : [],
|
|
new_member : (bot,event)=>{},
|
|
weburl : [{
|
|
url : 'self',
|
|
post_action : (bot,req,rep)=>{
|
|
},
|
|
get_action : (bot,req,rep)=>{
|
|
rep.type('application/json').code(200).send({reply: req.query.args });
|
|
},
|
|
|
|
}],
|
|
cron : []
|
|
};
|
|
|
|
|
|
|
|
} |