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:
parent
b7a847b612
commit
4cdd59dfcd
8 changed files with 19 additions and 20 deletions
5
app.js
5
app.js
|
@ -42,7 +42,10 @@ const master = new Master(`Bot ${process.env.TOKEN}`, "/shard.js", {
|
||||||
"guildMessageReactions",
|
"guildMessageReactions",
|
||||||
"directMessages",
|
"directMessages",
|
||||||
"directMessageReactions"
|
"directMessageReactions"
|
||||||
]
|
],
|
||||||
|
stats: {
|
||||||
|
requestTimeout: 30000
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ class CatCommand extends Command {
|
||||||
|
|
||||||
static description = "Gets a random cat picture";
|
static description = "Gets a random cat picture";
|
||||||
static aliases = ["kitters", "kitties", "kitty", "cattos", "catto", "cats", "cta"];
|
static aliases = ["kitters", "kitties", "kitty", "cattos", "catto", "cats", "cta"];
|
||||||
static requires = ["cat"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = CatCommand;
|
module.exports = CatCommand;
|
|
@ -11,8 +11,7 @@ class ImageSearchCommand extends Command {
|
||||||
if (this.args.length === 0) return "You need to provide something to search for!";
|
if (this.args.length === 0) return "You need to provide something to search for!";
|
||||||
await this.message.channel.sendTyping();
|
await this.message.channel.sendTyping();
|
||||||
const embeds = [];
|
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());
|
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.error && images.error.code === 403) return "The daily search quota has been exceeded. Check back later.";
|
|
||||||
if (images.results.length === 0) return "I couldn't find any results!";
|
if (images.results.length === 0) return "I couldn't find any results!";
|
||||||
for (const [i, value] of images.results.entries()) {
|
for (const [i, value] of images.results.entries()) {
|
||||||
embeds.push({
|
embeds.push({
|
||||||
|
|
|
@ -57,6 +57,10 @@ class StatsCommand extends Command {
|
||||||
{
|
{
|
||||||
"name": "Shard",
|
"name": "Shard",
|
||||||
"value": this.message.channel.guild ? this.client.guildShardMap[this.message.channel.guild.id] : "N/A",
|
"value": this.message.channel.guild ? this.client.guildShardMap[this.message.channel.guild.id] : "N/A",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Cluster",
|
||||||
|
"value": this.cluster,
|
||||||
"inline": true
|
"inline": true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
const fetch = require("node-fetch");
|
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 paginator = require("../../utils/pagination/pagination.js");
|
||||||
const Command = require("../../classes/command.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!";
|
if (this.args.length === 0) return "You need to provide something to search for!";
|
||||||
this.client.sendChannelTyping(this.message.channel.id);
|
this.client.sendChannelTyping(this.message.channel.id);
|
||||||
const messages = [];
|
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 videos = await fetch(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(this.args.join(" "))}`).then(res => res.json());
|
||||||
const result = await request.json();
|
if (videos.results.length === 0) return "I couldn't find any results!";
|
||||||
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 videos.results.entries()) {
|
||||||
for (const [i, value] of result.items.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}` });
|
||||||
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}` });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return paginator(this.client, this.message, messages);
|
return paginator(this.client, this.message, messages);
|
||||||
}
|
}
|
||||||
|
@ -26,7 +20,6 @@ class YouTubeCommand extends Command {
|
||||||
static description = "Searches YouTube";
|
static description = "Searches YouTube";
|
||||||
static aliases = ["yt", "video", "ytsearch"];
|
static aliases = ["yt", "video", "ytsearch"];
|
||||||
static arguments = ["[query]"];
|
static arguments = ["[query]"];
|
||||||
static requires = "google";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = YouTubeCommand;
|
module.exports = YouTubeCommand;
|
|
@ -1,3 +1,3 @@
|
||||||
// wrapper for the database drivers in ./database/
|
// 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`);
|
|
@ -1,5 +1,8 @@
|
||||||
// dummy (no-op) database handler
|
// dummy (no-op) database handler
|
||||||
const misc = require("../misc.js");
|
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.setup = async () => {};
|
||||||
exports.stop = async () => {};
|
exports.stop = async () => {};
|
||||||
|
|
|
@ -4,8 +4,6 @@ const logger = require("./logger.js");
|
||||||
// load command into memory
|
// load command into memory
|
||||||
exports.load = async (command, soundStatus) => {
|
exports.load = async (command, soundStatus) => {
|
||||||
const props = require(`../${command}`);
|
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("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}...`);
|
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("/");
|
const commandArray = command.split("/");
|
||||||
|
|
Loading…
Reference in a new issue