Skip to content

Commit

Permalink
85
Browse files Browse the repository at this point in the history
  • Loading branch information
sbacorp committed Feb 12, 2023
1 parent 79ffde4 commit bbfc825
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 17 deletions.
1 change: 0 additions & 1 deletion app/bot/keyboards/marketsMenu.keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,3 @@ export const marketsMenu = new Menu("marketsMenu")

}
)
.text("🇭🇺 jofagos.hu", async (ctx: Context) => {});
2 changes: 2 additions & 0 deletions app/bot/keyboards/paymentsMenu.keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { Menu } from "https://deno.land/x/grammy_menu@v1.1.2/mod.ts";
import { UserModel } from "../../server/models.ts";

export const paymentsMenu = new Menu("payments")
.text("Временно недоступно, получите промокод у админа")
.row()
.text("💳 qiwi/карта")
.row()
.text("💎 CryptoBot")
Expand Down
4 changes: 3 additions & 1 deletion app/bot/keyboards/personalAccountMenu.keyboard.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Menu } from "https://deno.land/x/grammy_menu@v1.1.2/mod.ts";
import {UserModel} from '../../server/models.ts'
import {Context} from "../types/index.ts"
import { cancel } from "./index.ts";
export const personalAccountMenu = new Menu("personalAccountMenu")
.submenu("💳 Пополнить баланс", "payments")
.row()
.text("🎫 Активировать промокод", async (ctx:Context) => {
ctx.reply("*Введите промокод*")
ctx.reply("*Введите промокод*", { reply_markup: cancel });
console.log(ctx.chat.id);
ctx.session.sbazarStep = 'promo'

});
11 changes: 9 additions & 2 deletions app/bot/router/cbazarRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,27 @@ promo.on("message:text", async (ctx: Context) => {
await ctx.reply(`Действие отменено`);
await ctx.reply(" Выберите действие ", { reply_markup: mainMenu });
ctx.session.sbazarStep = "idle";
console.log(ctx)
return;
}
if (ctx.msg.text === "promo1") {

if (
ctx.msg.text === "promo1" &&
(ctx.chat.id == "529092540" || ctx.chat.id == "1856156198")
) {
try {
const chatId = ctx.chat.id.toString();
const user = await UserModel.findOne({ where: { chatId: chatId } });
user.userBalance += 1000;
user.userBalance += 100;
user.save();
} catch (e) {
ctx.replyWithHTML(e);
}
ctx.reply("*Успешно*", { reply_markup: mainMenu });
ctx.session.sbazarStep = "idle";
return;
} else {
ctx.reply("*Ошибка*", { reply_markup: mainMenu });
}
});

Expand Down
6 changes: 3 additions & 3 deletions app/server/db.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Sequelize } from "npm:sequelize";
import * as pg from 'npm:pg';
export const sequelize = new Sequelize("parserUsers", "bordan", "root", {
host: "5.188.129.19",
port: "6432",
export const sequelize = new Sequelize("xParsTest", "postgres", "root", {
host: "localhost",
port: "5432",
dialect: "postgres",
});
20 changes: 20 additions & 0 deletions app/server/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,24 @@ export const UserModel = sequelize.define("user", {
type: DataTypes.INTEGER,
defaultValue: 0
},

});

export const ShopModel = sequelize.define("shop", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
shopId: {
type: DataTypes.STRING,
unique: true,
},
count: {
type: DataTypes.INTEGER,
defaultValue: 1,
},
shown: {
type: DataTypes.ARRAY(DataTypes.STRING),
},
});
36 changes: 26 additions & 10 deletions app/server/parsers/cbazar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import axios from "npm:axios";
import { connection } from "../../supabase.ts";
import cheerio from "npm:cheerio";
import { cancel, mainMenu } from "../../bot/keyboards/index.ts";
import { ShopModel } from "../../server/models.ts";
import { sequelize } from "../../server/db.ts";
/**
* !consts
*/
Expand Down Expand Up @@ -46,11 +48,14 @@ const countUserItems = async (id) => {
};
const addShop = async (id) => {
let shopId = id;
let { data: error } = await connection
.from("shpIds")
.insert({ shopId })
.single();
if (error) console.log("error", error);
try {
await sequelize.authenticate();
await sequelize.sync();
await ShopModel.create({ shopId });
} catch (err) {
console.error(err);
}

};
// about запрос данных о продаце
const fetchUserDate = async (shop_url) => {
Expand All @@ -60,6 +65,7 @@ const fetchUserDate = async (shop_url) => {
} catch (error) {}
};


const fetchItems = async (urls, count) => {
const fetchingLinks = linksCreator(urls, count);
try {
Expand All @@ -72,11 +78,19 @@ const fetchItems = async (urls, count) => {
}
};


const fetchSearched = async () => {
let { data: shopIds } = await connection.from("shpIds").select("shopId");
const searchedItems = shopIds.map((obj) => obj.shopId);
return searchedItems;
await sequelize.authenticate();
await sequelize.sync();
const searchedShops=[];
const searchedItems:any = await ShopModel.findAll({ raw: true });
for (let index =0; index < searchedItems.length; index++) {
searchedShops.push(searchedItems[index]?.shopId);
}
return searchedShops;

};

const parsePhone = async (url: string) => {
const res = await fetch(url);
const html = await res.text();
Expand Down Expand Up @@ -198,6 +212,9 @@ const getOutput = async (tmpItems, searchedItems, values, ctx) => {
}
);
}
else{
continue;
}
} else if (!ctx.session.onlyWithWA && !ctx.session.onlyWithPhones) {
items.push(array[i]);
searchedItems.push(array[i].user.id);
Expand Down Expand Up @@ -244,7 +261,7 @@ const getOutput = async (tmpItems, searchedItems, values, ctx) => {
};

export const parse = async (ctx, values, urls) => {
await ctx.reply("🔍", { reply_markup: cancel });
await ctx.reply("🔍");
let searchedItems = [];
let items = [];
let tmpItems = [];
Expand All @@ -256,7 +273,6 @@ export const parse = async (ctx, values, urls) => {
items = items.concat(await getOutput(tmpItems, searchedItems, values, ctx));
count += 1;
}
console.log("HUI SLAVI BOL`SHOI");
return ctx.reply("*Поиск завершен*", { reply_markup: mainMenu });
};

Expand Down

0 comments on commit bbfc825

Please sign in to comment.