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

add price and limit options #20

Merged
merged 1 commit into from
Jan 29, 2024
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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ All options are supported in all tabs, unless specified. They are white space se
* Keeps `N` copies of the item after running
* `stockN`
* (only supported by `mall`, `display`, and `closet`). Ensures `N` copies of the item are stocked in the relevant locations, keeps the rest in your inventory
* `limitN`
* (only supported by `mall` and `sell`) Sets a mall limit of `N` copies per person per day
* `priceN`
* (only supported by `mall` and `sell`) Sets the price for selling in the mall.
* `<N`
* Only performs the given operation on items that have a `mallPrice` that is less than `N`
* `>N`
Expand Down Expand Up @@ -136,7 +140,7 @@ Use `keeping-tabs debug help` to see a full list of available debug commands.

## TODO

* [ ] Add more mall options (add at fixed price, limit the items for sale)
* [x] Add more mall options (add at fixed price, limit the items for sale)
* [x] Add more mall options (add at min price)
* [ ] Add confirmation for kmailing, optionally?
* [x] Add option to keep certain number of items (using format of keepN)
Expand Down
11 changes: 7 additions & 4 deletions src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,17 @@ export const actions: {
return {
action: (item: Item) =>
putShop(
0,
0,
options.price ?? 0,
options.limit ?? 0,
Math.min(Math.max(0, (options.stock ?? 0) - shopAmount(item)), amount(item, options)),
item
),
};
}
return { action: (item: Item) => putShop(0, 0, amount(item, options), item) };
return {
action: (item: Item) =>
putShop(options.price ?? 0, options.limit ?? 0, amount(item, options), item),
};
},
sell: (options: Options) => {
return {
Expand All @@ -66,7 +69,7 @@ export const actions: {
) {
autosell(amount(item, options), item);
} else {
putShop(0, 0, amount(item, options), item);
putShop(options.price ?? 0, options.limit ?? 0, amount(item, options), item);
}
},
};
Expand Down
18 changes: 18 additions & 0 deletions src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Item } from "kolmafia";
export class Options {
keep?: number;
stock?: number;
limit?: number;
price?: number;
target?: string;
body?: string;
priceUpperThreshold?: number;
Expand All @@ -24,6 +26,16 @@ export class Options {
options.stock = parseInt(stock[1]);
continue;
}
const limit = optionStr.match(/limit(\d+)/);
if (limit && limit[1]) {
options.limit = parseInt(limit[1]);
continue;
}
const price = optionStr.match(/price(\d+)/);
if (price && price[1]) {
options.price = parseInt(price[1]);
continue;
}
const target = optionStr.match(/#(.*)/);
if (target && target[1]) {
options.target = target[1];
Expand Down Expand Up @@ -59,6 +71,12 @@ export class Options {
if (this.stock) {
optionsStr.push(`stock: ${this.stock}`);
}
if (this.limit) {
optionsStr.push(`limit: ${this.limit}`);
}
if (this.price) {
optionsStr.push(`price: ${this.price}`);
}
if (this.target) {
optionsStr.push(`target: ${this.target}`);
}
Expand Down
6 changes: 3 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export const ALL_TAB_TITLES = [
"collection",
"low",
] as const;
export type TabTitle = (typeof ALL_TAB_TITLES)[number];
export type TabTitle = typeof ALL_TAB_TITLES[number];
export type TabId = number;

export function isTabTitle(value: string): value is TabTitle {
return ALL_TAB_TITLES.includes(value as TabTitle);
}

const ALL_ACTION_OPTIONS = ["keep", "stock", "target"] as const;
export type ActionOption = (typeof ALL_ACTION_OPTIONS)[number];
const ALL_ACTION_OPTIONS = ["keep", "stock", "limit", "price", "target"] as const;
export type ActionOption = typeof ALL_ACTION_OPTIONS[number];

export function isActionOption(value: string): value is ActionOption {
return ALL_ACTION_OPTIONS.includes(value as ActionOption);
Expand Down
Loading