{"size": 1204, "ext": "js", "max_stars_repo_path": "src/plugins/Fap.js", "max_stars_repo_name": "crisbal/Telegram-Bot-Node", "max_stars_repo_stars_event_min_datetime": "2016-04-14T16:01:30.000Z", "max_stars_repo_stars_event_max_datetime": "2017-11-25T12:02:30.000Z", "max_issues_repo_path": "src/plugins/Fap.js", "max_issues_repo_name": "crisbal/Telegram-Bot-Node", "max_issues_repo_issues_event_min_datetime": "2016-04-05T23:46:15.000Z", "max_issues_repo_issues_event_max_datetime": "2017-11-09T11:59:26.000Z", "max_forks_repo_path": "src/plugins/Fap.js", "max_forks_repo_name": "crisbal/Telegram-Bot-Node", "max_forks_repo_forks_event_min_datetime": "2016-01-24T17:06:44.000Z", "max_forks_repo_forks_event_max_datetime": "2017-11-13T12:21:22.000Z"}
{"max_stars_count": 39, "max_issues_count": 107, "max_forks_count": 39, "avg_line_length": 30.8717948718, "max_line_length": 123, "alphanum_fraction": 0.5274086379}
const Plugin = require("../Plugin");
const Util = require("./../Util");
const request = require("request-promise-native");

module.exports = class Porn extends Plugin {
    static get plugin() {
        return {
            name: "Porn",
            description: "Searches porn.com.",
            help: "`/porn <query>`"
        };
    }

    async onCommand({command, args}) {
        if (command !== "porn") return;
        if (args.length === 0)
            return "Please enter a search query.";

        const query = args.join(" ");
        const data = JSON.parse(await request(`http://api.porn.com/videos/find.json?search=${encodeURIComponent(query)}`));
        if (data.success !== true)
            throw new Error("An error occurred.");

        const item = data.result[0];
        const minutes = String(Math.floor(item.duration / 60));
        let seconds = String(item.duration % 60);
        if (String(seconds).length === 1)
            seconds = "0" + seconds;

        return {
            type: "text",
            text: `${Util.makeHTMLLink(item.title, item.url)} - ${minutes}:${seconds}`,
            options: {
                parse_mode: "HTML"
            }
        };
    }
};
