libram 0.8.3 → 0.8.5

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.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { decode as decodeEntities } from "html-entities";
1
2
  import { availableAmount, cliExecute, getClanId, getClanName, getPlayerId, Monster, putStash, refreshStash, retrieveItem, stashAmount, takeStash, visitUrl, xpath, } from "kolmafia";
2
3
  import { getFoldGroup } from "./lib";
3
4
  import logger from "./logger";
@@ -114,7 +115,7 @@ export class Clan {
114
115
  return xpath(page, '//select[@name="whichclan"]//option').map((option) => {
115
116
  const validHtml = `<select>${option}</select>`;
116
117
  const id = Number.parseInt(xpath(validHtml, "//@value")[0]);
117
- const name = xpath(validHtml, "//text()")[0];
118
+ const name = decodeEntities(xpath(validHtml, "//text()")[0]);
118
119
  return new Clan(id, name);
119
120
  });
120
121
  }
@@ -174,9 +175,9 @@ export class Clan {
174
175
  const id = xpath(validHtml, "//@value")[0];
175
176
  if (!match || !id)
176
177
  return null;
177
- const [, name, degree] = match;
178
+ const [, encodedName, degree] = match;
178
179
  return {
179
- name,
180
+ name: decodeEntities(encodedName),
180
181
  degree: Number.parseInt(degree),
181
182
  id: Number.parseInt(id),
182
183
  };
package/dist/Kmail.d.ts CHANGED
@@ -11,7 +11,7 @@ declare type RawKmail = {
11
11
  export default class Kmail {
12
12
  readonly id: number;
13
13
  readonly date: Date;
14
- readonly type: "normal";
14
+ readonly type: "normal" | "giftshop";
15
15
  readonly senderId: number;
16
16
  readonly senderName: string;
17
17
  readonly rawMessage: string;
@@ -91,11 +91,11 @@ export default class CommunityService {
91
91
  }
92
92
  }
93
93
  static logTask(name, action) {
94
- const estimatedTurns = action() ?? 0;
95
94
  const { time, turns } = this.taskTimers.get(name) ?? {
96
95
  time: Date.now(),
97
96
  turns: myTurncount(),
98
97
  };
98
+ const estimatedTurns = action() ?? 0;
99
99
  CommunityService.log[name] = {
100
100
  type: "task",
101
101
  turnCost: myTurncount() - turns,
@@ -44,18 +44,36 @@ export declare function get(property: string, _default: Familiar): Familiar | nu
44
44
  export declare function get(property: string, _default: boolean): boolean;
45
45
  export declare function get(property: string, _default: number): number;
46
46
  export declare function get(property: string, _default?: string): string;
47
- export declare function set(property: BooleanProperty, value: boolean): void;
48
- export declare function set(property: NumericProperty, value: number): void;
49
- export declare function set(property: NumericOrStringProperty, value: number | string): void;
50
- export declare function set(property: StringProperty, value: string): void;
51
- export declare function set(property: LocationProperty, value: Location): void;
52
- export declare function set(property: MonsterProperty, value: Monster): void;
53
- export declare function set(property: FamiliarProperty, value: Familiar): void;
54
- export declare function set(property: StatProperty, value: Stat): void;
55
- export declare function set(property: PhylumProperty, value: Phylum): void;
47
+ export declare function set(property: BooleanProperty, value: boolean): boolean;
48
+ export declare function set(property: NumericProperty, value: number): number;
49
+ export declare function set<T extends number | string>(property: NumericOrStringProperty, value: T): T;
50
+ export declare function set(property: StringProperty, value: string): string;
51
+ export declare function set(property: LocationProperty, value: Location): Location;
52
+ export declare function set(property: MonsterProperty, value: Monster): Monster;
53
+ export declare function set(property: FamiliarProperty, value: Familiar): Familiar;
54
+ export declare function set(property: StatProperty, value: Stat): Stat;
55
+ export declare function set(property: PhylumProperty, value: Phylum): Phylum;
56
56
  export declare function set<D extends {
57
57
  toString(): string;
58
- }>(property: string, value: D): void;
58
+ }>(property: string, value: D): D;
59
+ /**
60
+ * Increment a property
61
+ *
62
+ * @param property Numeric property to increment
63
+ * @param delta Number by which to increment
64
+ * @param max Maximum value to set
65
+ * @returns New value
66
+ */
67
+ export declare function increment(property: NumericProperty, delta?: number, max?: number): number;
68
+ /**
69
+ * Decrement a property
70
+ *
71
+ * @param property Numeric property to decrement
72
+ * @param delta Number by which to decrement
73
+ * @param min Maximum value to set
74
+ * @returns New value
75
+ */
76
+ export declare function decrement(property: NumericProperty, delta?: number, min?: number): number;
59
77
  declare type Properties = Partial<{
60
78
  [P in KnownProperty]: unknown;
61
79
  }>;
package/dist/property.js CHANGED
@@ -103,10 +103,42 @@ export function get(property, _default) {
103
103
  *
104
104
  * @param property Name of the property
105
105
  * @param value Value to give the property
106
+ * @returns Value that was set
106
107
  */
107
108
  export function set(property, value) {
108
109
  const stringValue = value === null ? "" : value.toString();
109
110
  setProperty(property, stringValue);
111
+ return value;
112
+ }
113
+ /**
114
+ * Increment a property
115
+ *
116
+ * @param property Numeric property to increment
117
+ * @param delta Number by which to increment
118
+ * @param max Maximum value to set
119
+ * @returns New value
120
+ */
121
+ export function increment(property, delta = 1, max = Infinity) {
122
+ const value = get(property);
123
+ if (!isNumericProperty(property))
124
+ return value;
125
+ const nextValue = Math.min(max, value + delta);
126
+ return set(property, nextValue);
127
+ }
128
+ /**
129
+ * Decrement a property
130
+ *
131
+ * @param property Numeric property to decrement
132
+ * @param delta Number by which to decrement
133
+ * @param min Maximum value to set
134
+ * @returns New value
135
+ */
136
+ export function decrement(property, delta = 1, min = Infinity) {
137
+ const value = get(property);
138
+ if (!isNumericProperty(property))
139
+ return value;
140
+ const nextValue = Math.max(min, value - delta);
141
+ return set(property, nextValue);
110
142
  }
111
143
  /**
112
144
  * Sets the value of a set of mafia properties