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_DELETE: true,
GUILD_ROLE_UPDATE: true, GUILD_ROLE_UPDATE: true,
TYPING_START: 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: { allowedMentions: {
everyone: false, 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.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!"; 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"]; const blacklist = ["create", "add", "edit", "remove", "delete", "list", "random", "own", "owner"];
switch (this.args[0].toLowerCase()) { if (this.args[0].toLowerCase() === "create" || this.args[0].toLowerCase() === "add") {
case "create":
case "add":
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to 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 (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!"; const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
var result = await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message); 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; if (result) return result;
return `The tag \`${this.args[1].toLowerCase()}\` has been added!`; return `The tag \`${this.args[1].toLowerCase()}\` has been added!`;
case "delete": } else if (this.args[0].toLowerCase() === "delete" || this.args[0].toLowerCase() === "remove") {
case "remove":
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to delete!"; 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!"; const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
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!"; 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); await database.removeTag(this.args[1].toLowerCase(), this.message.channel.guild);
return `The tag \`${this.args[1].toLowerCase()}\` has been deleted!`; 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 (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!"; const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
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!"; 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); 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!`; return `The tag \`${this.args[1].toLowerCase()}\` has been edited!`;
case "own": } else if (this.args[0].toLowerCase() === "own" || this.args[0].toLowerCase() === "owner") {
case "owner":
if (this.args[1] === undefined) return "You need to provide the name of the tag you want to check the owner of!"; 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!"; const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
var user = await this.ipc.fetchUser(tags[this.args[1].toLowerCase()].author); if (!getResult) return "This tag doesn't exist!";
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}\``; const user = await this.ipc.fetchUser(getResult.author);
return `This tag is owned by **${user.username}#${user.discriminator}** (\`${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: \`${getResult.author}\``;
case "list": 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!"; if (!this.message.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!";
var pageSize = 15; const tagList = await database.getTags(this.message.channel.guild.id);
var embeds = []; const embeds = [];
var groups = Object.keys(tags).map((item, index) => { const groups = Object.keys(tagList).map((item, index) => {
return index % pageSize === 0 ? Object.keys(tags).slice(index, index + pageSize) : null; return index % 15 === 0 ? Object.keys(tagList).slice(index, index + 15) : null;
}).filter((item) => { }).filter((item) => {
return item; return item;
}); });
@ -67,11 +66,13 @@ class TagsCommand extends Command {
} }
if (embeds.length === 0) return "I couldn't find any tags!"; if (embeds.length === 0) return "I couldn't find any tags!";
return paginator(this.client, this.message, embeds); return paginator(this.client, this.message, embeds);
case "random": } else if (this.args[0].toLowerCase() === "random") {
return tags[random(Object.keys(tags))].content; const tagList = await database.getTags(this.message.channel.guild.id);
default: return tagList[random(Object.keys(tagList))].content;
if (!tags[this.args[0].toLowerCase()]) return "This tag doesn't exist!"; } else {
return tags[this.args[0].toLowerCase()].content; 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.disableChannel = async () => {};
exports.enableChannel = async () => {}; exports.enableChannel = async () => {};
exports.getTags = async () => {}; exports.getTags = async () => {};
exports.getTag = async () => {};
exports.setTag = async () => {}; exports.setTag = async () => {};
exports.removeTag = async () => {}; exports.removeTag = async () => {};
exports.editTag = async () => {}; exports.editTag = async () => {};

View file

@ -16,6 +16,11 @@ exports.setPrefix = async (prefix, guild) => {
collections.prefixCache.set(guild.id, prefix); 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) => { exports.getTags = async (guild) => {
const tagArray = (await connection.query("SELECT * FROM tags WHERE guild_id = $1", [guild])).rows; const tagArray = (await connection.query("SELECT * FROM tags WHERE guild_id = $1", [guild])).rows;
const tags = {}; const tags = {};
@ -85,7 +90,11 @@ exports.addCount = async (command) => {
exports.addGuild = async (guild) => { exports.addGuild = async (guild) => {
const query = await this.getGuild(guild); const query = await this.getGuild(guild);
if (query) return query; 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, [], []]); 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); return await this.getGuild(guild.id);
}; };

View file

@ -97,6 +97,11 @@ exports.enableChannel = async (channel) => {
collections.disabledCache.set(channel.guild.id, newDisabled); 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) => { exports.getTags = async (guild) => {
const tagArray = connection.prepare("SELECT * FROM tags WHERE guild_id = ?").all(guild); const tagArray = connection.prepare("SELECT * FROM tags WHERE guild_id = ?").all(guild);
const tags = {}; 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) => { 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); const parts = Math.floor((0 / info.length) * 10);
let playingMessage; let playingMessage;
if (!music && this.players.get(voiceChannel.guild.id)) { if (!music && this.players.get(voiceChannel.guild.id)) {