mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 05:17:35 +00:00
refactor: doc and notification (#42)
Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
+15
-21
@@ -3,38 +3,32 @@ import {config} from 'dotenv';
|
||||
|
||||
config({path: resolve(__dirname, '../.env')});
|
||||
|
||||
const email = {
|
||||
username: process.env.EMAIL_USERNAME,
|
||||
password: process.env.EMAIL_PASSWORD,
|
||||
test: process.env.EMAIL_TEST ?? 'false'
|
||||
};
|
||||
|
||||
const notifications = {
|
||||
email: email.username && email.password
|
||||
email: {
|
||||
username: process.env.EMAIL_USERNAME ?? '',
|
||||
password: process.env.EMAIL_PASSWORD ?? ''
|
||||
},
|
||||
slack: {
|
||||
channel: process.env.SLACK_CHANNEL ?? '',
|
||||
token: process.env.SLACK_TOKEN ?? ''
|
||||
},
|
||||
test: process.env.NOTIFICATION_TEST ?? 'false'
|
||||
};
|
||||
|
||||
const page = {
|
||||
height: 1920,
|
||||
navigationTimeout: Number(process.env.PAGE_TIMEOUT) ?? 30000,
|
||||
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
|
||||
width: 1080,
|
||||
navigationTimeout: Number(process.env.PAGE_TIMEOUT) ?? 30000
|
||||
width: 1080
|
||||
};
|
||||
|
||||
const rateLimitTimeout = Number(process.env.RATE_LIMIT_TIMEOUT) ?? 5000;
|
||||
|
||||
const stores = process.env.STORES ?? 'nvidia';
|
||||
|
||||
const notificationMethods = process.env.NOTIFICATION_METHODS ?? 'email';
|
||||
|
||||
const slack = {
|
||||
channel: process.env.SLACK_CHANNEL,
|
||||
token: process.env.SLACK_TOKEN
|
||||
};
|
||||
|
||||
export const Config = {
|
||||
email,
|
||||
notifications,
|
||||
rateLimitTimeout,
|
||||
page,
|
||||
rateLimitTimeout: 5000,
|
||||
stores,
|
||||
slack,
|
||||
notificationMethods
|
||||
stores
|
||||
};
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import {Logger} from './logger';
|
||||
/**
|
||||
* Send test email.
|
||||
*/
|
||||
if (Config.email.test === 'true') {
|
||||
if (Config.notifications.test === 'true') {
|
||||
sendNotification('test');
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ async function main() {
|
||||
await Promise.all(results);
|
||||
|
||||
Logger.info('↗ trying stores again');
|
||||
setTimeout(main, Config.rateLimitTimeout);
|
||||
setTimeout(main, Config.page.rateLimitTimeout);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,11 +3,11 @@ import sendEmail from './email';
|
||||
import sendSlaskMessage from './slack';
|
||||
|
||||
export default function sendNotification(cartUrl: string) {
|
||||
if (Config.notificationMethods.toLocaleLowerCase().includes('email')) {
|
||||
if (Config.notifications.email.username && Config.notifications.email.password) {
|
||||
sendEmail(cartUrl);
|
||||
}
|
||||
|
||||
if (Config.notificationMethods.toLocaleLowerCase().includes('slack')) {
|
||||
if (Config.notifications.slack.channel && Config.notifications.slack.token) {
|
||||
sendSlaskMessage(cartUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ import {WebClient} from '@slack/web-api';
|
||||
import {Config} from '../config';
|
||||
import {Logger} from '../logger';
|
||||
|
||||
const channel = Config.slack.channel ?? '';
|
||||
const token = Config.slack.token ?? '';
|
||||
const channel = Config.notifications.slack.channel;
|
||||
const token = Config.notifications.slack.token;
|
||||
const web = new WebClient(token);
|
||||
|
||||
export default function sendSlackMessage(text: string) {
|
||||
|
||||
Reference in New Issue
Block a user