Closed FawnPat closed 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);
}
})();
}
}
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.
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
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.
@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!
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';