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

🐛 fix manual pricing reverted to autoprice #492

Merged
merged 3 commits into from
Mar 25, 2021
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
110 changes: 65 additions & 45 deletions src/classes/Commands/sub-classes/PricelistManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export default class PricelistManagerCommands {
params.enabled = true;
}

if (params.max === undefined) {
params.max = 1;
}

if (params.min === undefined) {
params.min = 0;
}

if (params.max === undefined) {
params.max = 1;
}

if (params.intent === undefined) {
params.intent = 2;
} else if (typeof params.intent === 'string') {
Expand Down Expand Up @@ -130,10 +130,10 @@ export default class PricelistManagerCommands {

if (params.group && typeof params.group !== 'string') {
// if group parameter is defined, convert anything to string
params.group = (params.group as string).toString();
params.group = String(params.group);
}

if (typeof params.group === undefined) {
if (params.group === undefined) {
// If group parameter is not defined, set it to null.
params['group'] = 'all';
}
Expand Down Expand Up @@ -206,14 +206,14 @@ export default class PricelistManagerCommands {
params.enabled = true;
}

if (params.max === undefined) {
params.max = 1;
}

if (params.min === undefined) {
params.min = 0;
}

if (params.max === undefined) {
params.max = 1;
}

if (params.intent === undefined) {
params.intent = 2;
} else if (typeof params.intent === 'string') {
Expand All @@ -231,14 +231,25 @@ export default class PricelistManagerCommands {
if (params.autoprice === undefined) {
params.autoprice = false;
}
} else if (typeof params.buy !== 'object' && typeof params.sell === 'object') {
params['buy'] = {
keys: 0,
metal: 0
};
}

if (typeof params.sell === 'object') {
params.sell.keys = params.sell.keys || 0;
params.sell.metal = params.sell.metal || 0;

if (params.autoprice === undefined) {
params.autoprice = false;
}
} else if (typeof params.sell !== 'object' && typeof params.buy === 'object') {
params['sell'] = {
keys: 0,
metal: 0
};
}

if (
Expand Down Expand Up @@ -295,10 +306,10 @@ export default class PricelistManagerCommands {

if (params.group && typeof params.group !== 'string') {
// if group parameter is defined, convert anything to string
params.group = (params.group as string).toString();
params.group = String(params.group);
}

if (typeof params.group === undefined) {
if (params.group === undefined) {
// If group parameter is not defined, set it to null.
params['group'] = 'all';
}
Expand Down Expand Up @@ -559,39 +570,38 @@ export default class PricelistManagerCommands {
}

newPricelist.forEach((entry, i) => {
if (params.intent || params.intent === 0) {
if (typeof params.intent === 'number') {
entry.intent = params.intent as 0 | 1 | 2;
}

if (params.min === 0 || typeof params.min === 'number') {
entry.min = params.min as number;
if (typeof params.min === 'number') {
entry.min = params.min;
}

if (params.max === 0 || typeof params.max === 'number') {
entry.max = params.max as number;
if (typeof params.max === 'number') {
entry.max = params.max;
}

if (typeof params.enabled === 'boolean') {
entry.enabled = params.enabled;
}

if (params.group) {
entry.group = (params.group as string).toString();
entry.group = String(params.group);
}

if (params.removenote && typeof params.removenote === 'boolean' && params.removenote === true) {
if (params.removenote === true) {
// Sending "!update all=true&removenote=true" will set both
// note.buy and note.sell for entire/withgroup entries to null.
if (entry.note) {
entry.note.buy = null;
entry.note.sell = null;
}
entry.note.buy = null;
entry.note.sell = null;
}

if (typeof params.autoprice === 'boolean') {
if (params.autoprice === false) {
entry.time = null;
}

entry.autoprice = params.autoprice;
}

Expand All @@ -602,7 +612,7 @@ export default class PricelistManagerCommands {
entry.note.sell = params.note.sell || entry.note.sell;
}

if (typeof params.buy === 'object' && params.buy !== null) {
if (typeof params.buy === 'object') {
entry.buy.keys = params.buy.keys || 0;
entry.buy.metal = params.buy.metal || 0;

Expand All @@ -611,7 +621,7 @@ export default class PricelistManagerCommands {
}
}

if (typeof params.sell === 'object' && params.sell !== null) {
if (typeof params.sell === 'object') {
entry.sell.keys = params.sell.keys || 0;
entry.sell.metal = params.sell.metal || 0;

Expand All @@ -627,8 +637,8 @@ export default class PricelistManagerCommands {
sku: entry.sku,
enabled: entry.enabled,
intent: entry.intent,
max: entry.max,
min: entry.min,
max: entry.max,
autoprice: entry.autoprice,
buy: entry.buy.toJSON(),
sell: entry.sell.toJSON(),
Expand Down Expand Up @@ -687,24 +697,6 @@ export default class PricelistManagerCommands {
return this.bot.sendMessage(steamID, `❌ "sku" should not be empty or wrong format.`);
}

if (typeof params.buy === 'object' && params.buy !== null) {
params.buy.keys = params.buy.keys || 0;
params.buy.metal = params.buy.metal || 0;

if (params.autoprice === undefined) {
params.autoprice = false;
}
}

if (typeof params.sell === 'object' && params.sell !== null) {
params.sell.keys = params.sell.keys || 0;
params.sell.metal = params.sell.metal || 0;

if (params.autoprice === undefined) {
params.autoprice = false;
}
}

if (params.resetgroup) {
// if resetgroup (when sending "!update item=<itemName>&resetgroup=true") is defined,
// first check if it's a booelan type
Expand Down Expand Up @@ -800,6 +792,34 @@ export default class PricelistManagerCommands {

const itemEntry = this.bot.pricelist.getPrice(params.sku as string, false);

if (typeof params.buy === 'object') {
params.buy.keys = params.buy.keys || 0;
params.buy.metal = params.buy.metal || 0;

if (params.autoprice === undefined) {
params.autoprice = false;
}
} else if (typeof params.buy !== 'object' && typeof params.sell === 'object') {
params['buy'] = {
keys: itemEntry.buy.keys,
metal: itemEntry.buy.metal
};
}

if (typeof params.sell === 'object') {
params.sell.keys = params.sell.keys || 0;
params.sell.metal = params.sell.metal || 0;

if (params.autoprice === undefined) {
params.autoprice = false;
}
} else if (typeof params.sell !== 'object' && typeof params.buy === 'object') {
params['sell'] = {
keys: itemEntry.sell.keys,
metal: itemEntry.sell.metal
};
}

if (typeof params.note === 'object') {
params.note.buy = params.note.buy || itemEntry.note.buy;
params.note.sell = params.note.sell || itemEntry.note.sell;
Expand Down Expand Up @@ -851,7 +871,7 @@ export default class PricelistManagerCommands {

if (params.group && typeof params.group !== 'string') {
// if group parameter is defined, convert anything to string
params.group = (params.group as string).toString();
params.group = String(params.group);
}

const entryData = this.bot.pricelist.getPrice(params.sku as string, false).getJSON();
Expand Down
12 changes: 6 additions & 6 deletions src/classes/Pricelist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export interface EntryData {
sku: string;
enabled: boolean;
autoprice: boolean;
max: number;
min: number;
max: number;
intent: 0 | 1 | 2; // 'buy', 'sell', 'bank'
buy?: Currency | null;
sell?: Currency | null;
Expand All @@ -42,10 +42,10 @@ export class Entry {

autoprice: boolean;

max: number;

min: number;

max: number;

intent: 0 | 1 | 2;

buy: Currencies | null;
Expand All @@ -65,8 +65,8 @@ export class Entry {
this.name = name;
this.enabled = entry.enabled;
this.autoprice = entry.autoprice;
this.max = entry.max;
this.min = entry.min;
this.max = entry.max;
this.intent = entry.intent;

// TODO: Validate entry
Expand Down Expand Up @@ -126,8 +126,8 @@ export class Entry {
sku: this.sku,
enabled: this.enabled,
autoprice: this.autoprice,
max: this.max,
min: this.min,
max: this.max,
intent: this.intent,
buy: this.buy === null ? null : this.buy.toJSON(),
sell: this.sell === null ? null : this.sell.toJSON(),
Expand Down Expand Up @@ -539,8 +539,8 @@ export default class Pricelist extends EventEmitter {
sku: prices[0].sku,
enabled: prices[0].enabled,
intent: prices[0].intent,
max: prices[0].max,
min: prices[0].min,
max: prices[0].max,
autoprice: prices[0].autoprice,
buy: prices[0].buy,
sell: prices[0].sell,
Expand Down