SpikeHD / AmazonMonitor

Amazon price checker, item monitor and stock monitor, all shoved into a Discord bot
GNU General Public License v3.0
235 stars 39 forks source link

Possible issue with search? #45

Closed mclenz closed 3 years ago

mclenz commented 3 years ago

Seems search is trying to send an empty message back to Discord, or at least that's my interpretation of this, perhaps I'm interpreting it wrong?

I tried this with '!search Ryzen 9'

/usr/src/app/node_modules/discord.js/src/rest/RequestHandler.js:170
          return reject(new DiscordAPIError(request.path, data, request.method, res.status));
                        ^
DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (/usr/src/app/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
    at processTicksAndRejections (node:internal/process/task_queues:93:5) {
  method: 'post',
  path: '/channels/*REDACTED*/messages',
  code: 50006,
  httpStatus: 400

Running !search Ryzen comes back with 16 results. I also am unable to run !quickwatch 16 for example. It does not add it to the watch list when I do get valid results and run a !quickwatch [number]

I tried googling around, but I think this is specific to the app and how it's processing, or perhaps I did something wrong with the install on my end, but I can't find a solution via googling so far...

Thanks for any help you can provide! Awesome app/bot too, thanks for making it!

SpikeHD commented 3 years ago

This is a weird one, I'll let you know when I've got a solution. In the meantime, what country's Amazon are you using?

mclenz commented 3 years ago

Hey there, I'm looking at US Amazon.

Thanks for looking into it!

SpikeHD commented 3 years ago

Tried doing the same thing and it worked fine. Was there any more to the console output? Can you try it with the debugEnabled config option set to true, and send me the entire output?

mclenz commented 3 years ago

Here's the output with debug enabled:

 ##########################################################################
   _____                                        __      __         __         .__
  /  _  \   _____ _____  ____________   ____   /  \    /  \_____ _/  |_  ____ |  |__   ___________
 /  /_\  \ /     \\__  \ \___   /  _ \ /    \  \   \/\/   /\__  \\   __\/ ___\|  |  \_/ __ \_  __ \
/    |    \  Y Y  \/ __ \_/    (  <_> )   |  \  \        /  / __ \|  | \  \___|   Y  \  ___/|  | \/
\____|__  /__|_|  (____  /_____ \____/|___|  /   \__/\  /  (____  /__|  \___  >___|  /\___  >__|
        \/      \/     \/      \/          \/         \/        \/          \/     \/     \/
  by SpikeHD#3336
  ##########################################################################

[MESSAGE]  Loading command: details.js
[MESSAGE]  Loading command: help.js
[MESSAGE]  Loading command: search.js
[MESSAGE]  Loading command: unwatch.js
[MESSAGE]  Loading command: watch.js
[MESSAGE]  Loading command: watchlist.js
[DEBUG]  Data storage type: json
[MESSAGE]  Watchlist Loaded
[MESSAGE]  Puppeteer Launched
[LOG]  Checking item prices...
[MESSAGE]  Type: headless
[MESSAGE]  Waiting a couple seconds for JavaScript to load...
[DEBUG]  Got page in 7680ms
[MESSAGE]  Type: electronics

                computers & accessories

                computer components

                internal components

                 cpu processors
[DEBUG]  Detected as a regular item
[DEBUG]  Full object:
[DEBUG]  {
  full_title: 'AMD Ryzen 7 5800X 8-core, 16-Thread Unlocked Desktop Processor Without Cooler',
  full_link: 'https://www.amazon.com/dp/B0815XFSGK/??',
  asin: 'B0815XFSGK',
  seller: 'Visit the AMD Store',
  price: '',
  symbol: '',
  shipping: 'Free with prime',
  rating: '4.7 out of 5 stars',
  features: [
    ' - Make sure this fits\nby entering your model number.',
    ' - Make sure this fits\nby entering your model number.',
    ' - by entering your model number.',
    " - AMD's fastest 8 core processor for mainstream desktop, with 16 procesing threads",
    " - Can deliver elite 100+ FPS performance in the world's most popular games",
    ' - Cooler not included, high-performance cooler recommended',
    ' - 4.7 GHz Max Boost, unlocked for overclocking, 36 MB of cache, DDR-3200 support',
    ' - For the advanced Socket AM4 platform, can support PCIe 4.0 on X570 and B550 motherboards'
  ],
  availability: 'Available from these sellers.\n\n\n\n\n\n\n\n\n\nAvailable from these sellers.',
  image: 'https://images-na.ssl-images-amazon.com/images/I/61DYLoyNRWL._AC_SL1384_.jpg'
}
[WARNING]  Detected 2 empty values. Could potentially mean bot was flagged
[MESSAGE]  Type: headless
[MESSAGE]  Waiting a couple seconds for JavaScript to load...
[DEBUG]  Got page in 6289ms
[MESSAGE]  Type: electronics

                computers & accessories

                computer components

                internal components

                 cpu processors
[DEBUG]  Detected as a regular item
[DEBUG]  Full object:
[DEBUG]  {
  full_title: 'AMD Ryzen 9 5900X 12-core, 24-Thread Unlocked Desktop Processor Without Cooler',
  full_link: 'https://www.amazon.com/dp/B08164VTWH/??',
  asin: 'B08164VTWH',
  seller: 'Visit the AMD Store',
  price: '',
  symbol: '',
  shipping: 'Free with prime',
  rating: '4.8 out of 5 stars',
  features: [
    ' - Make sure this fits\nby entering your model number.',
    ' - Make sure this fits\nby entering your model number.',
    ' - by entering your model number.',
    " - The world's best gaming desktop processor, with 12 cores and 24 processing threads",
    " - Can deliver elite 100+ FPS performance in the world's most popular games",
    ' - Cooler not included, high-performance cooler recommended',
    ' - 4.8 GHz Max Boost, unlocked for overclocking, 70 MB of cache, DDR-3200 support',
    ' - For the advanced Socket AM4 platform, can support PCIe 4.0 on X570 and B550 motherboards'
  ],
  availability: 'Currently unavailable.',
  image: 'https://images-na.ssl-images-amazon.com/images/I/616VM20%2BAzL._AC_SL1384_.jpg'
}
[WARNING]  Detected 2 empty values. Could potentially mean bot was flagged
[MESSAGE]  Type: headless
[MESSAGE]  Waiting a couple seconds for JavaScript to load...
[DEBUG]  Search phrase: Ryzen 9
[MESSAGE]  Type: headless
[MESSAGE]  Waiting a couple seconds for JavaScript to load...
[DEBUG]  Got page in 2436ms
[MESSAGE]  Type:
[DEBUG]  Detected as a regular item
[DEBUG]  Full object:
[DEBUG]  {
  full_title: '',
  full_link: 'https://www.amazon.com/dp/B0815Y8J9N/??',
  asin: 'B0815Y8J9N',
  seller: '',
  price: '',
  symbol: '',
  shipping: 'Free with prime',
  rating: '',
  features: [],
  availability: '',
  image: 'https://via.placeholder.com/300x300.png?text=No+Image'
}
[WARNING]  Detected 7 empty values. Could potentially mean bot was flagged
[DEBUG]  Got page in 2391ms
[ERROR]  TypeError: Cannot read property 'forEach' of null
    at Object.module.exports.run (/usr/src/app/commands/search.js:29:8)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async exec (/usr/src/app/index.js:69:3)
/usr/src/app/node_modules/discord.js/src/rest/RequestHandler.js:170
          return reject(new DiscordAPIError(request.path, data, request.method, res.status));
                        ^
DiscordAPIError: Cannot send an empty message
    at RequestHandler.execute (/usr/src/app/node_modules/discord.js/src/rest/RequestHandler.js:170:25)
    at processTicksAndRejections (node:internal/process/task_queues:93:5) {
  method: 'post',
  path: '/channels/*REDACTED*/messages',
  code: 50006,
  httpStatus: 400
}
SpikeHD commented 3 years ago

Well, I can't be sure about why it would be failing to output search results, but I do see the problem with quickwatch, and will try to push a fix later.

mclenz commented 3 years ago

Not sure if it is at all related, but I also noticed several of my watchlist items don't have a title, but one does:

List of Amazon items currently being watched
1.
https://www.amazon.com/dp/B0815XFSGK/

2.
https://www.amazon.com/dp/B08164VTWH/

3.
https://www.amazon.com/dp/B0815Y8J9N/

4.
https://www.amazon.com/dp/B08P7SBD3Q/

5.
https://www.amazon.com/dp/B08NXVNMPQ/

6. Razer Naga Pro Wireless Gaming Mouse: Interchangeable Side Plate w/ 2, 6, 12 Button Configurations -...
https://www.amazon.com/dp/B08D27XXRY/
Currently watching 6 items in this server
mclenz commented 3 years ago

Also, even though the 6th watchlist item has a valid price, it did not pull the price (or so it seems). The watchlist.json file shows price of 0, but Amazon's site shows 149.99

    "link": "https://www.amazon.com/dp/B08D27XXRY/?",
    "lastPrice": 0,
    "item_name": "Razer Naga Pro Wireless Gaming Mouse: Interchangeable Side Plate w/ 2, 6, 12 Button Configurations - Focus+ 20K DPI Optical Sensor - Fastest Gaming Mouse Switch - Chroma RGB Lighting",
    "priceLimit": 0,
    "type": "link"

UPDATE

I unwatched and re-watched, for some reason now it's showing the 149.99 price for the 6th item.

SpikeHD commented 3 years ago

Usually, it's a bad sign when the bot gets the page in around 2000ms instead of about 6000ms, as well as the "Empty values" warning. Usually this means that the page Amazon returns is not the page of the item, but a captcha or other form of rate-limiting. Best thing you can do in that scenario is stop the bot for a little while, go onto Amazon from a browser and make sure it works fine that way, and try again in a few minutes.

There is no real fix for this other than waiting, unfortunately.

mclenz commented 3 years ago

I think you're right. I stopped the bot, and ran a curl command manually, and see this:

        <div class="a-box a-alert a-alert-info a-spacing-base">
            <div class="a-box-inner">
                <i class="a-icon a-icon-alert"></i>
                <h4>Enter the characters you see below</h4>
                <p class="a-last">Sorry, we just need to make sure you're not a robot. For best results, please make sure your browser is accepting cookies.</p>
                </div>
            </div>

            <div class="a-section">

                <div class="a-box a-color-offset-background">
                    <div class="a-box-inner a-padding-extra-large">

                        <form method="get" action="/errors/validateCaptcha" name="">
                            <input type=hidden name="amzn" value="Q6WewgCroX9xOtMN562xdw==" /><input type=hidden name="amzn-r" value="&#047;Razer&#045;Naga&#045;Wireless&#045;Gaming&#045;Mouse&#047;dp&#047;B08D27XXRY&#047;ref&#061;sr_1_1_sspa?dchild&#061;1" />

I wasn't aware of the captcha's Amazon does just for browsing pages, probably because I usually do it as a human manually. That's a bit of a bummer. I guess I'll wait a while and see if that goes away, and if so, set the interval for every 5 min or so maybe.

Thanks for checking in on it, and sorry for wasting your time!

SpikeHD commented 3 years ago

No worries! It's not the most clear of issues. I'll see about making the interval a tweak-able setting in order to try and prevent stuff like this.