Improved tag retrieval, blacklisted a ton of events, fixed skip issue for real
This commit is contained in:
		
							parent
							
								
									a81c93ece9
								
							
						
					
					
						commit
						5e8c587c41
					
				
					 6 changed files with 94 additions and 64 deletions
				
			
		
							
								
								
									
										16
									
								
								app.js
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								app.js
									
										
									
									
									
								
							| 
						 | 
					@ -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,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,69 +9,70 @@ 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":
 | 
					      if (this.args[1] === undefined) return "You need to provide the name of the tag you want to add!";
 | 
				
			||||||
      case "add":
 | 
					      if (blacklist.includes(this.args[1].toLowerCase())) return "You can't make a tag with that name!";
 | 
				
			||||||
        if (this.args[1] === undefined) return "You need to provide the name of the tag you want to add!";
 | 
					      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
				
			||||||
        if (blacklist.includes(this.args[1].toLowerCase())) return "You can't make a tag with that name!";
 | 
					      if (getResult) return "This tag already exists!";
 | 
				
			||||||
        if (tags[this.args[1].toLowerCase()]) return "This tag already exists!";
 | 
					      const result = await this.setTag(this.args.slice(2).join(" "), this.args[1].toLowerCase(), this.message);
 | 
				
			||||||
        var 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!`;
 | 
					    } else if (this.args[0].toLowerCase() === "delete" || this.args[0].toLowerCase() === "remove") {
 | 
				
			||||||
      case "delete":
 | 
					      if (this.args[1] === undefined) return "You need to provide the name of the tag you want to delete!";
 | 
				
			||||||
      case "remove":
 | 
					      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
				
			||||||
        if (this.args[1] === undefined) return "You need to provide the name of the tag you want to delete!";
 | 
					      if (!getResult) return "This tag doesn't exist!";
 | 
				
			||||||
        if (!tags[this.args[1].toLowerCase()]) 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!";
 | 
				
			||||||
        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!";
 | 
					      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!`;
 | 
					    } else if (this.args[0].toLowerCase() === "edit") {
 | 
				
			||||||
      case "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!";
 | 
					      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
				
			||||||
        if (!tags[this.args[1].toLowerCase()]) return "This tag doesn't exist!";
 | 
					      if (!getResult) 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!";
 | 
					      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!";
 | 
					      const getResult = await database.getTag(this.message.channel.guild.id, this.args[1].toLowerCase());
 | 
				
			||||||
        if (!tags[this.args[1].toLowerCase()]) return "This tag doesn't exist!";
 | 
					      if (!getResult) return "This tag doesn't exist!";
 | 
				
			||||||
        var user = await this.ipc.fetchUser(tags[this.args[1].toLowerCase()].author);
 | 
					      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: \`${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}\``;
 | 
				
			||||||
        return `This tag is owned by **${user.username}#${user.discriminator}** (\`${tags[this.args[1].toLowerCase()].author}\`).`;
 | 
					      return `This tag is owned by **${user.username}#${user.discriminator}** (\`${getResult.author}\`).`;
 | 
				
			||||||
      case "list":
 | 
					    } 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;
 | 
				
			||||||
        });
 | 
					      });
 | 
				
			||||||
        for (const [i, value] of groups.entries()) {
 | 
					      for (const [i, value] of groups.entries()) {
 | 
				
			||||||
          embeds.push({
 | 
					        embeds.push({
 | 
				
			||||||
            "embed": {
 | 
					          "embed": {
 | 
				
			||||||
              "title": "Tag List",
 | 
					            "title": "Tag List",
 | 
				
			||||||
              "color": 16711680,
 | 
					            "color": 16711680,
 | 
				
			||||||
              "footer": {
 | 
					            "footer": {
 | 
				
			||||||
                "text": `Page ${i + 1} of ${groups.length}`
 | 
					              "text": `Page ${i + 1} of ${groups.length}`
 | 
				
			||||||
              },
 | 
					            },
 | 
				
			||||||
              "description": value.join("\n"),
 | 
					            "description": value.join("\n"),
 | 
				
			||||||
              "author": {
 | 
					            "author": {
 | 
				
			||||||
                "name": this.message.author.username,
 | 
					              "name": this.message.author.username,
 | 
				
			||||||
                "icon_url": this.message.author.avatarURL
 | 
					              "icon_url": this.message.author.avatarURL
 | 
				
			||||||
              }
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
          });
 | 
					          }
 | 
				
			||||||
        }
 | 
					        });
 | 
				
			||||||
        if (embeds.length === 0) return "I couldn't find any tags!";
 | 
					      }
 | 
				
			||||||
        return paginator(this.client, this.message, embeds);
 | 
					      if (embeds.length === 0) return "I couldn't find any tags!";
 | 
				
			||||||
      case "random":
 | 
					      return paginator(this.client, this.message, embeds);
 | 
				
			||||||
        return tags[random(Object.keys(tags))].content;
 | 
					    } else if (this.args[0].toLowerCase() === "random") {
 | 
				
			||||||
      default:
 | 
					      const tagList = await database.getTags(this.message.channel.guild.id);
 | 
				
			||||||
        if (!tags[this.args[0].toLowerCase()]) return "This tag doesn't exist!";
 | 
					      return tagList[random(Object.keys(tagList))].content;
 | 
				
			||||||
        return tags[this.args[0].toLowerCase()].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;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 () => {};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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;
 | 
				
			||||||
  await connection.query("INSERT INTO guilds (guild_id, prefix, disabled, disabled_commands) VALUES ($1, $2, $3, $4)", [guild.id, process.env.PREFIX, [], []]);
 | 
					  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);
 | 
					  return await this.getGuild(guild.id);
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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 = {};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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)) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue