Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ an option to reset to autoprice once sold #1212

Merged
merged 2 commits into from
Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/classes/MyHandler/offer/accepted/updateListings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ export default function updateListings(
// If the item is not an unusual sku, we "allow" still (no-op)
const addInvalidUnusual = item.quality === 5 ? opt.pricelist.autoAddInvalidUnusual.enable : true;

const isAutopriceManuallyPricedItem =
opt.pricelist.autoResetToAutopriceOnceSold.enable &&
existsInPricelist &&
priceListEntry.autoprice === false &&
priceListEntry.intent === 2 && // Only if intent is set to bank
amount === 0; // No longer exist

const common1 =
normalizePainted.our === false && // must meet this setting
normalizePainted.their === true && // must meet this setting
Expand Down Expand Up @@ -174,6 +181,40 @@ export default function updateListings(

//

if (isAutopriceManuallyPricedItem) {
const entry: EntryData = {
sku: priceListEntry.sku,
intent: priceListEntry.intent,
enabled: priceListEntry.enabled,
min: priceListEntry.min,
max: priceListEntry.max,
autoprice: true
};

bot.pricelist
.updatePrice({ priceKey, entryData: entry, emitChange: true })
.then(updatedEntry => {
const msg =
`✅ Automatically reset ${entry.sku} to autoprice (item sold).` +
`\nPrevious: ${priceListEntry.buy.toString()}/${priceListEntry.sell.toString()}` +
`\nNew: ${updatedEntry.buy.toString()}/${updatedEntry.sell.toString()}`;
log.debug(msg);

if (opt.sendAlert.enable && opt.sendAlert.autoResetToAutopriceOnceSold) {
if (dwEnabled) {
sendAlert('autoResetToAutopriceOnceSold', bot, msg, null, null, [entry.sku]);
} else {
bot.messageAdmins(msg, []);
}
}

if (isPricecheckRequestEnabled) addToQ(priceKey, isNotPure, existsInPricelist);
})
.catch(err => {
log.warn(`❌ Failed to automatically reset ${entry.sku} to autoprice: `, err);
if (isPricecheckRequestEnabled) addToQ(priceKey, isNotPure, existsInPricelist);
});
}
if (isAutoaddPainted) {
const pSKU = Object.keys(highValueItems[priceKey].p)[0];
const paintedSKU = `${priceKey};${pSKU}`;
Expand Down
6 changes: 6 additions & 0 deletions src/classes/Options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const DEFAULTS: JsonOptions = {
autoRemoveAssetidFailed: true,
autoRemoveAssetidSuccess: true,
autoUpdateAssetid: true,
autoResetToAutopriceOnceSold: true,
autoAddPaintedItems: true,
failedAccept: true,
unableToProcessOffer: true,
Expand All @@ -104,6 +105,9 @@ export const DEFAULTS: JsonOptions = {
filterCantAfford: {
enable: false
},
autoResetToAutopriceOnceSold: {
enable: false
},
autoRemoveIntentSell: {
enable: false
},
Expand Down Expand Up @@ -1163,6 +1167,7 @@ interface SendAlert extends OnlyEnable {
autoRemoveAssetidFailed?: boolean;
autoRemoveAssetidSuccess?: boolean;
autoUpdateAssetid?: boolean;
autoResetToAutopriceOnceSold?: boolean;
autoAddPaintedItems?: boolean;
failedAccept?: boolean;
unableToProcessOffer?: boolean;
Expand Down Expand Up @@ -1197,6 +1202,7 @@ interface HighValueAlert {
interface Pricelist {
partialPriceUpdate?: PartialPriceUpdate;
filterCantAfford?: OnlyEnable;
autoResetToAutopriceOnceSold?: OnlyEnable;
autoRemoveIntentSell?: OnlyEnable;
autoAddInvalidItems?: OnlyEnable;
autoAddInvalidUnusual?: OnlyEnable;
Expand Down
9 changes: 7 additions & 2 deletions src/lib/DiscordWebhook/sendAlert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type AlertType =
| 'escrow-check-failed-not-restart-bptf-down'
| 'escrow-check-failed-not-restart-steam-maintenance'
| 'tryingToTake'
| 'autoResetToAutopriceOnceSold'
| 'autoAddPaintedItems'
| 'autoAddPaintedItemsFailed'
| 'failed-accept'
Expand Down Expand Up @@ -136,11 +137,15 @@ export default function sendAlert(
description = msg;
color = '16711680'; // red
} else if (type === 'autoRemoveAssetidSuccess') {
title = `✅ Automatically removed assetid ${items[0]} from price list`;
title = `Automatically removed assetid ${items[0]} from price list`;
description = msg;
color = '32768'; // green
} else if (type === 'autoResetToAutopriceOnceSold') {
title = `Automatically reset ${items[0]} to autoprice`;
description = msg;
color = '32768'; // green
} else if (type === 'autoUpdateAssetid') {
title = `Automatically updated ${items[0]} with ${items[1]} in price list due to rollback`;
title = `Automatically updated ${items[0]} with ${items[1]} in price list due to rollback`;
description = msg;
color = '32768'; // green
} else if (type === 'autoUpdatePartialPriceSuccess') {
Expand Down
8 changes: 8 additions & 0 deletions src/schemas/options-json/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,9 @@ export const optionsSchema: jsonschema.Schema = {
autoUpdateAssetid: {
type: 'boolean'
},
autoResetToAutopriceOnceSold: {
type: 'boolean'
},
autoAddPaintedItems: {
type: 'boolean'
},
Expand Down Expand Up @@ -575,6 +578,7 @@ export const optionsSchema: jsonschema.Schema = {
'autoRemoveAssetidFailed',
'autoRemoveAssetidSuccess',
'autoUpdateAssetid',
'autoResetToAutopriceOnceSold',
'autoAddPaintedItems',
'failedAccept',
'unableToProcessOffer',
Expand Down Expand Up @@ -607,6 +611,9 @@ export const optionsSchema: jsonschema.Schema = {
filterCantAfford: {
$ref: '#/definitions/only-enable'
},
autoResetToAutopriceOnceSold: {
$ref: '#/definitions/only-enable'
},
autoRemoveIntentSell: {
$ref: '#/definitions/only-enable'
},
Expand Down Expand Up @@ -634,6 +641,7 @@ export const optionsSchema: jsonschema.Schema = {
required: [
'partialPriceUpdate',
'filterCantAfford',
'autoResetToAutopriceOnceSold',
'autoRemoveIntentSell',
'autoAddInvalidItems',
'autoAddInvalidUnusual',
Expand Down