Added initial support for detecting videos, prevent music messages from showing on soundboard commands, fixed(?) permission checking
This commit is contained in:
parent
8aa0cc2163
commit
c67499af9d
6 changed files with 26 additions and 22 deletions
|
@ -4,7 +4,8 @@ const Command = require("../../classes/command.js");
|
|||
class ChannelCommand extends Command {
|
||||
async run() {
|
||||
if (!this.message.channel.guild) return `${this.message.author.mention}, this command only works in servers!`;
|
||||
if (!this.message.member.permissions.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to enable/disable me!`;
|
||||
console.log(this.message.member.permission);
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to enable/disable me!`;
|
||||
if (this.args.length === 0) return `${this.message.author.mention}, you need to provide whether I should be enabled or disabled in this channel!`;
|
||||
if (this.args[0] !== "disable" && this.args[0] !== "enable") return `${this.message.author.mention}, that's not a valid option!`;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class PrefixCommand extends Command {
|
|||
if (!this.message.channel.guild) return `${this.message.author.mention}, this command only works in servers!`;
|
||||
const guild = await database.getGuild(this.message.channel.guild.id);
|
||||
if (this.args.length !== 0) {
|
||||
if (!this.message.member.permissions.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to change the bot prefix!`;
|
||||
if (!this.message.member.permission.has("administrator") && this.message.member.id !== process.env.OWNER) return `${this.message.author.mention}, you need to be an administrator to change the bot prefix!`;
|
||||
await database.setPrefix(this.args[0], this.message.channel.guild);
|
||||
return `The prefix has been changed to ${this.args[0]}.`;
|
||||
} else {
|
||||
|
|
|
@ -25,13 +25,13 @@ class TagsCommand extends Command {
|
|||
case "remove":
|
||||
if (this.args[1] === undefined) return `${this.message.author.mention}, you need to provide the name of the tag you want to delete!`;
|
||||
if (!tags[this.args[1].toLowerCase()]) return `${this.message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags[this.args[1].toLowerCase()].author !== this.message.author.id && !this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't own this tag!`;
|
||||
if (tags[this.args[1].toLowerCase()].author !== this.message.author.id && !this.message.member.permission.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't own this tag!`;
|
||||
await database.removeTag(this.args[1].toLowerCase(), this.message.channel.guild);
|
||||
return `${this.message.author.mention}, the tag \`${this.args[1].toLowerCase()}\` has been deleted!`;
|
||||
case "edit":
|
||||
if (this.args[1] === undefined) return `${this.message.author.mention}, you need to provide the name of the tag you want to edit!`;
|
||||
if (!tags[this.args[1].toLowerCase()]) return `${this.message.author.mention}, this tag doesn't exist!`;
|
||||
if (tags[this.args[1].toLowerCase()].author !== this.message.author.id && !this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't own this tag!`;
|
||||
if (tags[this.args[1].toLowerCase()].author !== this.message.author.id && !this.message.member.permission.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't own this tag!`;
|
||||
await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message, guild);
|
||||
return `${this.message.author.mention}, the tag \`${this.args[1].toLowerCase()}\` has been edited!`;
|
||||
case "own":
|
||||
|
@ -72,7 +72,7 @@ class TagsCommand extends Command {
|
|||
return tags[random(Object.keys(tags))].content;
|
||||
case "enable":
|
||||
case "disable":
|
||||
if (!this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't have permission to disable tags!`;
|
||||
if (!this.message.member.permission.has("manageMessages") && this.message.author.id !== process.env.OWNER) return `${this.message.author.mention}, you don't have permission to disable tags!`;
|
||||
var toggleResult = await database.toggleTags(this.message.channel.guild);
|
||||
return `${this.message.author.mention}, tags for this guild have been ${toggleResult ? "disabled" : "enabled"}. To ${toggleResult ? "enable" : "disable"} them again, run ${guild.prefix}tags ${toggleResult ? "enable" : "disable"}.`;
|
||||
default:
|
||||
|
|
|
@ -4,7 +4,7 @@ const { random } = require("../utils/misc.js");
|
|||
|
||||
module.exports = async (client, member, oldChannel) => {
|
||||
const connection = soundPlayer.players.get(oldChannel.guild.id);
|
||||
if (connection && oldChannel.id === connection.voiceChannel.id) {
|
||||
if (connection && connection.type === "music" && oldChannel.id === connection.voiceChannel.id) {
|
||||
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id).length === 0) {
|
||||
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
||||
const awaitRejoin = new AwaitRejoin(oldChannel, true);
|
||||
|
|
|
@ -8,7 +8,7 @@ const path = require("path");
|
|||
const { EventEmitter } = require("events");
|
||||
const logger = require("./logger.js");
|
||||
|
||||
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif", "video/mp4", "video/webm", "video/mov"];
|
||||
|
||||
const jobs = {};
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
const fetch = require("node-fetch");
|
||||
const url = require("url");
|
||||
const { getType } = require("./image.js");
|
||||
const execPromise = require("util").promisify(require("child_process").exec);
|
||||
|
||||
|
@ -23,17 +22,18 @@ const gfycatURLs = [
|
|||
"giant.gfycat.com"
|
||||
];
|
||||
|
||||
const formats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
const imageFormats = ["image/jpeg", "image/png", "image/webp", "image/gif"];
|
||||
const videoFormats = ["video/mp4", "video/webm", "video/mov"];
|
||||
|
||||
// gets the proper image paths
|
||||
const getImage = async (image, image2, gifv = false) => {
|
||||
const getImage = async (image, image2, video, gifv = false) => {
|
||||
try {
|
||||
const payload = {
|
||||
url: image2,
|
||||
path: image
|
||||
};
|
||||
if (gifv) {
|
||||
const host = url.parse(image2).host;
|
||||
const host = new URL(image2).host;
|
||||
if (tenorURLs.includes(host)) {
|
||||
if (process.env.TENOR !== "") {
|
||||
const data = await fetch(`https://api.tenor.com/v1/gifs?ids=${image2.split("-").pop()}&key=${process.env.TENOR}`);
|
||||
|
@ -51,9 +51,12 @@ const getImage = async (image, image2, gifv = false) => {
|
|||
payload.path = `https://thumbs.gfycat.com/${image.split("/").pop().split(".mp4")[0]}-size_restricted.gif`;
|
||||
}
|
||||
payload.type = "image/gif";
|
||||
} else if (video) {
|
||||
payload.type = await getType(payload.path);
|
||||
if (!payload.type || !videoFormats.includes(payload.type)) return;
|
||||
} else {
|
||||
payload.type = await getType(payload.path);
|
||||
if (!payload.type || !formats.includes(payload.type)) return;
|
||||
if (!payload.type || !imageFormats.includes(payload.type)) return;
|
||||
}
|
||||
return payload;
|
||||
} catch (error) {
|
||||
|
@ -65,42 +68,42 @@ const getImage = async (image, image2, gifv = false) => {
|
|||
}
|
||||
};
|
||||
|
||||
const checkImages = async (message) => {
|
||||
const checkImages = async (message, video) => {
|
||||
let type;
|
||||
// first check the embeds
|
||||
if (message.embeds.length !== 0) {
|
||||
// embeds can vary in types, we check for tenor gifs first
|
||||
if (message.embeds[0].type === "gifv") {
|
||||
type = await getImage(message.embeds[0].video.url, message.embeds[0].url, true);
|
||||
type = await getImage(message.embeds[0].video.url, message.embeds[0].url, video, true);
|
||||
// then we check for other image types
|
||||
} else if ((message.embeds[0].type === "video" || message.embeds[0].type === "image") && message.embeds[0].thumbnail) {
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video);
|
||||
// finally we check both possible image fields for "generic" embeds
|
||||
} else if (message.embeds[0].type === "rich") {
|
||||
if (message.embeds[0].thumbnail) {
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url);
|
||||
type = await getImage(message.embeds[0].thumbnail.proxy_url, message.embeds[0].thumbnail.url, video);
|
||||
} else if (message.embeds[0].image) {
|
||||
type = await getImage(message.embeds[0].image.proxy_url, message.embeds[0].image.url);
|
||||
type = await getImage(message.embeds[0].image.proxy_url, message.embeds[0].image.url, video);
|
||||
}
|
||||
}
|
||||
// then check the attachments
|
||||
} else if (message.attachments.length !== 0 && message.attachments[0].width) {
|
||||
type = await getImage(message.attachments[0].proxy_url, message.attachments[0].url);
|
||||
type = await getImage(message.attachments[0].proxy_url, message.attachments[0].url, video);
|
||||
}
|
||||
// if the file is an image then return it
|
||||
return type ? type : false;
|
||||
};
|
||||
|
||||
// this checks for the latest message containing an image and returns the url of the image
|
||||
module.exports = async (client, cmdMessage) => {
|
||||
module.exports = async (client, cmdMessage, video = false) => {
|
||||
// we start by checking the current message for images
|
||||
const result = await checkImages(cmdMessage);
|
||||
const result = await checkImages(cmdMessage, video);
|
||||
if (result !== false) return result;
|
||||
// if there aren't any in the current message then check if there's a reply
|
||||
if (cmdMessage.messageReference) {
|
||||
const replyMessage = await client.getMessage(cmdMessage.messageReference.channelID, cmdMessage.messageReference.messageID);
|
||||
if (replyMessage) {
|
||||
const replyResult = await checkImages(replyMessage);
|
||||
const replyResult = await checkImages(replyMessage, video);
|
||||
if (replyResult !== false) return replyResult;
|
||||
}
|
||||
}
|
||||
|
@ -108,7 +111,7 @@ module.exports = async (client, cmdMessage) => {
|
|||
const messages = await cmdMessage.channel.getMessages();
|
||||
// iterate over each message
|
||||
for (const message of messages) {
|
||||
const result = await checkImages(message);
|
||||
const result = await checkImages(message, video);
|
||||
if (result === false) {
|
||||
continue;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue