Revert "Merge pull request #54 from lazuee/main"
This reverts commitd303e0420a, reversing changes made to43045f0b70.
This commit is contained in:
		@@ -118,47 +118,6 @@ class MessagePayload {
 | 
				
			|||||||
    return content;
 | 
					    return content;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /**
 | 
					 | 
				
			||||||
   * Makes the webembed content of this message.
 | 
					 | 
				
			||||||
   * @returns {?string}
 | 
					 | 
				
			||||||
   */
 | 
					 | 
				
			||||||
  async makeWebEmbed() {
 | 
					 | 
				
			||||||
    let content;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (this.options.embeds) {
 | 
					 | 
				
			||||||
      if (!Array.isArray(this.options.embeds)) {
 | 
					 | 
				
			||||||
        this.options.embeds = [this.options.embeds];
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      const webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
 | 
					 | 
				
			||||||
      this.options.embeds = this.options.embeds.filter(e => e instanceof MessageEmbed);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (webembeds.length > 0) {
 | 
					 | 
				
			||||||
        if (!content) content = '';
 | 
					 | 
				
			||||||
        // Add hidden embed link
 | 
					 | 
				
			||||||
        content += `${WebEmbed.hiddenEmbed} `;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        for (const webE of webembeds) {
 | 
					 | 
				
			||||||
          const data = await webE.toMessage();
 | 
					 | 
				
			||||||
          content += `${data} `;
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        content = content.trim();
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      // Check content
 | 
					 | 
				
			||||||
      if (typeof content == 'string' && content.length > 2000) {
 | 
					 | 
				
			||||||
        console.warn('[WARN] WebEmbed is longer than 2000 characters.');
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      if (typeof content == 'string' && content.length > 4000) {
 | 
					 | 
				
			||||||
        // Max length if user has nitro boost
 | 
					 | 
				
			||||||
        throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return content;
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
  
 | 
					 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
   * Resolves data.
 | 
					   * Resolves data.
 | 
				
			||||||
   * @returns {MessagePayload}
 | 
					   * @returns {MessagePayload}
 | 
				
			||||||
@@ -169,7 +128,6 @@ class MessagePayload {
 | 
				
			|||||||
    const isWebhook = this.isWebhook;
 | 
					    const isWebhook = this.isWebhook;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let content = this.makeContent();
 | 
					    let content = this.makeContent();
 | 
				
			||||||
    let webembed = await this.makeWebEmbed();
 | 
					 | 
				
			||||||
    const tts = Boolean(this.options.tts);
 | 
					    const tts = Boolean(this.options.tts);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let nonce;
 | 
					    let nonce;
 | 
				
			||||||
@@ -231,8 +189,38 @@ class MessagePayload {
 | 
				
			|||||||
      this.options.attachments = attachments;
 | 
					      this.options.attachments = attachments;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (this.options.embeds) {
 | 
				
			||||||
 | 
					      if (!Array.isArray(this.options.embeds)) {
 | 
				
			||||||
 | 
					        this.options.embeds = [this.options.embeds];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      const webembeds = this.options.embeds.filter(e => e instanceof WebEmbed);
 | 
				
			||||||
 | 
					      this.options.embeds = this.options.embeds.filter(e => e instanceof MessageEmbed);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (webembeds.length > 0) {
 | 
				
			||||||
 | 
					        if (!content) content = '';
 | 
				
			||||||
 | 
					        // Add hidden embed link
 | 
				
			||||||
 | 
					        content += `\n${WebEmbed.hiddenEmbed} \n`;
 | 
				
			||||||
 | 
					        if (webembeds.length > 1) {
 | 
				
			||||||
 | 
					          console.warn('Multiple webembeds are not supported, this will be ignored.');
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        // Const embed = webembeds[0];
 | 
				
			||||||
 | 
					        for (const webE of webembeds) {
 | 
				
			||||||
 | 
					          const data = await webE.toMessage();
 | 
				
			||||||
 | 
					          content += `\n${data}`;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      // Check content
 | 
				
			||||||
 | 
					      if (typeof content == 'string' && content.length > 2000) {
 | 
				
			||||||
 | 
					        console.warn('[WARN] Content is longer than 2000 characters.');
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      if (typeof content == 'string' && content.length > 4000) {
 | 
				
			||||||
 | 
					        // Max length if user has nitro boost
 | 
				
			||||||
 | 
					        throw new RangeError('MESSAGE_EMBED_LINK_LENGTH');
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    this.data = {
 | 
					    this.data = {
 | 
				
			||||||
      webembed,
 | 
					 | 
				
			||||||
      content,
 | 
					      content,
 | 
				
			||||||
      tts,
 | 
					      tts,
 | 
				
			||||||
      nonce,
 | 
					      nonce,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,29 +192,13 @@ class Webhook {
 | 
				
			|||||||
      messagePayload = await MessagePayload.create(this, options).resolveData();
 | 
					      messagePayload = await MessagePayload.create(this, options).resolveData();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let { data, files } = await messagePayload.resolveFiles();
 | 
					    const { data, files } = await messagePayload.resolveFiles();
 | 
				
			||||||
    let webembed = data.webembed;
 | 
					    const d = await this.client.api.webhooks(this.id, this.token).post({
 | 
				
			||||||
    delete data.webembed; //remove webembed
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    let d = await this.client.api.webhooks(this.id, this.token).post({
 | 
					 | 
				
			||||||
      data,
 | 
					      data,
 | 
				
			||||||
      files,
 | 
					      files,
 | 
				
			||||||
      query: { thread_id: messagePayload.options.threadId, wait: true },
 | 
					      query: { thread_id: messagePayload.options.threadId, wait: true },
 | 
				
			||||||
      auth: false,
 | 
					      auth: false,
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (webembed) {
 | 
					 | 
				
			||||||
      data.content = webembed;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      const _d = await this.client.api.webhooks(this.id, this.token).post({
 | 
					 | 
				
			||||||
        data,
 | 
					 | 
				
			||||||
        files,
 | 
					 | 
				
			||||||
        query: { thread_id: messagePayload.options.threadId, wait: true },
 | 
					 | 
				
			||||||
        auth: false,
 | 
					 | 
				
			||||||
      });
 | 
					 | 
				
			||||||
      d.webembed = this.client.channels?.cache.get(_d.channel_id)?.messages._add(_d, false) ?? _d;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 
 | 
					 | 
				
			||||||
    return this.client.channels?.cache.get(d.channel_id)?.messages._add(d, false) ?? d;
 | 
					    return this.client.channels?.cache.get(d.channel_id)?.messages._add(d, false) ?? d;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -171,20 +171,10 @@ class TextBasedChannel {
 | 
				
			|||||||
      messagePayload = await MessagePayload.create(this, options).resolveData();
 | 
					      messagePayload = await MessagePayload.create(this, options).resolveData();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let { data, files } = await messagePayload.resolveFiles();
 | 
					    const { data, files } = await messagePayload.resolveFiles();
 | 
				
			||||||
    let webembed = data.webembed;
 | 
					    const d = await this.client.api.channels[this.id].messages.post({ data, files });
 | 
				
			||||||
    delete data.webembed; //remove webembed
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let d = await this.client.api.channels[this.id].messages.post({ data, files });
 | 
					    return this.messages.cache.get(d.id) ?? this.messages._add(d);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    if (webembed) {
 | 
					 | 
				
			||||||
      data.content = webembed;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
      const _d = await this.client.api.channels[this.id].messages.post({ data, files });
 | 
					 | 
				
			||||||
      d.webembed = this.messages.cache.get(_d.id) ?? this.messages._add(_d);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return this.messages.cache.get(d.id) ?? this.messages._add(d); //webembed missing after cached..  ¯\_(ツ)_/¯
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /**
 | 
					  /**
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user