Skip to content

Commit

Permalink
Merge pull request #234 from SeRi0uS007/ignore-listing-price
Browse files Browse the repository at this point in the history
Ignore listing by price
  • Loading branch information
Nuklon authored Dec 21, 2024
2 parents 6b8582f + 294f679 commit 4d9e902
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions code.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
const SETTING_MAX_MISC_PRICE = 'SETTING_MAX_MISC_PRICE';
const SETTING_PRICE_OFFSET = 'SETTING_PRICE_OFFSET';
const SETTING_PRICE_MIN_CHECK_PRICE = 'SETTING_PRICE_MIN_CHECK_PRICE';
const SETTING_PRICE_MIN_LIST_PRICE = 'SETTING_PRICE_MIN_LIST_PRICE';
const SETTING_PRICE_ALGORITHM = 'SETTING_PRICE_ALGORITHM';
const SETTING_PRICE_IGNORE_LOWEST_Q = 'SETTING_PRICE_IGNORE_LOWEST_Q';
const SETTING_PRICE_HISTORY_HOURS = 'SETTING_PRICE_HISTORY_HOURS';
Expand All @@ -215,6 +216,7 @@
SETTING_MAX_MISC_PRICE: 10,
SETTING_PRICE_OFFSET: 0.00,
SETTING_PRICE_MIN_CHECK_PRICE: 0.00,
SETTING_PRICE_MIN_LIST_PRICE: 0.03,
SETTING_PRICE_ALGORITHM: 1,
SETTING_PRICE_IGNORE_LOWEST_Q: 1,
SETTING_PRICE_HISTORY_HOURS: 12,
Expand Down Expand Up @@ -1296,25 +1298,32 @@

const sellQueue = async.queue(
(task, next) => {
totalNumberOfProcessedQueueItems++;

const digits = getNumberOfDigits(totalNumberOfQueuedItems);
const itemId = task.item.assetid || task.item.id;
const itemName = task.item.name || task.item.description.name;
const itemNameWithAmount = task.item.amount == 1 ? itemName : `${task.item.amount}x ${itemName}`;
const padLeft = `${padLeftZero(`${totalNumberOfProcessedQueueItems}`, digits)} / ${totalNumberOfQueuedItems}`;

if (getSettingWithDefault(SETTING_PRICE_MIN_LIST_PRICE) * 100 >= market.getPriceIncludingFees(task.sellPrice)) {
logDOM(`${padLeft} - ${itemNameWithAmount} is not listed due to ignoring price settings.`);
$(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_PRICE_NOT_CHECKED);
next();
return;
}

market.sellItem(
task.item,
task.sellPrice,
(error, data) => {
totalNumberOfProcessedQueueItems++;

const digits = getNumberOfDigits(totalNumberOfQueuedItems);
const itemId = task.item.assetid || task.item.id;
const itemName = task.item.name || task.item.description.name;
const padLeft = `${padLeftZero(`${totalNumberOfProcessedQueueItems}`, digits)} / ${totalNumberOfQueuedItems}`;

const success = Boolean(data?.success);
const message = data?.message || '';

const callback = () => setTimeout(() => next(), getRandomInt(1000, 1500));

if (success) {
const amount = task.item.amount == 1 ? '' : `${task.item.amount}x `;
logDOM(`${padLeft} - ${amount}${itemName} listed for ${formatPrice(market.getPriceIncludingFees(task.sellPrice) * task.item.amount)}, you will receive ${formatPrice(task.sellPrice * task.item.amount)}.`);
logDOM(`${padLeft} - ${itemNameWithAmount} listed for ${formatPrice(market.getPriceIncludingFees(task.sellPrice) * task.item.amount)}, you will receive ${formatPrice(task.sellPrice * task.item.amount)}.`);
$(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_SUCCESS);

totalPriceWithoutFeesOnMarket += task.sellPrice * task.item.amount;
Expand All @@ -1327,7 +1336,7 @@
}

if (message && isRetryMessage(message)) {
logDOM(`${padLeft} - ${itemName} retrying listing because: ${message.charAt(0).toLowerCase()}${message.slice(1)}`);
logDOM(`${padLeft} - ${itemNameWithAmount} retrying listing because: ${message.charAt(0).toLowerCase()}${message.slice(1)}`);

totalNumberOfProcessedQueueItems--;
sellQueue.unshift(task);
Expand All @@ -1339,7 +1348,7 @@
return;
}

logDOM(`${padLeft} - ${itemName} not added to market${message ? ` because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : '.'}`);
logDOM(`${padLeft} - ${itemNameWithAmount} not added to market${message ? ` because: ${message.charAt(0).toLowerCase()}${message.slice(1)}` : '.'}`);
$(`#${task.item.appid}_${task.item.contextid}_${itemId}`).css('background', COLOR_ERROR);

callback();
Expand Down Expand Up @@ -3813,6 +3822,10 @@
Don't check market listings with prices of and below: 
<input type="number" step="0.01" id="${SETTING_PRICE_MIN_CHECK_PRICE}" value=${getSettingWithDefault(SETTING_PRICE_MIN_CHECK_PRICE)}>
</div>
<div style="margin-top:6px;">
Don't list market listings with prices of and below:&nbsp;
<input type="number" step="0.01" id="${SETTING_PRICE_MIN_LIST_PRICE}" value=${getSettingWithDefault(SETTING_PRICE_MIN_LIST_PRICE)}>
</div>
<div style="margin-top:24px">
Show price labels in inventory:&nbsp;
<input type="checkbox" id="${SETTING_INVENTORY_PRICE_LABELS}" ${getSettingWithDefault(SETTING_INVENTORY_PRICE_LABELS) == 1 ? 'checked' : ''}>
Expand Down Expand Up @@ -3865,6 +3878,7 @@
setSetting(SETTING_MAX_MISC_PRICE, $(`#${SETTING_MAX_MISC_PRICE}`, price_options).val());
setSetting(SETTING_PRICE_OFFSET, $(`#${SETTING_PRICE_OFFSET}`, price_options).val());
setSetting(SETTING_PRICE_MIN_CHECK_PRICE, $(`#${SETTING_PRICE_MIN_CHECK_PRICE}`, price_options).val());
setSetting(SETTING_PRICE_MIN_LIST_PRICE, $(`#${SETTING_PRICE_MIN_LIST_PRICE}`, price_options).val())
setSetting(SETTING_PRICE_ALGORITHM, $(`#${SETTING_PRICE_ALGORITHM}`, price_options).val());
setSetting(SETTING_PRICE_IGNORE_LOWEST_Q, $(`#${SETTING_PRICE_IGNORE_LOWEST_Q}`, price_options).prop('checked') ? 1 : 0);
setSetting(SETTING_PRICE_HISTORY_HOURS, $(`#${SETTING_PRICE_HISTORY_HOURS}`, price_options).val());
Expand Down

0 comments on commit 4d9e902

Please sign in to comment.