Improved tag retrieval, blacklisted a ton of events, fixed skip issue for real

This commit is contained in:
Essem 2021-08-14 08:00:16 -05:00
parent a81c93ece9
commit 5e8c587c41
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
6 changed files with 94 additions and 64 deletions

16
app.js
View file

@ -65,7 +65,21 @@ const Admiral = new Fleet({
GUILD_ROLE_DELETE: true,
GUILD_ROLE_UPDATE: true,
TYPING_START: true,
MESSAGE_DELETE_BULK: true
MESSAGE_DELETE_BULK: true,
WEBHOOKS_UPDATE: true,
STAGE_INSTANCE_CREATE: true,
STAGE_INSTANCE_DELETE: true,
STAGE_INSTANCE_UPDATE: true,
MESSAGE_REACTION_ADD: true,
MESSAGE_REACTION_REMOVE: true,
MESSAGE_REACTION_REMOVE_ALL: true,
MESSAGE_REACTION_REMOVE_EMOJI: true,
INVITE_CREATE: true,
INVITE_DELETE: true,
THREAD_CREATE: true,
THREAD_UPDATE: true,
THREAD_DELETE: true,
THREAD_LIST_SYNC: true
},
allowedMentions: {
everyone: false,

View file

@ -9,43 +9,42 @@ class TagsCommand extends Command {
if (!this.message.channel.guild) return "This command only works in servers!";
if (this.args.length === 0) return "You need to provide the name of the tag you want to view!";
const tags = await database.getTags(this.message.channel.guild.id);
const blacklist = ["create", "add", "edit", "remove", "delete", "list", "random", "own", "owner"];
switch (this.args[0].toLowerCase()) {
case "create":
case "add":
if (this.args[0].toLowerCase() === "create" || this.args[0].toLowerCase() === "add") {
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to add!";
if (blacklist.includes(this.args[1].toLowerCase())) return "You can't make a tag with that name!";
if (tags[this.args[1].toLowerCase()]) return "This tag already exists!";
var result = await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message);
const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
if (getResult) return "This tag already exists!";
const result = await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message);
if (result) return result;
return `The tag \`${this.args[1].toLowerCase()}\` has been added!`;
case "delete":
case "remove":
} else if (this.args[0].toLowerCase() === "delete" || this.args[0].toLowerCase() === "remove") {
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to delete!";
if (!tags[this.args[1].toLowerCase()]) return "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 "You don't own this tag!";
const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
if (!getResult) return "This tag doesn't exist!";
if (getResult.author !== this.message.author.id && !this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return "You don't own this tag!";
await database.removeTag(this.args[1].toLowerCase(), this.message.channel.guild);
return `The tag \`${this.args[1].toLowerCase()}\` has been deleted!`;
case "edit":
} else if (this.args[0].toLowerCase() === "edit") {
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to edit!";
if (!tags[this.args[1].toLowerCase()]) return "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 "You don't own this tag!";
const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
if (!getResult) return "This tag doesn't exist!";
if (getResult.author !== this.message.author.id && !this.message.member.permissions.has("manageMessages") && this.message.author.id !== process.env.OWNER) return "You don't own this tag!";
await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message, true);
return `The tag \`${this.args[1].toLowerCase()}\` has been edited!`;
case "own":
case "owner":
} else if (this.args[0].toLowerCase() === "own" || this.args[0].toLowerCase() === "owner") {
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to check the owner of!";
if (!tags[this.args[1].toLowerCase()]) return "This tag doesn't exist!";
var user = await this.ipc.fetchUser(tags[this.args[1].toLowerCase()].author);
if (!user) return `I couldn't find exactly who owns this tag, but I was able to get their ID: \`${tags[this.args[1].toLowerCase()].author}\``;
return `This tag is owned by **${user.username}#${user.discriminator}** (\`${tags[this.args[1].toLowerCase()].author}\`).`;
case "list":
const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
if (!getResult) return "This tag doesn't exist!";
const user = await this.ipc.fetchUser(getResult.author);
if (!user) return `I couldn't find exactly who owns this tag, but I was able to get their ID: \`${getResult.author}\``;
return `This tag is owned by **${user.username}#${user.discriminator}** (\`${getResult.author}\`).`;
} else if (this.args[0].toLowerCase() === "list") {
if (!this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
var pageSize = 15;
var embeds = [];
var groups = Object.keys(tags).map((item, index) => {
return index % pageSize === 0 ? Object.keys(tags).slice(index, index + pageSize) : null;
const tagList = await database.getTags(this.message.channel.guild.id);
const embeds = [];
const groups = Object.keys(tagList).map((item, index) => {
return index % 15 === 0 ? Object.keys(tagList).slice(index, index + 15) : null;
}).filter((item) => {
return item;
});
@ -67,11 +66,13 @@ class TagsCommand extends Command {
}
if (embeds.length === 0) return "I couldn't find any tags!";
return paginator(this.client, this.message, embeds);
case "random":
return tags[random(Object.keys(tags))].content;
default:
if (!tags[this.args[0].toLowerCase()]) return "This tag doesn't exist!";
return tags[this.args[0].toLowerCase()].content;
} else if (this.args[0].toLowerCase() === "random") {
const tagList = await database.getTags(this.message.channel.guild.id);
return tagList[random(Object.keys(tagList))].content;
} else {
const getResult = await database.getTag(this.message.channel.guild.id, this.args[0].toLowerCase());
if (!getResult) return "This tag doesn't exist!";
return getResult.content;
}
}

View file

@ -16,6 +16,7 @@ exports.enableCommand = async () => {};
exports.disableChannel = async () => {};
exports.enableChannel = async () => {};
exports.getTags = async () => {};
exports.getTag = async () => {};
exports.setTag = async () => {};
exports.removeTag = async () => {};
exports.editTag = async () => {};

View file

@ -16,6 +16,11 @@ exports.setPrefix = async (prefix, guild) => {
collections.prefixCache.set(guild.id, prefix);
};
exports.getTag = async (guild, tag) => {
const tagResult = (await connection.query("SELECT * FROM tags WHERE guild_id = $1 AND name = $2", [guild, tag])).rows;
return tagResult[0] ? { content: tagResult[0].content, author: tagResult[0].author } : undefined;
};
exports.getTags = async (guild) => {
const tagArray = (await connection.query("SELECT * FROM tags WHERE guild_id = $1", [guild])).rows;
const tags = {};
@ -85,7 +90,11 @@ exports.addCount = async (command) => {
exports.addGuild = async (guild) => {
const query = await this.getGuild(guild);
if (query) return query;
try {
await connection.query("INSERT INTO guilds (guild_id, prefix, disabled, disabled_commands) VALUES ($1, $2, $3, $4)", [guild.id, process.env.PREFIX, [], []]);
} catch (e) {
logger.error(`Failed to register guild ${guild.id}: ${e}`);
}
return await this.getGuild(guild.id);
};

View file

@ -97,6 +97,11 @@ exports.enableChannel = async (channel) => {
collections.disabledCache.set(channel.guild.id, newDisabled);
};
exports.getTag = async (guild, tag) => {
const tagResult = connection.prepare("SELECT * FROM tags WHERE guild_id = ? AND name = ?").get(guild, tag);
return tagResult ? { content: tagResult.content, author: tagResult.author } : undefined;
};
exports.getTags = async (guild) => {
const tagArray = connection.prepare("SELECT * FROM tags WHERE guild_id = ?").all(guild);
const tags = {};

View file

@ -89,7 +89,7 @@ exports.play = async (client, sound, message, music = false) => {
};
exports.nextSong = async (client, message, connection, track, info, music, voiceChannel, loop = false, inQueue = false, lastTrack = null) => {
this.skipVotes.set(this.message.channel.guild.id, { count: 0, ids: [] });
this.skipVotes.set(voiceChannel.guild.id, { count: 0, ids: [] });
const parts = Math.floor((0 / info.length) * 10);
let playingMessage;
if (!music && this.players.get(voiceChannel.guild.id)) {