Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions bot.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Imports
const { Bot } = require("grammy");
const { BOT_TOKEN, ADMINS, LIMIT } = require("./config");
const { isUrl, getRandomId, getProductDetails } = require("./utils");
const { manageProducts, manageUsers } = require("./db");
const unshort = require("./unshort");
import { Bot } from "grammy"
import { BOT_TOKEN, ADMINS, LIMIT } from "./config.js"
import { isUrl, getRandomId, getProductDetails } from "./utils.js"
import { manageProducts, manageUsers } from "./db.js"
import unshort from "./unshort.js"

const bot = new Bot(BOT_TOKEN); // Initialize bot

Expand Down Expand Up @@ -257,4 +257,4 @@ bot.catch((err) => {

setInterval(track, 3600000); //Track every hr.

module.exports = bot;
export default bot;
18 changes: 9 additions & 9 deletions config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require('dotenv').config()
import 'dotenv/config'

// Check if bot token is there or not
if(!process.env.BOT_TOKEN) {
Expand All @@ -11,11 +11,11 @@ if(!process.env.DB_URL) {
process.exit(1);
}

module.exports = {
ADMINS: process.env.ADMINS || '',
BOT_TOKEN: process.env.BOT_TOKEN || '',
DB_URL: process.env.DB_URL || '',
WORKER_URL: process.env.WORKER_URL || '',
API_KEY: process.env.API_KEY || '', // Generate any API Key and pass it when accessing the API.
LIMIT: Number(process.env.LIMIT), // Maximum number of products can be added by a user at a time.
}
const ADMINS = process.env.ADMINS || ''
const BOT_TOKEN = process.env.BOT_TOKEN || ''
const DB_URL = process.env.DB_URL || ''
const WORKER_URL = process.env.WORKER_URL || ''
const API_KEY = process.env.API_KEY || '' // Generate any API Key and pass it when accessing the API.
const LIMIT = Number(process.env.LIMIT) // Maximum number of products can be added by a user at a time.

export { ADMINS, BOT_TOKEN, DB_URL, WORKER_URL, API_KEY, LIMIT }
6 changes: 3 additions & 3 deletions db.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const {DB_URL} = require('./config');
const MongoClient = require('mongodb').MongoClient;
import {DB_URL} from './config.js';
import {MongoClient} from 'mongodb';
var mongo;

// Check if mongodb is connected or not
Expand Down Expand Up @@ -65,4 +65,4 @@ const manageProducts = async(data, action) => {
}
}

module.exports = {manageProducts, manageUsers};
export {manageProducts, manageUsers};
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { getRandomId, getProductDetails } = require("./utils");
const { manageProducts, manageUsers } = require("./db");
const {API_KEY} = require('./config');
const express = require('express');
const bot = require('./bot');
import { getRandomId, getProductDetails } from "./utils.js"
import { manageProducts, manageUsers } from "./db.js"
import {API_KEY} from './config.js'
import express from 'express'
import bot from './bot.js'

//Globals
const port = process.env.PORT || 3000;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"type": "git",
"url": "git+https://github.com/AffanTheBest/price-tracker.git"
},
"type": "module",
"keywords": [
"price-tracker",
"amazon",
Expand Down
4 changes: 2 additions & 2 deletions unshort.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const axios = require('axios');
import axios from 'axios';
const unshort = async (url) => {
const extractUrl = req => req?.request?.res?.responseUrl ||
req?.request?._redirectable?._currentUrl ||
Expand All @@ -16,4 +16,4 @@ const unshort = async (url) => {
return longUrl;
}

module.exports = unshort;
export default unshort;
8 changes: 4 additions & 4 deletions utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const cheerio = require('cheerio');
const axios = require('axios');
const {WORKER_URL} = require('./config');
import cheerio from 'cheerio'
import axios from 'axios'
import {WORKER_URL} from './config.js'

const urlRegex = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i;

Expand Down Expand Up @@ -54,4 +54,4 @@ const getProductDetails = async(url, merchant) => {
}
}

module.exports = { isUrl, getRandomId, getProductDetails };
export { isUrl, getRandomId, getProductDetails };