diff --git a/src/config.ts b/src/config.ts index c694f25..47d1a4a 100644 --- a/src/config.ts +++ b/src/config.ts @@ -9,9 +9,15 @@ const notifications = { password: process.env.EMAIL_PASSWORD ?? '' }, phone: { - availableCarriers: ['sprint', 'verizon', 'tmobile', 'att', 'google'], - carrier: process.env.PHONE_CARRIER, - number: process.env.PHONE_NUMBER + availableCarriers: new Map([ + ['sprint', 'messaging.sprintpcs.com'], + ['verizon', 'vtext.com'], + ['tmobile', 'tmomail.net'], + ['att', 'txt.att.net'], + ['google', 'msg.fi.google.com'] + ]), + carrier: process.env.PHONE_CARRIER ?? '', + number: process.env.PHONE_NUMBER ?? '' }, slack: { channel: process.env.SLACK_CHANNEL ?? '', diff --git a/src/index.ts b/src/index.ts index 05a16a6..8cbbf34 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,13 +5,6 @@ import open from 'open'; import sendNotification from './notification'; import {Logger} from './logger'; -/** - * Send test email. - */ -if (Config.notifications.test === 'true') { - sendNotification('test'); -} - /** * Starts the bot. */ @@ -94,6 +87,13 @@ function isOutOfStock(domText: string, oosLabels: string[]) { return oosLabels.some(label => domTextLowerCase.includes(label)); } +/** + * Send test email. + */ +if (Config.notifications.test === 'true') { + sendNotification('test'); +} + /** * Will continually run until user interferes. */ diff --git a/src/notification/email.ts b/src/notification/email.ts index 4e32217..9090e00 100644 --- a/src/notification/email.ts +++ b/src/notification/email.ts @@ -4,18 +4,19 @@ import {Config} from '../config'; import {Logger} from '../logger'; const subject = 'NVIDIA - BUY NOW'; +const email = Config.notifications.email; const transporter = nodemailer.createTransport({ service: 'gmail', auth: { - user: Config.notifications.email.username, - pass: Config.notifications.email.password + user: email.username, + pass: email.password } }); const mailOptions: Mail.Options = { - from: Config.notifications.email.username, - to: Config.notifications.email.username, + from: email.username, + to: email.username, subject }; diff --git a/src/notification/index.ts b/src/notification/index.ts index 113db25..2b61518 100644 --- a/src/notification/index.ts +++ b/src/notification/index.ts @@ -13,8 +13,8 @@ export default function sendNotification(cartUrl: string) { } if (Config.notifications.phone.number) { - const carrier = Config.notifications.phone.carrier?.toLowerCase(); - if (carrier && Config.notifications.phone.availableCarriers.includes(carrier)) { + const carrier = Config.notifications.phone.carrier.toLowerCase(); + if (carrier && Config.notifications.phone.availableCarriers.has(carrier)) { sendSMS(cartUrl); } } diff --git a/src/notification/sms.ts b/src/notification/sms.ts index e93f97c..30c792d 100644 --- a/src/notification/sms.ts +++ b/src/notification/sms.ts @@ -4,20 +4,13 @@ import {Config} from '../config'; import {Logger} from '../logger'; const subject = 'NVIDIA - BUY NOW'; - -enum carrierAddress { - sprint = 'messaging.sprintpcs.com', - verizon = 'vtext.com', - tmobile = 'tmomail.net', - att = 'txt.att.net', - google = 'msg.fi.google.com' -} +const [email, phone] = [Config.notifications.email, Config.notifications.phone]; const transporter = nodemailer.createTransport({ service: 'gmail', auth: { - user: Config.notifications.email.username, - pass: Config.notifications.email.password + user: email.username, + pass: email.password } }); @@ -41,9 +34,8 @@ export default function sendSMS(text: string) { } function generateAddress() { - const carrier = Config.notifications.phone.carrier?.toLowerCase(); - if (carrier && Object.keys(carrierAddress).includes(carrier)) { - // @ts-expect-error - return [Config.notifications.phone.number, carrierAddress[carrier]].join('@'); + const carrier = phone.carrier.toLowerCase(); + if (carrier && phone.availableCarriers.has(carrier)) { + return [phone.number, phone.availableCarriers.get(carrier)].join('@'); } } diff --git a/src/store/amazon.ts b/src/store/amazon.ts index dde883c..7161a94 100644 --- a/src/store/amazon.ts +++ b/src/store/amazon.ts @@ -7,49 +7,49 @@ export const Amazon: Store = { brand: 'pny', model: 'xlr8', url: 'https://www.amazon.com/PNY-GeForce-Gaming-Epic-X-Graphics/dp/B08HBR7QBM?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'msi', model: 'gaming trio', url: 'https://www.amazon.com/MSI-GeForce-RTX-3080-10G/dp/B08HR7SV3M?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'evga', model: 'ftw3', url: 'https://www.amazon.com/EVGA-10G-P5-3897-KR-GeForce-Technology-Backplate/dp/B08HR3Y5GQ?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'evga', model: 'xc3', url: 'https://www.amazon.com/EVGA-10G-P5-3885-KR-GeForce-Cooling-Backplate/dp/B08HR55YB5?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'gigabyte', model: 'windforce', url: 'https://www.amazon.com/GIGABYTE-GeForce-Graphics-WINDFORCE-GV-N3080GAMING/dp/B08HJTH61J?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'gigabyte', model: 'windforce eagle', url: 'https://www.amazon.com/GIGABYTE-GeForce-Graphics-WINDFORCE-GV-N3080EAGLE/dp/B08HJS2JLJ?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'asus', model: 'tuf', url: 'https://www.amazon.com/ASUS-Graphics-DisplayPort-Military-Grade-Certification/dp/B08HH5WF97?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] }, { brand: 'msi', model: 'ventus', url: 'https://www.amazon.com/MSI-GeForce-RTX-3080-10G/dp/B08HR5SXPS?ref_=ast_sto_dp', - oosLabels: ['currently unavailable', 'Enter the characters you see below'] + oosLabels: ['currently unavailable', 'enter the characters you see below'] } ], name: 'amazon'