Search basics
This commit is contained in:
912
package-lock.json
generated
912
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@
|
|||||||
"eslint": "^5.15.1"
|
"eslint": "^5.15.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"leetx": "0.0.3",
|
"request": "^2.88.0",
|
||||||
"request": "^2.88.0"
|
"torrent-search-api": "^2.0.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
const tsa = require('torrent-search-api')
|
||||||
|
tsa.enableProvider('ThePirateBay')
|
||||||
// Make a response e
|
// Make a response e
|
||||||
|
|
||||||
//Check if can be responded to
|
//Check if can be responded to
|
||||||
@@ -17,6 +19,15 @@ exports.getPredicate = msg=>{
|
|||||||
return pred.join(" ")
|
return pred.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.magnet = searchterm=>{
|
exports.magnet = async searchterm=>{
|
||||||
|
console.log(`Search for:${searchterm}`)
|
||||||
|
let result = await tsa.search(searchterm,5)
|
||||||
|
let resultString=''
|
||||||
|
for(let i=0;i<3;i++){
|
||||||
|
let magnet = await tsa.getMagnet(result[i]) || ' '
|
||||||
|
resultString = resultString + `*${result[i].title.replace(/[\[\]]/g,'')}* - ${magnet}\n`
|
||||||
|
}
|
||||||
|
console.log(resultString)
|
||||||
|
//console.log(await tsa.getMagnet(result[0]))
|
||||||
|
return resultString
|
||||||
}
|
}
|
@@ -1,12 +1,12 @@
|
|||||||
// Obtain a sendMessage Object
|
// Obtain a sendMessage Object
|
||||||
const makeResponse = require('./makeResponse')
|
const makeResponse = require('./makeResponse')
|
||||||
|
|
||||||
module.exports = (messageObject)=>{
|
module.exports = async (messageObject)=>{
|
||||||
if(makeResponse.canRespond(messageObject.text)){
|
if(makeResponse.canRespond(messageObject.text)){
|
||||||
console.log(makeResponse.getCommand(messageObject.text))
|
console.log(makeResponse.getCommand(messageObject.text))
|
||||||
return {
|
return {
|
||||||
"chat_id": messageObject.from.id,
|
"chat_id": messageObject.from.id,
|
||||||
"text": makeResponse.getPredicate(messageObject.text),
|
"text": await makeResponse.magnet( makeResponse.getPredicate(messageObject.text)),
|
||||||
"parse_mode": "Markdown",
|
"parse_mode": "Markdown",
|
||||||
"reply_to_message_id": messageObject.message_id
|
"reply_to_message_id": messageObject.message_id
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,9 @@
|
|||||||
const process = require('./process')
|
const process = require('./process')
|
||||||
const request = require('request')
|
const request = require('request')
|
||||||
|
|
||||||
module.exports.call = (base,updateObject)=>{
|
module.exports.call = async (base,updateObject)=>{
|
||||||
if('message' in updateObject){
|
if('message' in updateObject){
|
||||||
let responseObject = process(updateObject.message)
|
let responseObject = await process(updateObject.message)
|
||||||
//console.log(process.process(updateObject.message))
|
//console.log(process.process(updateObject.message))
|
||||||
if(responseObject)
|
if(responseObject)
|
||||||
{
|
{
|
||||||
@@ -15,7 +15,7 @@ module.exports.call = (base,updateObject)=>{
|
|||||||
"body":responseObject
|
"body":responseObject
|
||||||
},(err,res,body)=>{
|
},(err,res,body)=>{
|
||||||
if(err) console.log(err)
|
if(err) console.log(err)
|
||||||
if(body.ok) console.log("Successfully sent")
|
if(body.ok) console.log(`Successfully sent: ${body.result[0].message.text}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user