Made youtube use searx for results, fall back to dummy db when none is specified, added cluster to stats, more QOL changes

This commit is contained in:
TheEssem 2021-06-26 15:56:02 -05:00
parent b7a847b612
commit 4cdd59dfcd
No known key found for this signature in database
GPG Key ID: A3F9F02129092FCA
8 changed files with 19 additions and 20 deletions

5
app.js
View File

@ -42,7 +42,10 @@ const master = new Master(`Bot ${process.env.TOKEN}`, "/shard.js", {
"guildMessageReactions",
"directMessages",
"directMessageReactions"
]
],
stats: {
requestTimeout: 30000
}
}
});

View File

@ -17,7 +17,6 @@ class CatCommand extends Command {
static description = "Gets a random cat picture";
static aliases = ["kitters", "kitties", "kitty", "cattos", "catto", "cats", "cta"];
static requires = ["cat"];
}
module.exports = CatCommand;

View File

@ -11,8 +11,7 @@ class ImageSearchCommand extends Command {
if (this.args.length === 0) return "You need to provide something to search for!";
await this.message.channel.sendTyping();
const embeds = [];
const images = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=images&disabled_engines=flickr__images,ccengine__images,library of congress__images,deviantart__images,bing images__images&q=${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
//if (images.error && images.error.code === 403) return "The daily search quota has been exceeded. Check back later.";
const images = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=images&q=!goi%20!bii%20!ddi%20${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
if (images.results.length === 0) return "I couldn't find any results!";
for (const [i, value] of images.results.entries()) {
embeds.push({

View File

@ -57,6 +57,10 @@ class StatsCommand extends Command {
{
"name": "Shard",
"value": this.message.channel.guild ? this.client.guildShardMap[this.message.channel.guild.id] : "N/A",
},
{
"name": "Cluster",
"value": this.cluster,
"inline": true
}
]

View File

@ -1,5 +1,6 @@
const fetch = require("node-fetch");
const { decodeEntities } = require("../../utils/misc.js");
const { searx } = require("../../servers.json");
const { random } = require("../../utils/misc.js");
const paginator = require("../../utils/pagination/pagination.js");
const Command = require("../../classes/command.js");
@ -8,17 +9,10 @@ class YouTubeCommand extends Command {
if (this.args.length === 0) return "You need to provide something to search for!";
this.client.sendChannelTyping(this.message.channel.id);
const messages = [];
const request = await fetch(`https://www.googleapis.com/youtube/v3/search?part=snippet&q=${encodeURIComponent(this.args.join(" "))}&key=${process.env.GOOGLE}&maxResults=50`);
const result = await request.json();
if (result.error && result.error.code === 403) return "I've exceeded my YouTube API search quota for the day. Check back later.";
for (const [i, value] of result.items.entries()) {
if (value.id.kind === "youtube#channel") {
messages.push({ content: `Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nhttps://youtube.com/channel/${value.id.channelId}` });
} else if (value.id.kind === "youtube#playlist") {
messages.push({ content: `Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nCreated by **${decodeEntities(value.snippet.channelTitle).replaceAll("*", "\\*")}**\nhttps://youtube.com/playlist?list=${value.id.playlistId}` });
} else {
messages.push({ content: `Page ${i + 1} of ${result.items.length}\n<:youtube:637020823005167626> **${decodeEntities(value.snippet.title).replaceAll("*", "\\*")}**\nUploaded by **${decodeEntities(value.snippet.channelTitle).replaceAll("*", "\\*")}** on **${value.snippet.publishedAt.split("T")[0]}**\nhttps://youtube.com/watch?v=${value.id.videoId}` });
}
const videos = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
if (videos.results.length === 0) return "I couldn't find any results!";
for (const [i, value] of videos.results.entries()) {
messages.push({ content: `Page ${i + 1} of ${videos.results.length}\n<:youtube:637020823005167626> **${value.title.replaceAll("*", "\\*")}**\nUploaded by **${value.author.replaceAll("*", "\\*")}**\n${value.url}` });
}
return paginator(this.client, this.message, messages);
}
@ -26,7 +20,6 @@ class YouTubeCommand extends Command {
static description = "Searches YouTube";
static aliases = ["yt", "video", "ytsearch"];
static arguments = ["[query]"];
static requires = "google";
}
module.exports = YouTubeCommand;

View File

@ -1,3 +1,3 @@
// wrapper for the database drivers in ./database/
module.exports = require(`./database/${process.env.DB.split("://")[0]}.js`);
module.exports = require(`./database/${process.env.DB ? process.env.DB.split("://")[0] : "dummy"}.js`);

View File

@ -1,5 +1,8 @@
// dummy (no-op) database handler
const misc = require("../misc.js");
const logger = require("../logger.js");
logger.warn("Using dummy database adapter. If this isn't what you wanted, check your DB variable.");
exports.setup = async () => {};
exports.stop = async () => {};

View File

@ -4,8 +4,6 @@ const logger = require("./logger.js");
// load command into memory
exports.load = async (command, soundStatus) => {
const props = require(`../${command}`);
if (props.requires.includes("google") && process.env.GOOGLE === "") return logger.log("warn", `Google info not provided in config, skipped loading command ${command}...`);
if (props.requires.includes("cat") && process.env.CAT === "") return logger.log("warn", `Cat API info not provided in config, skipped loading command ${command}...`);
if (props.requires.includes("mashape") && process.env.MASHAPE === "") return logger.log("warn", `Mashape/RapidAPI info not provided in config, skipped loading command ${command}...`);
if (props.requires.includes("sound") && soundStatus) return logger.log("warn", `Failed to connect to some Lavalink nodes, skipped loading command ${command}...`);
const commandArray = command.split("/");