2023-03-15 14:09:09 +00:00
|
|
|
import { request } from "undici";
|
|
|
|
import { readFileSync } from "fs";
|
|
|
|
const { searx } = JSON.parse(readFileSync(new URL("../../config/servers.json", import.meta.url)));
|
|
|
|
import { random } from "../../utils/misc.js";
|
|
|
|
// import paginator from "../../utils/pagination/pagination.js";
|
|
|
|
import Command from "../../classes/command.js";
|
|
|
|
|
|
|
|
class YouTubeCommand extends Command {
|
|
|
|
async run() {
|
|
|
|
const query = this.options.query ?? this.args.join(" ");
|
|
|
|
this.success = false;
|
|
|
|
if (!query || !query.trim()) return "You need to provide something to search for!";
|
2023-03-17 00:23:01 +00:00
|
|
|
// await this.acknowledge();
|
2023-03-15 14:09:09 +00:00
|
|
|
const messages = [];
|
|
|
|
const videos = await request(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(query)}`).then(res => res.body.json());
|
|
|
|
if (videos.results.length === 0) return "I couldn't find any results!";
|
|
|
|
// console.log(videos.results[0])
|
|
|
|
this.success = true;
|
|
|
|
return videos.results[0].url
|
|
|
|
// return paginator(this.client, { type: this.type, message: this.message, interaction: this.interaction, channel: this.channel, author: this.author }, messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static flags = [{
|
|
|
|
name: "query",
|
|
|
|
type: 3,
|
|
|
|
description: "The query you want to search for",
|
|
|
|
required: true
|
|
|
|
}];
|
|
|
|
|
|
|
|
static description = "Searches YouTube";
|
|
|
|
static aliases = ["yt", "video", "ytsearch"];
|
|
|
|
static arguments = ["[query]"];
|
|
|
|
}
|
|
|
|
|
2021-08-19 14:19:14 +00:00
|
|
|
export default YouTubeCommand;
|