jef / streetmerchant

🤖 The world's easiest, most powerful stock checker
https://jef.buzz/streetmerchant
MIT License
4.97k stars 1.3k forks source link

redis error - Bot won't run #1619

Closed FawnPat closed 3 years ago

FawnPat commented 3 years ago

Expected Behavior

Ideally, the bot would run

Current Behavior

I ran git pull to update my bot to the latest version, and when when I try to run it, I receive the following 2 errors (I'm posting them both here because I'm not cure if they're related, though I notice they are returning the same error code):

src/notification/redis.ts:2:34 - error TS2307: Cannot find module 'redis' or its corresponding type declarations.

2 import redis, {RedisClient} from 'redis';



src/util.ts:6:27 - error TS2307: Cannot find module 'top-user-agents' or its corresponding type declarations.

6 import topUserAgents from 'top-user-agents';

I

<!-- Tell us what happens instead of the expected behavior -->

## Steps to Reproduce

<!-- Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. -->
<!-- Include code to reproduce, if relevant -->

## Environment

- OS: Windows 10

<!-- Put your dotenv within backticks below. Be sure to remove any secrets/passwords. -->
```dotenv

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         # ** All configuration variables are optional **
# Read https://github.com/jef/streetmerchant#customization for help on customizing this file                                                                                                                                             
#############################################################################################

ASCII_BANNER=
ASCII_COLOR=
AUTO_ADD_TO_CART=
BROWSER_TRUSTED=
COUNTRY="usa"
DESKTOP_NOTIFICATIONS=
DISCORD_NOTIFY_GROUP=
DISCORD_WEB_HOOK=""
EMAIL_PASSWORD=""
EMAIL_TO=
EMAIL_USERNAME=""
HEADLESS=
IN_STOCK_WAIT_TIME="1800"
LOG_LEVEL=
LOW_BANDWIDTH=
MAX_PRICE_SERIES_3060TI="650"
MAX_PRICE_SERIES_3070="700"
MAX_PRICE_SERIES_3080="1000"
MAX_PRICE_SERIES_3090="1900"
MAX_PRICE_SERIES_RYZEN5600="400"
MAX_PRICE_SERIES_RYZEN5800="550"
MAX_PRICE_SERIES_RYZEN5900="650"
MAX_PRICE_SERIES_RYZEN5950="900"
MAX_PRICE_SERIES_SONYPS5C="600"
MAX_PRICE_SERIES_SONYPS5DE="500"
MAX_PRICE_SERIES_RX6800="725"
MAX_PRICE_SERIES_RX6800XT="800"
MAX_PRICE_SERIES_RX6900XT="1150"
MICROCENTER_LOCATION=
MQTT_BROKER_ADDRESS=
MQTT_BROKER_PORT=
MQTT_CLIENT_ID=
MQTT_PASSWORD=
MQTT_QOS=
MQTT_TOPIC=
MQTT_USERNAME=
NVIDIA_ADD_TO_CART_ATTEMPTS=
NVIDIA_SESSION_TTL=
OPEN_BROWSER="false"
PAGE_BACKOFF_MIN=
PAGE_BACKOFF_MAX=
PAGE_SLEEP_MIN="15000"
PAGE_SLEEP_MAX="20000"
PAGE_TIMEOUT="60000"
PAGERDUTY_INTEGRATION_KEY=
PAGERDUTY_SEVERITY=
PHILIPS_HUE_API_KEY=
PHILIPS_HUE_CLOUD_ACCESS_TOKEN=
PHILIPS_HUE_CLOUD_CLIENT_ID=
PHILIPS_HUE_CLOUD_CLIENT_SECRET=
PHILIPS_HUE_CLOUD_REFRESH_TOKEN=
PHILIPS_HUE_LAN_BRIDGE_IP=
PHILIPS_HUE_LIGHT_COLOR=
PHILIPS_HUE_LIGHT_IDS=
PHILIPS_HUE_LIGHT_PATTERN=
PHONE_CARRIER=""
PHONE_NUMBER=""
PLAY_SOUND=
PROXY_ADDRESS=
PROXY_PORT=
PUSHBULLET=
PUSHOVER_TOKEN=
PUSHOVER_USER=
PUSHOVER_PRIORITY=
SCREENSHOT=
SHOW_ONLY_BRANDS="amd,asus,evga,gigabyte,microsoft,msi,nvidia,sony,zotac"
SHOW_ONLY_MODELS="5600x,5800x,5900x,5950x,amd reference,dual,dual oc,strix,strix oc,tuf,tuf oc,ftw3,ftw3 ultra,xc3,xc3 black,xc3 ultra,aorus master,aorus xtreme,eagle,eagle oc,gaming,gaming oc,turbo,vision,vision oc,xbox series x,xbox series s,gaming x trio,ventus 2x oc,ventus 3x,ventus 3x oc,founders edition,ps5 console,ps5 digital,amp holo,amp extreme holo,trinity,trinity oc,twin edge,twin edge oc"
SHOW_ONLY_SERIES="ryzen5600,ryzen5800,ryzen5900,ryzen5950,rx6800,rx6800xt,rx6900xt,3060ti,3070,3080,3090,sonyps5c,sonyps5de,xboxss,xboxsx"
SLACK_CHANNEL=
SLACK_TOKEN=
SMTP_ADDRESS=
SMTP_PORT=
STORES="bestbuy,blt,walmart,target,newegg,tigerdirect,adorama,amd,asus,bandh,bestbuy-ca,gamestop,evga,newegg-ca,nvidia,officedepot,amazon,amazon-ca"
TELEGRAM_ACCESS_TOKEN=
TELEGRAM_CHAT_ID=
TWILIO_ACCOUNT_SID=
TWILIO_AUTH_TOKEN=
TWILIO_FROM_NUMBER=
TWILIO_TO_NUMBER=
TWITCH_ACCESS_TOKEN=
TWITCH_CHANNEL=
TWITCH_CLIENT_ID=
TWITCH_CLIENT_SECRET=
TWITCH_REFRESH_TOKEN=
TWITTER_ACCESS_TOKEN_KEY=
TWITTER_ACCESS_TOKEN_SECRET=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=
TWITTER_TWEET_TAGS=
USER_AGENT=
WEB_PORT=

```

## Logs

<!-- Provide a brief log -->
```
0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Users\\Distill\\Desktop\\streetmerchant\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'run',
0 verbose cli   'build'
0 verbose cli ]
1 info using npm@7.1.1
2 info using node@v15.2.1
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:C:\Users\Distill\Desktop\streetmerchant\node_modules\npm\npmrc Completed in 0ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 0ms
7 timing config:load:env Completed in 1ms
8 timing config:load:file:C:\Users\Distill\Desktop\streetmerchant\.npmrc Completed in 1ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:C:\Users\Distill\.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:C:\Users\Distill\AppData\Roaming\npm\etc\npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 1ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 5ms
19 verbose npm-session 08e3d2e538503b25
20 timing npm:load Completed in 12ms
21 timing command:run-script Completed in 5639ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (C:\Users\Distill\Desktop\streetmerchant\node_modules\npm\node_modules\@npmcli\promise-spawn\index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:329:20)
22 verbose stack     at maybeClose (node:internal/child_process:1055:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
23 verbose cwd C:\Users\Distill\Desktop\streetmerchant
24 verbose Windows_NT 10.0.19042
25 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Distill\\Desktop\\streetmerchant\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
26 verbose node v15.2.1
27 verbose npm  v7.1.1
28 error code 2
29 error path C:\Users\Distill\Desktop\streetmerchant
30 error command failed
31 error command C:\Windows\system32\cmd.exe /d /s /c tsc
32 verbose exit 2

0 verbose cli [
0 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
0 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
0 verbose cli   'run',
0 verbose cli   'start'
0 verbose cli ]
1 info using npm@7.0.8
2 info using node@v15.2.1
3 timing config:load:defaults Completed in 1ms
4 timing config:load:file:C:\Program Files\nodejs\node_modules\npm\npmrc Completed in 1ms
5 timing config:load:builtin Completed in 1ms
6 timing config:load:cli Completed in 1ms
7 timing config:load:env Completed in 0ms
8 timing config:load:file:C:\Users\Distill\Desktop\streetmerchant\.npmrc Completed in 0ms
9 timing config:load:project Completed in 1ms
10 timing config:load:file:C:\Users\Distill\.npmrc Completed in 0ms
11 timing config:load:user Completed in 0ms
12 timing config:load:file:C:\Users\Distill\AppData\Roaming\npm\etc\npmrc Completed in 0ms
13 timing config:load:global Completed in 0ms
14 timing config:load:cafile Completed in 0ms
15 timing config:load:validate Completed in 0ms
16 timing config:load:setUserAgent Completed in 0ms
17 timing config:load:setEnvs Completed in 0ms
18 timing config:load Completed in 5ms
19 verbose npm-session 9516842339997f24
20 timing npm:load Completed in 12ms
21 timing command:run-script Completed in 5962ms
22 verbose stack Error: command failed
22 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\@npmcli\promise-spawn\index.js:64:27)
22 verbose stack     at ChildProcess.emit (node:events:329:20)
22 verbose stack     at maybeClose (node:internal/child_process:1055:16)
22 verbose stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:288:5)
23 verbose cwd C:\Users\Distill\Desktop\streetmerchant
24 verbose Windows_NT 10.0.19042
25 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
26 verbose node v15.2.1
27 verbose npm  v7.0.8
28 error code 2
29 error path C:\Users\Distill\Desktop\streetmerchant
30 error command failed
31 error command C:\Windows\system32\cmd.exe /d /s /c "npm run build && node build/index.js"
32 verbose exit 2
```
FawnPat commented 3 years ago

I should also note, I made some modifications to my src/notification/discord.ts file. Not ure this has any bearing on the issues above, but I thought I'd post this just in case:

import {Link, Store} from '../store/model';
import Discord from 'discord.js';
import {config} from '../config';
import {logger} from '../logger';

const discord = config.notifications.discord;
const {notifyGroup, webhooks, notifyGroupSeries} = discord;

function getIdAndToken(webhook: string) {
    const match = /.*\/webhooks\/(\d+)\/(.+)/.exec(webhook);

    if (!match) {
        throw new Error('could not get discord webhook');
    }

    return {
        id: match[1],
        token: match[2]
    };
}

export function sendDiscordMessage(link: Link, store: Store) {
    if (webhooks.length > 0) {
        logger.debug('↗ sending discord message');

        (async () => {
            try {
                var storeTest:string = '';
                var brand:string = '';
                var series:string = '';
                var model:string = '';
                var dgroup:string = '';
                var dhook: string = '';
                const embed = new Discord.MessageEmbed();
                    //.setTitle('_**Stock alert!**_')
                    //.setDescription(
                        //'> provided by [streetmerchant](https://github.com/jef/streetmerchant) with :heart:'
                    //)
                    //.setThumbnail(
                        //'https://raw.githubusercontent.com/jef/streetmerchant/main/docs/assets/images/streetmerchant-logo.png'
                    //)
                    embed.setColor('#52b788')
                    embed.setTimestamp();

                embed.addField('Store', store.name, true);
                if (link.price)
                    embed.addField(
                        'Price',
                        `${store.currency}${link.price}`,
                        true
                    );
                embed.addField('Product Page', link.url);
                if (link.cartUrl) embed.addField('Add to Cart', link.cartUrl);
                //embed.addField('Brand', link.brand, true);
                //embed.addField('Model', link.model, true);
                //embed.addField('Series', link.series, true);
                embed.addField('Product Info', link.brand.toUpperCase() + " " + link.model + " " + link.series);
                embed.addField('Words of Wisdom', 'Be Quick and Good Luck!', true);
                brand = link.brand;
                series = link.series;
                model = link.model;
                storeTest = store.name;

                var stringTest:number = storeTest.indexOf("-ca");

                if (stringTest >= 0) {
                    embed.setTitle('Canukistanadian Stock Found - Go Go Go!!!');
                    dhook = 'https://discord.com/api/webhooks/784265158314426388/hidfayEfMlARshQ3R2mI-ha8kVB99B5CTXa_zSO1nXaN6DcdD773N9D47DRpaDYEwbSL';
                    dgroup = '<@784263914938564609>';
                } else {
                    if (series == '3080') {
                        embed.setTitle('3080 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/778053339023540225/ly_CARYvD93mIfS6C8KNIe2pv52BFqT8Sf9CHJuqmVo8EQk_hdhu35JNgc6csQpoD9U8';
                        dgroup = '<@&778108928109051924>';
                    } else if (series == '3090') {
                        embed.setTitle('3090 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784256860840263700/ash3UbzOUYM8XLqZ0RRT8NllUjA_MoAP9I4waFuG627UDw_u9c5RkEX-KbPZUKJz16T6';
                        dgroup = '<@&784256770562064406>';
                    } else if (series == '3070') {
                        embed.setTitle('3070 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784257028104781845/EjgbQMIzpkfpK8qdZf7et-Vc-CrEZdEk4D4NjWxbxh3SUsR0QTNk82Fg8-4WeOZhlWIc';
                        dgroup = '<@&784255285594161153>';
                    } else if (series == '3060ti') { 
                        embed.setTitle('3060ti In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784257225807233064/Te9r3bTwno9S6lEXtDzYKsCnSHWaZfpOdP1v46AOkdPZO863zWtHQQryZ8h3zBe2a-oG';
                        dgroup = '<@&784256955081424936>';
                    } else if (brand == 'microsoft' || series == 'xboxss' || series == 'xboxsx' || model == 'xbox series x' || model == 'xbox series s') {
                        embed.setTitle('Xbox In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/778096321923645462/M9eEnSQQJTu42Nfsrk2iL5u19CAE53oF3wS-AxMVIdY7suRZaNVCQT8_wplICmQlwSv6';
                        dgroup = '<@&778109229872971776>' ;
                    } else if (brand == 'sony' || series == 'sonyps5c' || series == 'sonyps5de' || model == 'ps5 console' || model == 'ps5 digital') {
                        embed.setTitle('PS5 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/778096168819228673/_IL1gvv8PkEidZpLdCE_LSyJKZOIxejTHQkIsdckZJ3wfvdH6hAEZKofU3Ff_SnnPX7f';
                        dgroup = '<@&778109285216944128>';
                    } else if (series == 'rx6800') {
                        embed.setTitle('rx6800 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784258418398593044/pFqtENXJHaqcwIEg-NsHz5MZ60iyprSGs4UdoKXPVkWWBTTJ0B9vw-lR8SXRrg9rnPmF';
                        dgroup = '<@&784254403129245747>';
                    } else if (series == 'rx6800xt') {
                        embed.setTitle('rx6800xt In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/778096437812264970/UUtYATL4stknlK4OE7RUFqZgwEHyIBudXzh_rAYkITpQGDJqjm5RiKIGcJQncIKrgiQv';
                        dgroup = '<@&778109085697835008>';
                    } else if (series == 'rx6900xt') {
                        embed.setTitle('rx6900xt In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784258543024734239/0FqOuwBJEvp-6AdLmlpQitU4sBqbEISi-nmaL05dp6XpvqjhQyCVzS7N1Ok5V9zfFDgz';
                        dgroup = '<@&784255231105040404>';
                    } else if (series == 'ryzen5600') {
                        embed.setTitle('Ryzen 5600 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784259512684773427/-jOt5AWudYUT63cB6hBodxS4CALjBJKzIGjKcJHtNTFaL-q6EBVagtlfObJJE8ZIEAkU';
                        dgroup = '<@&784257312751616040>';
                    } else if (series == 'ryzen5800') {
                        embed.setTitle('Ryzen 5800 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784259658201301052/c0eduEiAy5zVPTGrauUM7pmrCwaLgEXAbIH4y9Z4M1l8_JjrSR_Qcza9z5OoNvYQzrhQ';
                        dgroup = '<@&784257075618250792>';
                    } else if (series == 'ryzen5900') {
                        embed.setTitle('Ryzen 5900 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/778096380459352085/u3M3kbnLWXgKWPhwRcZSQLWZskekjfKyVjyd7PbK4uQgjjn2pSvcSz-811i7D9bhnxxj';
                        dgroup = '<@&778109166282735626>';
                    } else if (series == 'ryzen5950') {
                        embed.setTitle('Ryzen 5950 In Stock - Go Go Go!!!');
                        dhook = 'https://discord.com/api/webhooks/784259888787488819/UW0gKk8M6xWcYYyB27SkWT6xZJ1SQJ1C8B7gMY8T84MtKVHsedBdJ-0SVksVqXGU1Ytd';
                        dgroup = '<@&784257729534361660>';
                    }
                }

                embed.setTimestamp();

                //let notifyText: string[] = [];

                //if (notifyGroup) {
                    //notifyText = notifyText.concat(notifyGroup);
                //}

                //if (Object.keys(notifyGroupSeries).indexOf(link.series) !== 0) {
                    //notifyText = notifyText.concat(
                        //notifyGroupSeries[link.series]
                    //);
                //}

                const promises = [];
                for (const webhook of webhooks) {
                    const {id, token} = getIdAndToken(dhook);
                    const client = new Discord.WebhookClient(id, token);

                    promises.push({
                        client,
                        message: client.send(dgroup, {
                            embeds: [embed],
                            username: 'Anorak'
                        })
                    });
                }

                (await Promise.all(promises)).forEach(({client}) =>
                    client.destroy()
                );

                logger.info('✔ discord message sent');
            } catch (error: unknown) {
                logger.error("✖ couldn't send discord message", error);
            }
        })();
    }
}
wofnull commented 3 years ago

First of all: Please cleanup the posted dotenv file, remove the discord webhook ( can be used to spam your discord ), your mail adress and phone number for privacy reasons.

So without knowing what changes else were made i assume that you forked the github repo to an external / private git server, which is in basicly not a problem but makes tracking changes that were made on your end aswell as the last state you were working in the origin base and to which version you updated most likely not really good trackable for us.

However since this is about redis, i will assume that the most recent version of your working bot was before the commits on Dec 26, 2020? ( redis was added on this date and got an hotfix directly ) Please take a look into the changes from https://github.com/jef/streetmerchant/commit/fb82526a427e503fff1f1cf56b091ff0c8a5a96e ( REDIS added to project ) https://github.com/jef/streetmerchant/commit/6bc7737ef04e5592e19b0b6a76e5fb0cd4b048df ( Disable REDIS if not present or configured in dotenv file ) https://github.com/jef/streetmerchant/commit/a908ce417bf10d497c1f9531f2187f4379606432 ( REDIS Initialization process ) if anything interferes with your changes or was not updated during your pull / merge. As said before , we can only assume what is different in your repo, since we cannot see it here on github.

FawnPat commented 3 years ago

First of all:

Please cleanup the posted dotenv file, remove the discord webhook ( can be used to spam your discord ), your mail adress and phone number for privacy reasons.

So without knowing what changes else were made i assume that you forked the github repo to an external / private git server, which is in basicly not a problem but makes tracking changes that were made on your end aswell as the last state you were working in the origin base and to which version you updated most likely not really good trackable for us.

However since this is about redis, i will assume that the most recent version of your working bot was before the commits on Dec 26, 2020? ( redis was added on this date and got an hotfix directly )

Please take a look into the changes from

https://github.com/jef/streetmerchant/commit/fb82526a427e503fff1f1cf56b091ff0c8a5a96e ( REDIS added to project )

https://github.com/jef/streetmerchant/commit/6bc7737ef04e5592e19b0b6a76e5fb0cd4b048df ( Disable REDIS if not present or configured in dotenv file )

https://github.com/jef/streetmerchant/commit/a908ce417bf10d497c1f9531f2187f4379606432 ( REDIS Initialization process )

if anything interferes with your changes or was not updated during your pull / merge.

As said before , we can only assume what is different in your repo, since we cannot see it here on github.

Thanks Wofnull.

You are correct, the last working version we had was before those commits.

I'll take a look at the items you've linked

jef commented 3 years ago

Thanks @wofnull! @FawnPat, if you've only changed the Discord implementation, I would stash your change and just whatever latest is in main and pop back your changes.

If there's more to your changes, the suggestions from @wofnull will put you in a good direction.

FawnPat commented 3 years ago

@jef @wofnull Thank you both for you responses.

After reviewing the items posted by @wofnull and reading the error messages again, I realized I had forgotten to run npm install after updating the bot, so naturally it didn't have the resources it needed to run properly.

After running npm install the bot is working once again!