Skip to content

Commit 815f6f5

Browse files
authored
Update autoActionsUtil.js
1 parent ef17d9b commit 815f6f5

File tree

1 file changed

+39
-25
lines changed

1 file changed

+39
-25
lines changed

app/utils/autoActionsUtil.js

+39-25
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import {
22
idAutoBuyerFoundLog,
33
idProgressAutobuyer
44
} from "../elementIds.constants";
5-
import { startAutoBuyer, stopAutoBuyer } from "../handlers/autobuyerProcessor";
5+
import {autoRestartAutoBuyer, startAutoBuyer, stopAutoBuyer} from "../handlers/autobuyerProcessor";
66
import { updateStats } from "../handlers/statsProcessor";
77
import {
88
getValue,
99
increAndGetStoreValue,
1010
setValue
1111
} from "../services/repository";
1212
import {
13-
convertRangeToSeconds,
13+
convertRangeToSeconds, convertSecondsToTime,
1414
getRandNum,
1515
getRandNumberInRange,
1616
hideLoader,
@@ -38,27 +38,41 @@ export const stopBotIfRequired = (buyerSetting) => {
3838
const isSelling = false;
3939
// buyerSetting["idSellCheckBuyPrice"] || buyerSetting["idSellFutBinPrice"];
4040
const isTransferListFull =
41-
isSelling &&
42-
repositories.Item &&
43-
repositories.Item.transfer.length >=
41+
isSelling &&
42+
repositories.Item &&
43+
repositories.Item.transfer.length >=
4444
repositories.Item.pileSizes._collection[5];
4545

46-
if (
47-
isTransferListFull ||
48-
timeElapsed ||
49-
(cardsToBuy && purchasedCardCount >= cardsToBuy)
50-
) {
51-
const message = timeElapsed
46+
const message = timeElapsed
5247
? "Time elapsed"
5348
: isTransferListFull
54-
? "Transfer list is full"
55-
: "Max purchases count reached";
49+
? "Transfer list is full"
50+
: "Max purchases count reached";
5651

57-
if (sendDetailedNotification)
58-
sendNotificationToUser(`Autobuyer stopped | ${message}`);
59-
writeToLog(`Autobuyer stopped | ${message}`, idProgressAutobuyer);
52+
if (timeElapsed){
53+
if (buyerSetting["idAbRestartAfter"]) {
54+
const autoRestart = convertRangeToSeconds(
55+
buyerSetting["idAbRestartAfter"]
56+
);
57+
writeToLog(
58+
`Autobuyer stopped (Time elapsed) | Automatic restart in ${convertSecondsToTime(autoRestart)}`,
59+
idProgressAutobuyer
60+
);
61+
62+
}
6063
stopAfter = null;
61-
stopAutoBuyer();
64+
65+
stopAutoBuyer(false);
66+
autoRestartAutoBuyer();
67+
} else {
68+
if (isTransferListFull || (cardsToBuy && purchasedCardCount >= cardsToBuy)) {
69+
70+
if (sendDetailedNotification)
71+
sendNotificationToUser(`Autobuyer stopped | ${message}`);
72+
writeToLog(`Autobuyer stopped | ${message}`, idProgressAutobuyer);
73+
stopAfter = null;
74+
stopAutoBuyer();
75+
}
6276
}
6377
};
6478

@@ -67,7 +81,7 @@ export const pauseBotIfRequired = async function (buyerSetting) {
6781
if (!isBuyerActive) return;
6882
const pauseFor = convertRangeToSeconds(buyerSetting["idAbPauseFor"]) * 1000;
6983
const cycleAmount =
70-
pauseCycle || getRandNumberInRange(buyerSetting["idAbCycleAmount"]);
84+
pauseCycle || getRandNumberInRange(buyerSetting["idAbCycleAmount"]);
7185
if (!pauseCycle) {
7286
pauseCycle = cycleAmount;
7387
}
@@ -103,9 +117,9 @@ export const switchFilterIfRequired = async function () {
103117
const fiterSearchCount = getValue("fiterSearchCount");
104118
const currentFilterCount = getValue("currentFilterCount");
105119
if (
106-
!availableFilters ||
107-
!availableFilters.length ||
108-
fiterSearchCount > currentFilterCount
120+
!availableFilters ||
121+
!availableFilters.length ||
122+
fiterSearchCount > currentFilterCount
109123
) {
110124
increAndGetStoreValue("currentFilterCount");
111125
return false;
@@ -114,14 +128,14 @@ export const switchFilterIfRequired = async function () {
114128
setValue("currentPage", 1);
115129
const currentFilterIndex = getValue("currentFilterIndex") || 0;
116130
let filterIndex = getValue("runSequentially")
117-
? currentFilterIndex % availableFilters.length
118-
: getRandNum(0, availableFilters.length - 1);
131+
? currentFilterIndex % availableFilters.length
132+
: getRandNum(0, availableFilters.length - 1);
119133

120134
setValue("currentFilterIndex", filterIndex + 1);
121135
let filterName = availableFilters[filterIndex];
122136
await loadFilter.call(this, filterName);
123137
writeToLog(
124-
`--------------------------- Running for filter ${filterName} ---------------------------------------------`,
125-
idAutoBuyerFoundLog
138+
`--------------------------- Running for filter ${filterName} ---------------------------------------------`,
139+
idAutoBuyerFoundLog
126140
);
127141
};

0 commit comments

Comments
 (0)