libram 0.6.6 → 0.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Clan.d.ts CHANGED
@@ -4,10 +4,6 @@ export interface Rank {
4
4
  degree: number;
5
5
  id: number;
6
6
  }
7
- export declare class ClanError extends Error {
8
- reason?: Error;
9
- constructor(message: string, reason?: Error);
10
- }
11
7
  export declare class Clan {
12
8
  readonly id: number;
13
9
  readonly name: string;
@@ -43,6 +39,7 @@ export declare class Clan {
43
39
  */
44
40
  static getWhitelisted(): Clan[];
45
41
  private constructor();
42
+ private _check;
46
43
  /**
47
44
  * Join clan
48
45
  */
package/dist/Clan.js CHANGED
@@ -1,39 +1,7 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
1
  import { availableAmount, cliExecute, getClanId, getClanName, getPlayerId, Monster, putStash, refreshStash, retrieveItem, stashAmount, takeStash, visitUrl, xpath, } from "kolmafia";
8
2
  import { getFoldGroup } from "./lib";
9
3
  import logger from "./logger";
10
4
  import { arrayToCountedMap, countedMapToArray, countedMapToString, notNull, parseNumber, } from "./utils";
11
- export class ClanError extends Error {
12
- reason;
13
- constructor(message, reason) {
14
- super(message);
15
- this.reason = reason;
16
- Object.setPrototypeOf(this, ClanError.prototype);
17
- }
18
- }
19
- // It would be fantastic to have this function properly typed
20
- // But until someone can work out how to do it, it gets the
21
- // comment blocks of shame
22
- /* eslint-disable */
23
- function validate(target, propertyName, descriptor) {
24
- if (!descriptor?.value)
25
- return;
26
- const method = descriptor.value;
27
- // @ts-ignore
28
- descriptor.value = function (...args) {
29
- // @ts-ignore
30
- if (this.id !== getClanId()) {
31
- throw new Error("You are no longer a member of this clan");
32
- }
33
- return method.apply(this, args);
34
- };
35
- }
36
- /* eslint-enable */
37
5
  const clanIdCache = {};
38
6
  const toPlayerId = (player) => typeof player === "string" ? getPlayerId(player) : player;
39
7
  const LOG_FAX_PATTERN = /(\d{2}\/\d{2}\/\d{2}, \d{2}:\d{2}(?:AM|PM): )<a [^>]+>([^<]+)<\/a>(?: faxed in a (?<monster>.*?))<br>/;
@@ -146,11 +114,16 @@ export class Clan {
146
114
  this.id = id;
147
115
  this.name = name;
148
116
  }
117
+ _check() {
118
+ if (this.id !== getClanId()) {
119
+ throw new Error("You are no longer a member of this clan");
120
+ }
121
+ }
149
122
  /**
150
123
  * Join clan
151
124
  */
152
125
  join() {
153
- return Clan._join(this.id);
126
+ return Clan.join(this.id);
154
127
  }
155
128
  check() {
156
129
  return visitUrl("clan_hall.php").includes(`<b>${this.name}</b>`);
@@ -159,6 +132,7 @@ export class Clan {
159
132
  * Return the monster that is currently in the current clan's fax machine if any
160
133
  */
161
134
  getCurrentFax() {
135
+ this._check();
162
136
  const logs = visitUrl("clan_log.php");
163
137
  const lastFax = logs.match(LOG_FAX_PATTERN);
164
138
  if (!lastFax)
@@ -172,6 +146,7 @@ export class Clan {
172
146
  * List available ranks (name, degree and id) from the current clan
173
147
  */
174
148
  getRanks() {
149
+ this._check();
175
150
  const page = visitUrl("clan_whitelist.php");
176
151
  return xpath(page, '//select[@name="level"]//option')
177
152
  .map((option) => {
@@ -197,6 +172,7 @@ export class Clan {
197
172
  * @param title Title to give the player. If not provided, will be blank
198
173
  */
199
174
  addPlayerToWhitelist(player, rankName, title = "") {
175
+ this._check();
200
176
  const playerId = toPlayerId(player);
201
177
  const ranks = this.getRanks();
202
178
  const rank = rankName
@@ -213,6 +189,7 @@ export class Clan {
213
189
  * @param player Player id or name
214
190
  */
215
191
  removePlayerFromWhitelist(player) {
192
+ this._check();
216
193
  const playerId = toPlayerId(player);
217
194
  const result = visitUrl(`clan_whitelist.php?action=updatewl&pwd&who=${playerId}&remove=Remove`);
218
195
  return result.includes("Whitelist updated.");
@@ -221,6 +198,7 @@ export class Clan {
221
198
  * Return the amount of meat in the current clan's coffer.
222
199
  */
223
200
  getMeatInCoffer() {
201
+ this._check();
224
202
  const page = visitUrl("clan_stash.php");
225
203
  const [, meat] = page.match(/Your <b>Clan Coffer<\/b> contains ([\d,]+) Meat./) || ["0", "0"];
226
204
  return parseNumber(meat);
@@ -230,10 +208,12 @@ export class Clan {
230
208
  * @param amount Amount of meat to put in coffer
231
209
  */
232
210
  putMeatInCoffer(amount) {
211
+ this._check();
233
212
  const result = visitUrl(`clan_stash.php?pwd&action=contribute&howmuch=${amount}`);
234
213
  return result.includes("You contributed");
235
214
  }
236
215
  take(items) {
216
+ this._check();
237
217
  const map = arrayToCountedMap(items);
238
218
  map.forEach((quantity, item) => {
239
219
  let needed = Math.max(0, quantity - availableAmount(item));
@@ -271,6 +251,7 @@ export class Clan {
271
251
  return Array.isArray(items) ? countedMapToArray(map) : map;
272
252
  }
273
253
  put(items) {
254
+ this._check();
274
255
  const map = arrayToCountedMap(items);
275
256
  if (!this.check())
276
257
  throw new Error(`Wanted to return ${countedMapToString(map)} to ${this.name} but KoLmafia's clan data is out of sync`);
@@ -284,34 +265,8 @@ export class Clan {
284
265
  }
285
266
  withStash(items, callback // eslint-disable-line @typescript-eslint/no-explicit-any
286
267
  ) {
268
+ this._check();
287
269
  const map = arrayToCountedMap(items);
288
270
  return Clan._withStash(() => this.take(map), (borrowed) => this.put(borrowed), callback);
289
271
  }
290
272
  }
291
- __decorate([
292
- validate
293
- ], Clan.prototype, "getCurrentFax", null);
294
- __decorate([
295
- validate
296
- ], Clan.prototype, "getRanks", null);
297
- __decorate([
298
- validate
299
- ], Clan.prototype, "addPlayerToWhitelist", null);
300
- __decorate([
301
- validate
302
- ], Clan.prototype, "removePlayerFromWhitelist", null);
303
- __decorate([
304
- validate
305
- ], Clan.prototype, "getMeatInCoffer", null);
306
- __decorate([
307
- validate
308
- ], Clan.prototype, "putMeatInCoffer", null);
309
- __decorate([
310
- validate
311
- ], Clan.prototype, "take", null);
312
- __decorate([
313
- validate
314
- ], Clan.prototype, "put", null);
315
- __decorate([
316
- validate
317
- ], Clan.prototype, "withStash", null);
package/dist/Kmail.js CHANGED
@@ -40,9 +40,7 @@ export default class Kmail {
40
40
  }
41
41
  static _genericSend(to, message, items, meat, chunkSize, constructUrl, successString) {
42
42
  let m = meat;
43
- const sendableItems = [
44
- ...arrayToCountedMap(items).entries(),
45
- ].filter(([item]) => isGiftable(item));
43
+ const sendableItems = [...arrayToCountedMap(items).entries()].filter(([item]) => isGiftable(item));
46
44
  let result = true;
47
45
  const chunks = chunk(sendableItems, chunkSize);
48
46
  // Split the items to be sent into chunks of max 11 item types
package/dist/Path.d.ts CHANGED
@@ -65,4 +65,5 @@ export declare const Paths: {
65
65
  readonly YouRobot: Path;
66
66
  readonly QuantumTerrarium: Path;
67
67
  readonly Wildfire: Path;
68
+ readonly GreyYou: Path;
68
69
  };
package/dist/Path.js CHANGED
@@ -75,4 +75,6 @@ export const Paths = {
75
75
  YouRobot: new Path("You, Robot", 41, false, false, true, 0, 0, 0),
76
76
  QuantumTerrarium: new Path("Quantum Terrarium", 42, true, true, false),
77
77
  Wildfire: new Path("Wildfire", 43),
78
+ GreyYou: new Path("Grey You", 44, false, true, true, 0, 0, 0, // eslint-disable-next-line libram/verify-constants
79
+ $classes `Grey Goo`),
78
80
  };
package/dist/ascend.d.ts CHANGED
@@ -28,10 +28,10 @@ declare type Eudora = typeof eudorae[number];
28
28
  * Sets up various iotms you may want to use in the coming ascension
29
29
  * @param ascensionItems.workshed Workshed to switch to.
30
30
  * @param ascensionItems.garden Garden to switch to.
31
- * @param ascensionItems An object potentially containing your workshed, garden, and eudora, all as items
31
+ * @param ascensionItems An object potentially containing your workshed, garden, chateau, and eudora, all as strings
32
32
  * @param throwOnFail If true, this will throw an error when it fails to switch something
33
33
  */
34
- export declare function prepareAscension({ workshed, garden, eudora, chateau, }?: {
34
+ export declare function prepareAscension({ workshed, garden, eudora, chateau, throwOnFail, }?: {
35
35
  workshed?: Workshed;
36
36
  garden?: Garden;
37
37
  eudora?: Eudora;
@@ -40,5 +40,6 @@ export declare function prepareAscension({ workshed, garden, eudora, chateau, }?
40
40
  ceiling?: Ceiling;
41
41
  nightstand?: Nightstand;
42
42
  };
43
+ throwOnFail?: boolean;
43
44
  }): void;
44
45
  export {};
package/dist/ascend.js CHANGED
@@ -1,4 +1,4 @@
1
- import { containsText, eudoraItem, getCampground, getWorkshed, Item, toInt, toItem, use, visitUrl, xpath, } from "kolmafia";
1
+ import { containsText, eudoraItem, getCampground, getWorkshed, Item, toInt, use, visitUrl, xpath, } from "kolmafia";
2
2
  import { ChateauMantegna } from "./resources";
3
3
  import { $item, $items, $stat } from "./template-string";
4
4
  export var Lifestyle;
@@ -135,45 +135,51 @@ const eudorae = [
135
135
  * Sets up various iotms you may want to use in the coming ascension
136
136
  * @param ascensionItems.workshed Workshed to switch to.
137
137
  * @param ascensionItems.garden Garden to switch to.
138
- * @param ascensionItems An object potentially containing your workshed, garden, and eudora, all as items
138
+ * @param ascensionItems An object potentially containing your workshed, garden, chateau, and eudora, all as strings
139
139
  * @param throwOnFail If true, this will throw an error when it fails to switch something
140
140
  */
141
- export function prepareAscension({ workshed, garden, eudora, chateau, } = {}) {
142
- if (workshed && getWorkshed() !== toItem(workshed)) {
141
+ export function prepareAscension({ workshed, garden, eudora, chateau, throwOnFail, } = {}) {
142
+ throwOnFail = throwOnFail ?? true;
143
+ if (workshed && getWorkshed() !== Item.get(workshed)) {
143
144
  use(Item.get(workshed));
145
+ if (getWorkshed().name !== workshed && throwOnFail) {
146
+ throw new Error(`Failed to switch workshed to ${workshed}; it is currently still ${getWorkshed()}.`);
147
+ }
144
148
  }
145
149
  if (garden && !Object.getOwnPropertyNames(getCampground()).includes(garden)) {
146
150
  use(Item.get(garden));
147
- if (!Object.getOwnPropertyNames(getCampground()).includes(garden)) {
151
+ if (!Object.getOwnPropertyNames(getCampground()).includes(garden) &&
152
+ throwOnFail) {
148
153
  throw new Error(`We really thought we changed your garden to a ${garden}, but Mafia is saying otherwise.`);
149
154
  }
150
155
  }
151
156
  if (eudora && eudoraItem().name !== eudora) {
152
157
  const eudoraNumber = 1 + eudorae.indexOf(eudora);
153
- if (!xpath(visitUrl("account.php?tab=correspondence"), `//select[@name="whichpenpal"]/option/@value`).includes(eudoraNumber.toString())) {
158
+ if (!xpath(visitUrl("account.php?tab=correspondence"), `//select[@name="whichpenpal"]/option/@value`).includes(eudoraNumber.toString()) &&
159
+ throwOnFail) {
154
160
  throw new Error(`I'm sorry buddy, but you don't seem to be subscribed to ${eudora}. Which makes it REALLY hard to correspond with them.`);
155
161
  }
156
162
  else {
157
163
  visitUrl(`account.php?actions[]=whichpenpal&whichpenpal=${eudoraNumber}&action=Update`, true);
158
164
  }
159
- if (eudoraItem() !== toItem(eudora)) {
165
+ if (eudoraItem() !== Item.get(eudora) && throwOnFail) {
160
166
  throw new Error(`We really thought we changed your eudora to a ${eudora}, but Mafia is saying otherwise.`);
161
167
  }
162
168
  }
163
169
  if (chateau && ChateauMantegna.have()) {
164
170
  const { desk, ceiling, nightstand } = chateau;
165
171
  if (ceiling && ChateauMantegna.getCeiling() !== ceiling) {
166
- if (!ChateauMantegna.changeCeiling(ceiling)) {
172
+ if (!ChateauMantegna.changeCeiling(ceiling) && throwOnFail) {
167
173
  throw new Error(`We tried, but were unable to change your chateau ceiling to ${ceiling}. Probably.`);
168
174
  }
169
175
  }
170
176
  if (desk && ChateauMantegna.getDesk() !== desk) {
171
- if (!ChateauMantegna.changeDesk(desk)) {
177
+ if (!ChateauMantegna.changeDesk(desk) && throwOnFail) {
172
178
  throw new Error(`We tried, but were unable to change your chateau desk to ${desk}. Probably.`);
173
179
  }
174
180
  }
175
181
  if (nightstand && ChateauMantegna.getNightstand() !== nightstand) {
176
- if (!ChateauMantegna.changeNightstand(nightstand)) {
182
+ if (!ChateauMantegna.changeNightstand(nightstand) && throwOnFail) {
177
183
  throw new Error(`We tried, but were unable to change your chateau nightstand to ${nightstand}. Probably.`);
178
184
  }
179
185
  }
@@ -1,31 +1,27 @@
1
1
  import { Requirement } from "../../maximize";
2
- /**
3
- * A log of the predicted turns, actual turns, and duration of each CS test performed.
4
- */
5
- export declare const log: {
6
- [index: string]: {
7
- predictedTurns: number;
8
- turnCost: number;
9
- seconds: number;
10
- };
11
- };
12
- declare class Test {
2
+ export default class CommunityService {
13
3
  private choice;
4
+ private stat;
14
5
  private property;
15
6
  private predictor;
16
7
  private maximizeRequirements;
17
8
  /**
18
9
  * Class to store properties of various CS tests.
19
10
  * @param id The id the game HTML uses to identify the test; this is used primarily in runChoice.
11
+ * @param stat The principle stat the test measures, often used as more easily memorable shorthand for the specific tests
20
12
  * @param property The name of the test as a string, often used as part of the string property "csServicesPerformed".
21
13
  * @param predictor A function that returns an estimate for the number of turns that the test will take given your character's current state.
22
14
  * @param maximizeRequirements A Requirement object, if applicable, that aligns with the things needed to maximize for this particular test.
23
15
  */
24
- constructor(id: number, property: string, predictor: () => number, maximizeRequirements?: Requirement | null);
16
+ private constructor();
25
17
  /**
26
18
  * @returns The id number of the test, used primarily in runChoice.
27
19
  */
28
20
  get id(): number;
21
+ /**
22
+ * @returns The primary stat the test measures, used primarily as memorable shorthand in place of test names.
23
+ */
24
+ get statName(): string;
29
25
  /**
30
26
  * @returns The name of the test, used primarily as part of the string property "csServicesPerformed"
31
27
  */
@@ -38,6 +34,7 @@ declare class Test {
38
34
  * @returns A Requirement object, if applicable, that aligns with the things needed to maximize for this particular test.
39
35
  */
40
36
  get requirement(): Requirement | null;
37
+ static logTask(name: string, action: () => number | void): void;
41
38
  /**
42
39
  * Checks the "csServicesPerformed" property to see whether mafia currently believes this test is complete.
43
40
  * @returns Whether mafia currently believes this test is complete.
@@ -54,33 +51,50 @@ declare class Test {
54
51
  do(): boolean;
55
52
  /**
56
53
  * Wrapper function that prepares for a test and then completes it, adding time and turn details to the log.
57
- * @param prepare A function that does all necessary preparations for this CS test, including choosing your outfit.
58
- * @param beCertain Whether we should check council.php instead of mafia to determine whether the test is complete.
59
- * @param maxTurns We will run the test iff the predicted turns is less than or equal to this parameter.
60
- * @returns The output of the prepare function given, or null if the test is already complete.
54
+ * @param prepare A function that does all necessary preparations for this CS test, including choosing your outfit. Optionally returns the number of turns you expect to spend preparing for the test.
55
+ * @param beCertain Whether we should check council.php instead of mafia to determine the test cost and whether the test is complete.
56
+ * @param maxTurns We will run the test iff the predicted/actual turns is less than or equal to this parameter.
57
+ * @returns "completed", "failed", or "already completed".
61
58
  */
62
- run(prepare: () => void, beCertain?: boolean, maxTurns?: number): boolean;
59
+ run(prepare: () => void | number, maxTurns?: number): "completed" | "failed" | "already completed";
60
+ private _verifyIsDone;
63
61
  /**
64
62
  * Checks council.php to verify that a test is complete; more reliable than isDone, but requires an additional pagehit.
65
63
  * @returns Whether council.php suggests that the test is complete.
66
64
  */
67
65
  verifyIsDone(): boolean;
66
+ private _actualCost;
67
+ /**
68
+ * Checks council.php for the number of turns this test will take; more reliable than prediction, but requires an additional pagehit.
69
+ * @returns The number of turns to complete this test according to council.php.
70
+ */
71
+ actualCost(): number;
72
+ /**
73
+ * A log of the predicted turns, actual turns, and duration of each CS test performed.
74
+ */
75
+ static log: {
76
+ [index: string]: {
77
+ predictedTurns: number;
78
+ turnCost: number;
79
+ seconds: number;
80
+ type: "test" | "task";
81
+ };
82
+ };
83
+ /**
84
+ * Prints turncount and time details of the test in question.
85
+ * @param colour The colour (or color) you'd like the log to be printed in.
86
+ */
87
+ static printLog(colour?: string): void;
88
+ static HP: CommunityService;
89
+ static Muscle: CommunityService;
90
+ static Mysticality: CommunityService;
91
+ static Moxie: CommunityService;
92
+ static FamiliarWeight: CommunityService;
93
+ static WeaponDamage: CommunityService;
94
+ static SpellDamage: CommunityService;
95
+ static Noncombat: CommunityService;
96
+ static BoozeDrop: CommunityService;
97
+ static HotRes: CommunityService;
98
+ static CoilWire: CommunityService;
99
+ static donate: () => void;
68
100
  }
69
- export declare const HP: Test;
70
- export declare const Muscle: Test;
71
- export declare const Mysticality: Test;
72
- export declare const Moxie: Test;
73
- export declare const FamiliarWeight: Test;
74
- export declare const WeaponDamage: Test;
75
- export declare const SpellDamage: Test;
76
- export declare const Noncombat: Test;
77
- export declare const BoozeDrop: Test;
78
- export declare const HotRes: Test;
79
- export declare const CoilWire: Test;
80
- /**
81
- * Prints turncount and time details of the test in question.
82
- * @param colour The colour (or color) you'd like the log to be printed in.
83
- */
84
- export declare function printLog(colour?: string): void;
85
- export declare const donate: () => void;
86
- export {};