Skip to content

Commit

Permalink
bot search done
Browse files Browse the repository at this point in the history
  • Loading branch information
patheticGeek committed Jan 6, 2020
1 parent 7302549 commit 3c2e258
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 242 deletions.
11 changes: 9 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,15 @@
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceFolder}/index.js"
"program": "${workspaceFolder}/index.js",
"skipFiles": ["<node_internals>/**"]
},
{
"type": "node",
"request": "attach",
"name": "Attach",
"processId": "${command:PickProcess}",
"skipFiles": ["<node_internals>/**"]
}
]
}
93 changes: 85 additions & 8 deletions bot/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Telegram = require("node-telegram-bot-api");
const fetch = require("isomorphic-unfetch");
const axios = require("axios");

const dev = process.env.NODE_ENV !== "production";
const token = dev ? require("./token") : process.env.TELEGRAM_TOKEN;
const api = "https://torrent-aio-bot.herokuapp.com/api/v1";
Expand All @@ -19,17 +20,93 @@ bot.onText(/\/search piratebay (.+)/, async (msg, match) => {

bot.sendMessage(from, "Searching...");

const data = await fetch(api + "/search/piratebay?query=" + query);
if (data.error) {
const data = await axios(api + "/search/piratebay?query=" + query).then(
({ data }) => data
);
if (!data || data.error) {
bot.sendMessage(from, "An error occured on server");
} else if (data.totalResults === 0) {
bot.sendMessage(from, "No results found.");
} else if (data.results.length > 0) {
let results1 = "";
let results2 = "";
let results3 = "";
data.results.forEach((result, i) => {
if (i <= 2) {
results1 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (2 < i && i <= 5) {
results2 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (5 < i && i <= 8) {
results3 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
}
});
bot.sendMessage(from, results1);
bot.sendMessage(from, results2);
bot.sendMessage(from, results3);
}
});

bot.onText(/\/search 1337x (.+)/, async (msg, match) => {
var from = msg.from.id;
var query = match[1];

bot.sendMessage(from, "Searching...");

const data = await axios(api + "/search/1337x?query=" + query).then(
({ data }) => data
);
if (!data || data.error) {
bot.sendMessage(from, "An error occured on server");
} else if (data.totalResults === 0) {
bot.sendMessage(from, "No results found.");
} else if (data.results.length > 0) {
let results1 = "";
let results2 = "";
let results3 = "";
data.results.forEach((result, i) => {
if (i <= 2) {
results1 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (2 < i && i <= 5) {
results2 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (5 < i && i <= 8) {
results3 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
}
});
bot.sendMessage(from, results1);
bot.sendMessage(from, results2);
bot.sendMessage(from, results3);
}
});

bot.onText(/\/search limetorrent (.+)/, async (msg, match) => {
var from = msg.from.id;
var query = match[1];

bot.sendMessage(from, "Searching...");

const data = await axios(api + "/search/limetorrent?query=" + query).then(
({ data }) => data
);
if (!data || data.error) {
bot.sendMessage(from, "An error occured on server");
} else if (data.totalResults === 0) {
bot.sendMessage(from, "No results found.");
} else if (data.results.lenght > 0) {
let results = "";
data.results.forEach(result => {
results += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (data.results.length > 0) {
let results1 = "";
let results2 = "";
let results3 = "";
data.results.forEach((result, i) => {
if (i <= 2) {
results1 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (2 < i && i <= 5) {
results2 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
} else if (5 < i && i <= 8) {
results3 += `Name: ${result.name} \nSeeds: ${result.seeds} \nDetails: ${result.details} \nLink: ${result.link} \n\n`;
}
});
bot.sendMessage(from, results);
bot.sendMessage(from, results1);
bot.sendMessage(from, results2);
bot.sendMessage(from, results3);
}
});

Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const express = require("express");
const compression = require("compression");
const puppeteer = require("puppeteer");
const WebTorrent = require("webtorrent");
const fetch = require("isomorphic-unfetch");
const axios = require("axios");
require("./bot");

const prettyBytes = require("./lib/prettyBytes");
Expand All @@ -25,7 +25,7 @@ const torrentClient = new WebTorrent({});
const PORT = parseInt(process.env.PORT, 10) || 3000;

setInterval(async () => {
const data = await fetch(
const data = await axios(
"https://ping-pong-sn.herokuapp.com/ping?link=https://torrent-aio-bot.herokuapp.com/ping"
);
console.log("setInterval triggred: ", data.status);
Expand Down
Loading

0 comments on commit 3c2e258

Please sign in to comment.