Skip to content

Commit

Permalink
💫 v0.3.1 Added "alwaysOnline" function
Browse files Browse the repository at this point in the history
- Added "alwaysOnline" function
- AutoIssue improvements
- Fixed bug when goodsStateCheck didnt started
  • Loading branch information
NightStrang6r committed Sep 6, 2022
1 parent 610013c commit f42b9bb
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 42 deletions.
72 changes: 44 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "funpayserver",
"version": "0.3.0",
"version": "0.3.1",
"description": "CLI app for auto-managing your FunPay account",
"main": "src/index.js",
"dependencies": {
"chalk": "^5.0.1",
"clone": "^2.1.2",
"commander": "^9.4.0",
"fs-extra": "^10.1.0",
"inquirer": "^9.1.0",
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ if(settings.autoResponse == true) {
enableUserDataUpdate(300 * 1000);

// Start runner loop
if(settings.autoIssue == true || settings.autoResponse == true) {
if(settings.alwaysOnline == true || settings.autoIssue == true || settings.autoResponse == true || settings.goodsStateCheck == true) {
await runner.start();
}

Expand Down
34 changes: 22 additions & 12 deletions src/sales.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import c from 'chalk';
import clone from 'clone';
import fetch from './fetch.js';
import { log } from './log.js';
import { parseDOM } from './DOMParser.js';
Expand Down Expand Up @@ -28,17 +29,24 @@ async function checkForNewOrders() {
log(`Проверяем на наличие новых заказов...`, 'c');
orders = await getNewOrders(backupOrders);

if(!orders || !orders.newOrders[0]) {
//log(`Новых заказов нет.`);
if(!orders || orders.newOrders.length == 0) {
log(`Новых заказов нет.`, 'c');
return;
}

const order = orders.newOrders[0];
if(!order) return;
for(let i = 0; i < orders.newOrders.length; i++) {
const order = orders.newOrders[i];

log(`Новый заказ ${c.yellowBright(order.id)} от покупателя ${c.yellowBright(order.buyerName)}`);
issueGood(order.buyerName, order.name);
backupOrders = orders.backupOrders;
if(!order) {
log('!order', 'c');
return;
}

log(`Новый заказ ${c.yellowBright(order.id)} от покупателя ${c.yellowBright(order.buyerName)} на сумму ${c.yellowBright(order.price)} ₽.`);
await issueGood(order.buyerName, order.name);
}

backupOrders = clone(orders.backupOrders);
} catch (err) {
log(`Ошибка при автовыдаче: ${err}`, 'r');
}
Expand Down Expand Up @@ -173,24 +181,26 @@ async function getNewOrders(lastOrders) {
log(`Начальные данные по заказам не переданы`);
return;
}

let result = [];
let orders = [];

try {
orders = await getOrders();
if(!orders || !orders[0]) {
log(`Список продаж пуст`);
log(`Список продаж пуст.`, 'r');
return;
}

const lastOrderId = lastOrders[0].id;
//log(`Last order id: ${lastOrderId}`);

for(let i = 0; i < orders.length; i++) {
if(orders[i].id == lastOrderId) {
if(orders[i].id == lastOrderId || result.length >= 3) {
break;
}

result[i] = orders[i];
result.push(Object.assign(orders[i]));
}
} catch(err) {
log(`Ошибка при получении новых заказов: ${err}`, 'r');
Expand Down Expand Up @@ -229,14 +239,14 @@ async function getOrders() {
const status = order.querySelector(".tc-status").innerHTML;
const price = Number(order.querySelector(".tc-price").firstChild.textContent);

result[i] = {
result.push({
id: id,
name: name,
buyerId: buyerId,
buyerName: buyerName,
status: status,
price: price
}
});
}

return result;
Expand Down
8 changes: 8 additions & 0 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async function loadSettings() {

settings = {
token: answers.token,
alwaysOnline: answers.alwaysOnline,
lotsRaise: answers.lotsRaise,
goodsStateCheck: answers.goodsStateCheck,
autoIssue: answers.autoIssue,
Expand Down Expand Up @@ -178,6 +179,7 @@ async function askSettings() {
console.log();
return {
token: question1.golden_key,
alwaysOnline: true,
lotsRaise: true,
goodsStateCheck: true,
autoIssue: true,
Expand All @@ -186,6 +188,11 @@ async function askSettings() {
}

const answers = await inq.prompt([{
name: 'alwaysOnline',
type: 'list',
message: `Включить функцию вечного онлайна?`,
choices: ['Да', 'Нет']
},{
name: 'lotsRaise',
type: 'list',
message: `Включить функцию автоматического поднятия предложений?`,
Expand All @@ -212,6 +219,7 @@ async function askSettings() {

const askSettings = {
token: question1.golden_key,
alwaysOnline: (answers.alwaysOnline == 'Да') ? true : false,
lotsRaise: (answers.lotsRaise == 'Да') ? true : false,
goodsStateCheck: (answers.goodsStateCheck == 'Да') ? true : false,
autoIssue: (answers.autoIssue == 'Да') ? true : false,
Expand Down

0 comments on commit f42b9bb

Please sign in to comment.