Skip to content

Commit da50309

Browse files
committed
Removed default tag
1 parent a7fbb93 commit da50309

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

bot.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Imports
22
import { Bot } from "grammy"
33
import { BOT_TOKEN, ADMINS, LIMIT } from "./config.js"
4-
import { isUrl, getRandomId, getProductDetails } from "./utils.js"
4+
import { isUrl, getRandomId, getProductDetails, productCommonUrl } from "./utils.js"
55
import { manageProducts, manageUsers } from "./db.js"
66
import unshort from "./unshort.js"
77

@@ -28,12 +28,11 @@ const processUrl = async (msg, ctx) => {
2828
if (isUrl(productUrl)) {
2929
const merchant = productUrl.replace("www.", "").split("//")[1].split(".")[0];
3030
if (merchant.match(/amazon|flipkart|snapdeal/gi)) {
31-
const noOfProducts = (
32-
await manageProducts({ userId: ctx.from.id }, "read")
33-
)?.result?.length;
31+
const noOfProducts = ( await manageProducts({ userId: ctx.from.id }, "read") )?.result?.length;
3432
if (noOfProducts < LIMIT) {
3533
const sentMsg = await ctx.reply(`Tracking ${merchant} product...`, { reply_to_message_id: ctx.message.message_id });
3634
const details = await getProductDetails(productUrl, merchant);
35+
3736
if (details.ok) {
3837
try {
3938
const tracking_id = getRandomId();
@@ -240,14 +239,14 @@ const track = async () => {
240239
user.userId,
241240
`<a href="${details.image}"> </a><b>Price has been ${details.price > product.price ? "increased" : "decreased"
242241
} by ${Math.abs(product.price - details.price)}</b>. \n\n<b>${details.title
243-
}</b>\n\nCurrent Price: <b>${details.price}</b>\nLink: <a href="${details.link
242+
}</b>\n\nCurrent Price: <b>${details.price}</b>\nLink: <a href="${productCommonUrl(details.link, true)
244243
}">${product.merchant}</a>\n\nTo stop tracking send /stop_${user.tracking_id
245244
}`,
246245
{
247246
parse_mode: "HTML",
248247
reply_markup: {
249248
inline_keyboard: details?.link ? [
250-
[{ text: "Buy Now", url: details.link }],
249+
[{ text: "Buy Now", url: productCommonUrl(details.link, true) }],
251250
[{ text: "Stop Tracking - " + user.tracking_id, callback_data: `stopTracking`, }]]
252251
: []
253252
}

utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cheerio from 'cheerio'
1+
import * as cheerio from 'cheerio'
22
import axios from 'axios'
33
import {WORKER_URL} from './config.js'
44

@@ -28,7 +28,7 @@ const selectors = {
2828
}
2929
}
3030

31-
const productCommonUrl = (link) => {
31+
const productCommonUrl = (link, tag) => {
3232
const url = new URL(link?.replace("www.", ""));
3333
const merchant = url.hostname.split(".")[0];
3434
let id, commonUrl;
@@ -37,7 +37,7 @@ const productCommonUrl = (link) => {
3737
id = link.match(
3838
/https?:\/\/(www\.)?(.*)amazon\.([a-z\.]{2,6})(\/d\/(.*)|\/(.*)\/?(?:dp|o|gp|-)\/)(aw\/d\/|product\/)?(B[0-9]{1}[0-9A-Z]{8}|[0-9]{9}(?:X|[0-9]))/i
3939
).splice(-1)[0];
40-
commonUrl = "https://www.amazon.in/dp/" + id + "?tag=asloot-21";
40+
commonUrl = "https://www.amazon.in/dp/" + id + `${tag ? ('?tag=' + 'asloot-21') : ''}`;
4141
break;
4242
case "flipkart":
4343
id = url.searchParams.get("pid");

0 commit comments

Comments
 (0)