Basic response filtering
This commit is contained in:
22
scripts/makeResponse.js
Normal file
22
scripts/makeResponse.js
Normal file
@@ -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=>{
|
||||||
|
|
||||||
|
}
|
@@ -1,10 +1,18 @@
|
|||||||
// Obtain a sendMessage Object
|
// 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
|
||||||
|
}
|
||||||
}
|
}
|
@@ -7,13 +7,16 @@ module.exports.call = (base,updateObject)=>{
|
|||||||
if('message' in updateObject){
|
if('message' in updateObject){
|
||||||
let responseObject = process(updateObject.message)
|
let responseObject = process(updateObject.message)
|
||||||
//console.log(process.process(updateObject.message))
|
//console.log(process.process(updateObject.message))
|
||||||
request.post({
|
if(responseObject)
|
||||||
"url":`${base}sendMessage`,
|
{
|
||||||
"json":true,
|
request.post({
|
||||||
"body":responseObject
|
"url":`${base}sendMessage`,
|
||||||
},(err,res,body)=>{
|
"json":true,
|
||||||
if(err) console.log(err)
|
"body":responseObject
|
||||||
if(body.ok) console.log("Successfully sent")
|
},(err,res,body)=>{
|
||||||
})
|
if(err) console.log(err)
|
||||||
|
if(body.ok) console.log("Successfully sent")
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user