From 2e72d1bd8edd02a5396d2e707a6fc11b5e60728b Mon Sep 17 00:00:00 2001 From: Christopher Rose Date: Mon, 5 Aug 2019 21:59:54 +0530 Subject: [PATCH] Basic response filtering --- scripts/makeResponse.js | 22 ++++++++++++++++++++++ scripts/process.js | 20 ++++++++++++++------ scripts/respond.js | 19 +++++++++++-------- 3 files changed, 47 insertions(+), 14 deletions(-) create mode 100644 scripts/makeResponse.js diff --git a/scripts/makeResponse.js b/scripts/makeResponse.js new file mode 100644 index 0000000..bb78cdb --- /dev/null +++ b/scripts/makeResponse.js @@ -0,0 +1,22 @@ +// Make a response e + +//Check if can be responded to +exports.canRespond = msg=>{ + //let words = msg.split(" ") + return('!'==msg[0]) +} + +exports.getCommand = msg=>{ + let words = msg.split(" ") + return words[0].substring(1) +} + +exports.getPredicate = msg=>{ + let pred = msg.split(" ") + pred.shift(); + return pred.join(" ") +} + +exports.magnet = searchterm=>{ + +} \ No newline at end of file diff --git a/scripts/process.js b/scripts/process.js index a7080e6..f9c1743 100644 --- a/scripts/process.js +++ b/scripts/process.js @@ -1,10 +1,18 @@ // Obtain a sendMessage Object +const makeResponse = require('./makeResponse') + +module.exports = (messageObject)=>{ + if(makeResponse.canRespond(messageObject.text)){ + console.log(makeResponse.getCommand(messageObject.text)) + return { + "chat_id": messageObject.from.id, + "text": makeResponse.getPredicate(messageObject.text), + "parse_mode": "Markdown", + "reply_to_message_id": messageObject.message_id + } -module.exports = (updateObject)=>{ - return { - "chat_id": updateObject.from.id, - "text":updateObject.text, - "reply_to_message_id": updateObject.message_id } - //return JSON.stringify(updateObject) + else{ + return null + } } \ No newline at end of file diff --git a/scripts/respond.js b/scripts/respond.js index a21cc07..cec9bf5 100644 --- a/scripts/respond.js +++ b/scripts/respond.js @@ -7,13 +7,16 @@ module.exports.call = (base,updateObject)=>{ if('message' in updateObject){ let responseObject = process(updateObject.message) //console.log(process.process(updateObject.message)) - request.post({ - "url":`${base}sendMessage`, - "json":true, - "body":responseObject - },(err,res,body)=>{ - if(err) console.log(err) - if(body.ok) console.log("Successfully sent") - }) + if(responseObject) + { + request.post({ + "url":`${base}sendMessage`, + "json":true, + "body":responseObject + },(err,res,body)=>{ + if(err) console.log(err) + if(body.ok) console.log("Successfully sent") + }) + } } } \ No newline at end of file