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 = (updateObject)=>{
|
module.exports = (messageObject)=>{
|
||||||
|
if(makeResponse.canRespond(messageObject.text)){
|
||||||
|
console.log(makeResponse.getCommand(messageObject.text))
|
||||||
return {
|
return {
|
||||||
"chat_id": updateObject.from.id,
|
"chat_id": messageObject.from.id,
|
||||||
"text":updateObject.text,
|
"text": makeResponse.getPredicate(messageObject.text),
|
||||||
"reply_to_message_id": updateObject.message_id
|
"parse_mode": "Markdown",
|
||||||
|
"reply_to_message_id": messageObject.message_id
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return null
|
||||||
}
|
}
|
||||||
//return JSON.stringify(updateObject)
|
|
||||||
}
|
}
|
@@ -7,6 +7,8 @@ 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))
|
||||||
|
if(responseObject)
|
||||||
|
{
|
||||||
request.post({
|
request.post({
|
||||||
"url":`${base}sendMessage`,
|
"url":`${base}sendMessage`,
|
||||||
"json":true,
|
"json":true,
|
||||||
@@ -17,3 +19,4 @@ module.exports.call = (base,updateObject)=>{
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user