libram 0.3.2 → 0.4.2

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.
Files changed (99) hide show
  1. package/dist/Clan.js +268 -485
  2. package/dist/Copier.js +11 -48
  3. package/dist/Dungeon.js +77 -157
  4. package/dist/Kmail.d.ts +13 -7
  5. package/dist/Kmail.js +92 -233
  6. package/dist/Path.js +68 -120
  7. package/dist/ascend.js +153 -172
  8. package/dist/combat.d.ts +86 -1
  9. package/dist/combat.js +295 -387
  10. package/dist/console.js +13 -36
  11. package/dist/diet/index.d.ts +31 -0
  12. package/dist/diet/index.js +333 -0
  13. package/dist/diet/knapsack.d.ts +7 -0
  14. package/dist/diet/knapsack.js +106 -0
  15. package/dist/dungeons/Dreadsylvania.d.ts +4 -0
  16. package/dist/dungeons/Dreadsylvania.js +14 -0
  17. package/dist/dungeons/Dungeon.d.ts +28 -0
  18. package/dist/dungeons/Dungeon.js +99 -0
  19. package/dist/dungeons/Hobopolis.d.ts +4 -0
  20. package/dist/dungeons/Hobopolis.js +14 -0
  21. package/dist/dungeons/SlimeTube.d.ts +4 -0
  22. package/dist/dungeons/SlimeTube.js +14 -0
  23. package/dist/freerun.d.ts +23 -0
  24. package/dist/freerun.js +92 -0
  25. package/dist/index.d.ts +6 -1
  26. package/dist/index.js +21 -263
  27. package/dist/lib.d.ts +43 -0
  28. package/dist/lib.js +296 -405
  29. package/dist/logger.js +23 -63
  30. package/dist/maximize.d.ts +29 -12
  31. package/dist/maximize.js +318 -421
  32. package/dist/modifier.d.ts +13 -0
  33. package/dist/modifier.js +35 -0
  34. package/dist/modifierTypes.d.ts +16 -0
  35. package/dist/modifierTypes.js +9 -0
  36. package/dist/mood.js +220 -531
  37. package/dist/property.d.ts +2 -0
  38. package/dist/property.js +96 -242
  39. package/dist/propertyTypes.d.ts +9 -0
  40. package/dist/propertyTypes.js +1 -0
  41. package/dist/propertyTyping.d.ts +2 -9
  42. package/dist/propertyTyping.js +42 -53
  43. package/dist/resources/2007/CandyHearts.d.ts +9 -0
  44. package/dist/resources/2007/CandyHearts.js +24 -0
  45. package/dist/resources/2008/DivineFavors.d.ts +9 -0
  46. package/dist/resources/2008/DivineFavors.js +27 -0
  47. package/dist/resources/2009/Bandersnatch.js +37 -112
  48. package/dist/resources/2009/LoveSongs.d.ts +9 -0
  49. package/dist/resources/2009/LoveSongs.js +24 -0
  50. package/dist/resources/2009/SpookyPutty.js +20 -46
  51. package/dist/resources/2010/Brickos.d.ts +9 -0
  52. package/dist/resources/2010/Brickos.js +21 -0
  53. package/dist/resources/2010/CrownOfThrones.d.ts +18 -0
  54. package/dist/resources/2010/CrownOfThrones.js +550 -0
  55. package/dist/resources/2011/Gygaxian.d.ts +9 -0
  56. package/dist/resources/2011/Gygaxian.js +24 -0
  57. package/dist/resources/2011/ObtuseAngel.js +21 -63
  58. package/dist/resources/2012/RainDoh.js +14 -40
  59. package/dist/resources/2012/Resolutions.d.ts +9 -0
  60. package/dist/resources/2012/Resolutions.js +28 -0
  61. package/dist/resources/2013/Florist.d.ts +61 -0
  62. package/dist/resources/2013/Florist.js +149 -0
  63. package/dist/resources/2013/PulledTaffy.d.ts +9 -0
  64. package/dist/resources/2013/PulledTaffy.js +33 -0
  65. package/dist/resources/2014/WinterGarden.js +15 -43
  66. package/dist/resources/2015/ChateauMantegna.js +52 -86
  67. package/dist/resources/2015/MayoClinic.d.ts +13 -0
  68. package/dist/resources/2015/MayoClinic.js +36 -0
  69. package/dist/resources/2016/SourceTerminal.d.ts +1 -0
  70. package/dist/resources/2016/SourceTerminal.js +114 -237
  71. package/dist/resources/2016/Witchess.js +33 -59
  72. package/dist/resources/2017/TunnelOfLove.js +62 -111
  73. package/dist/resources/2018/SongBoom.js +32 -68
  74. package/dist/resources/2019/BeachComb.d.ts +2 -0
  75. package/dist/resources/2019/BeachComb.js +26 -0
  76. package/dist/resources/2019/Snapper.d.ts +28 -0
  77. package/dist/resources/2019/Snapper.js +70 -0
  78. package/dist/resources/2020/Guzzlr.js +79 -163
  79. package/dist/resources/LibramSummon.d.ts +12 -0
  80. package/dist/resources/LibramSummon.js +66 -0
  81. package/dist/resources/index.d.ts +18 -11
  82. package/dist/resources/index.js +19 -85
  83. package/dist/resources/putty-likes.js +15 -30
  84. package/dist/ring-buffer.d.ts +24 -0
  85. package/dist/ring-buffer.js +135 -0
  86. package/dist/since.d.ts +1 -0
  87. package/dist/since.js +56 -112
  88. package/dist/template-string.js +40 -132
  89. package/dist/utils.d.ts +14 -0
  90. package/dist/utils.js +50 -114
  91. package/package.json +5 -3
  92. package/dist/libram-example-briefcase.js +0 -16073
  93. package/dist/libram-example-clan.js +0 -8898
  94. package/dist/libram-example-consult.js +0 -6179
  95. package/dist/libram-example-item.js +0 -3248
  96. package/dist/libram-example-kmail.js +0 -2065
  97. package/dist/libram-example-lib.js +0 -7608
  98. package/dist/libram-example-props.js +0 -4770
  99. package/dist/libram-example-resources.js +0 -12226
package/dist/Clan.js CHANGED
@@ -1,531 +1,314 @@
1
- "use strict";
2
-
3
- require("core-js/modules/es.object.to-string.js");
4
-
5
- require("core-js/modules/es.regexp.to-string.js");
6
-
7
- require("core-js/modules/es.reflect.construct.js");
8
-
9
- require("core-js/modules/es.array.iterator.js");
10
-
11
- require("core-js/modules/es.regexp.constructor.js");
12
-
13
- require("core-js/modules/es.string.replace.js");
14
-
15
- require("core-js/modules/es.symbol.js");
16
-
17
- require("core-js/modules/es.symbol.description.js");
18
-
19
- require("core-js/modules/es.array.slice.js");
20
-
21
- Object.defineProperty(exports, "__esModule", {
22
- value: true
23
- });
24
- exports.Clan = exports.ClanError = void 0;
25
-
26
- require("core-js/modules/es.array.includes.js");
27
-
28
- require("core-js/modules/es.string.includes.js");
29
-
30
- require("core-js/modules/es.regexp.exec.js");
31
-
32
- require("core-js/modules/es.string.match.js");
33
-
34
- require("core-js/modules/es.array.filter.js");
35
-
36
- require("core-js/modules/es.array.map.js");
37
-
38
- require("core-js/modules/es.number.parse-int.js");
39
-
40
- require("core-js/modules/es.array.find.js");
41
-
42
- require("core-js/modules/es.array.sort.js");
43
-
44
- require("core-js/modules/es.array.concat.js");
45
-
46
- var _kolmafia = require("kolmafia");
47
-
48
- var _lib = require("./lib");
49
-
50
- var _logger = _interopRequireDefault(require("./logger"));
51
-
52
- var _utils = require("./utils");
53
-
54
- var _class;
55
-
56
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
57
-
58
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
59
-
60
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
61
-
62
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
63
-
64
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
65
-
66
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e2) { throw _e2; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
67
-
68
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
69
-
70
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
71
-
72
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
73
-
74
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
75
-
76
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
77
-
78
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
79
-
80
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
81
-
82
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
83
-
84
- function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
85
-
86
- function _wrapRegExp() { _wrapRegExp = function _wrapRegExp(re, groups) { return new BabelRegExp(re, undefined, groups); }; var _super = RegExp.prototype; var _groups = new WeakMap(); function BabelRegExp(re, flags, groups) { var _this = new RegExp(re, flags); _groups.set(_this, groups || _groups.get(re)); return _setPrototypeOf(_this, BabelRegExp.prototype); } _inherits(BabelRegExp, RegExp); BabelRegExp.prototype.exec = function (str) { var result = _super.exec.call(this, str); if (result) result.groups = buildGroups(result, this); return result; }; BabelRegExp.prototype[Symbol.replace] = function (str, substitution) { if (typeof substitution === "string") { var groups = _groups.get(this); return _super[Symbol.replace].call(this, str, substitution.replace(/\$<([^>]+)>/g, function (_, name) { return "$" + groups[name]; })); } else if (typeof substitution === "function") { var _this = this; return _super[Symbol.replace].call(this, str, function () { var args = arguments; if (typeof args[args.length - 1] !== "object") { args = [].slice.call(args); args.push(buildGroups(args, _this)); } return substitution.apply(this, args); }); } else { return _super[Symbol.replace].call(this, str, substitution); } }; function buildGroups(result, re) { var g = _groups.get(re); return Object.keys(g).reduce(function (groups, name) { groups[name] = result[g[name]]; return groups; }, Object.create(null)); } return _wrapRegExp.apply(this, arguments); }
87
-
88
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
89
-
90
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
91
-
92
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
93
-
94
- function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
95
-
96
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
97
-
98
- function _wrapNativeSuper(Class) { var _cache = typeof Map === "function" ? new Map() : undefined; _wrapNativeSuper = function _wrapNativeSuper(Class) { if (Class === null || !_isNativeFunction(Class)) return Class; if (typeof Class !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache !== "undefined") { if (_cache.has(Class)) return _cache.get(Class); _cache.set(Class, Wrapper); } function Wrapper() { return _construct(Class, arguments, _getPrototypeOf(this).constructor); } Wrapper.prototype = Object.create(Class.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf(Wrapper, Class); }; return _wrapNativeSuper(Class); }
99
-
100
- function _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct; } else { _construct = function _construct(Parent, args, Class) { var a = [null]; a.push.apply(a, args); var Constructor = Function.bind.apply(Parent, a); var instance = new Constructor(); if (Class) _setPrototypeOf(instance, Class.prototype); return instance; }; } return _construct.apply(null, arguments); }
101
-
102
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
103
-
104
- function _isNativeFunction(fn) { return Function.toString.call(fn).indexOf("[native code]") !== -1; }
105
-
106
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
107
-
108
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
109
-
110
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
111
-
112
- var ClanError = /*#__PURE__*/function (_Error) {
113
- _inherits(ClanError, _Error);
114
-
115
- var _super = _createSuper(ClanError);
116
-
117
- function ClanError(message, reason) {
118
- var _this;
119
-
120
- _classCallCheck(this, ClanError);
121
-
122
- _this = _super.call(this, message);
123
-
124
- _defineProperty(_assertThisInitialized(_this), "reason", void 0);
125
-
126
- _this.reason = reason;
127
- Object.setPrototypeOf(_assertThisInitialized(_this), ClanError.prototype);
128
- return _this;
129
- }
130
-
131
- return ClanError;
132
- }( /*#__PURE__*/_wrapNativeSuper(Error)); // It would be fantastic to have this function properly typed
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
+ import { availableAmount, cliExecute, getClanId, getClanName, getPlayerId, putStash, refreshStash, retrieveItem, stashAmount, takeStash, visitUrl, xpath, } from "kolmafia";
8
+ import { getFoldGroup } from "./lib";
9
+ import logger from "./logger";
10
+ import { arrayToCountedMap, countedMapToArray, countedMapToString, notNull, parseNumber, } from "./utils";
11
+ export class ClanError extends Error {
12
+ constructor(message, reason) {
13
+ super(message);
14
+ this.reason = reason;
15
+ Object.setPrototypeOf(this, ClanError.prototype);
16
+ }
17
+ }
18
+ // It would be fantastic to have this function properly typed
133
19
  // But until someone can work out how to do it, it gets the
134
20
  // comment blocks of shame
135
-
136
21
  /* eslint-disable */
137
-
138
-
139
- exports.ClanError = ClanError;
140
-
141
22
  function validate(target, propertyName, descriptor) {
142
- if (!(descriptor !== null && descriptor !== void 0 && descriptor.value)) return;
143
- var method = descriptor.value; // @ts-ignore
144
-
145
- descriptor.value = function () {
23
+ if (!descriptor?.value)
24
+ return;
25
+ const method = descriptor.value;
146
26
  // @ts-ignore
147
- if (this.id !== (0, _kolmafia.getClanId)()) {
148
- throw new Error("You are no longer a member of this clan");
149
- }
150
-
151
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
152
- args[_key] = arguments[_key];
153
- }
154
-
155
- return method.apply(this, args);
156
- };
27
+ descriptor.value = function (...args) {
28
+ // @ts-ignore
29
+ if (this.id !== getClanId()) {
30
+ throw new Error("You are no longer a member of this clan");
31
+ }
32
+ return method.apply(this, args);
33
+ };
157
34
  }
158
35
  /* eslint-enable */
159
-
160
-
161
- var clanIdCache = {};
162
-
163
- var toPlayerId = player => typeof player === "string" ? (0, _kolmafia.getPlayerId)(player) : player;
164
-
165
- var LOG_FAX_PATTERN = /*#__PURE__*/_wrapRegExp(/([0-9]{2}\/[0-9]{2}\/[0-9]{2}, [0-9]{2}:[0-9]{2}(?:AM|PM): )<a (?:(?!>)[\s\S])+>((?:(?!<)[\s\S])+)<\/a>(?: faxed in a (.*?))<br>/, {
166
- monster: 3
167
- });
168
-
169
- var WHITELIST_DEGREE_PATTERN = /*#__PURE__*/_wrapRegExp(/(.*?) \(\xB0([0-9]+)\)/, {
170
- name: 1,
171
- degree: 2
172
- });
173
-
174
- var Clan = (_class = /*#__PURE__*/function () {
175
- function Clan(id, name) {
176
- _classCallCheck(this, Clan);
177
-
178
- _defineProperty(this, "id", void 0);
179
-
180
- _defineProperty(this, "name", void 0);
181
-
182
- this.id = id;
183
- this.name = name;
184
- }
185
- /**
186
- * Join clan
187
- */
188
-
189
-
190
- _createClass(Clan, [{
191
- key: "join",
192
- value: function join() {
193
- return Clan._join(this.id);
36
+ const clanIdCache = {};
37
+ const toPlayerId = (player) => typeof player === "string" ? getPlayerId(player) : player;
38
+ const LOG_FAX_PATTERN = /(\d{2}\/\d{2}\/\d{2}, \d{2}:\d{2}(?:AM|PM): )<a [^>]+>([^<]+)<\/a>(?: faxed in a (?<monster>.*?))<br>/;
39
+ const WHITELIST_DEGREE_PATTERN = /(?<name>.*?) \(°(?<degree>\d+)\)/;
40
+ export class Clan {
41
+ constructor(id, name) {
42
+ this.id = id;
43
+ this.name = name;
194
44
  }
195
- }, {
196
- key: "check",
197
- value: function check() {
198
- return (0, _kolmafia.visitUrl)("clan_hall.php").includes("<b>".concat(this.name, "</b>"));
45
+ static _join(id) {
46
+ const result = visitUrl(`showclan.php?recruiter=1&whichclan=${id}&pwd&whichclan=${id}&action=joinclan&apply=Apply+to+this+Clan&confirm=on`);
47
+ if (!result.includes("clanhalltop.gif")) {
48
+ throw new Error("Could not join clan");
49
+ }
50
+ return Clan.get();
199
51
  }
200
- /**
201
- * Return the monster that is currently in the current clan's fax machine if any
202
- */
203
-
204
- }, {
205
- key: "getCurrentFax",
206
- value: function getCurrentFax() {
207
- var logs = (0, _kolmafia.visitUrl)("clan_log.php");
208
- var lastFax = logs.match(LOG_FAX_PATTERN);
209
- if (!lastFax) return null;
210
-
211
- var _lastFax = _slicedToArray(lastFax, 4),
212
- monsterName = _lastFax[3];
213
-
214
- if (!monsterName) return null;
215
- return Monster.get(monsterName);
52
+ static _withStash(borrowFn,
53
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
+ returnFn,
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ callback) {
57
+ const borrowed = borrowFn();
58
+ const map = arrayToCountedMap(borrowed);
59
+ try {
60
+ return callback(borrowed);
61
+ }
62
+ finally {
63
+ if (map.size > 0) {
64
+ const returned = arrayToCountedMap(returnFn(borrowed));
65
+ map.forEach((quantity, item) => {
66
+ const remaining = quantity - (returned.get(item) || 0);
67
+ if (remaining > 0) {
68
+ map.set(item, remaining);
69
+ }
70
+ else {
71
+ map.delete(item);
72
+ }
73
+ });
74
+ if (map.size > 0) {
75
+ logger.error(`Failed to return <b>${countedMapToString(map)}</b> to <b>${this.name}</b> stash`);
76
+ }
77
+ }
78
+ }
216
79
  }
217
80
  /**
218
- * List available ranks (name, degree and id) from the current clan
81
+ * Join a clan and return its instance
82
+ * @param clanIdOrName Clan id or name
219
83
  */
220
-
221
- }, {
222
- key: "getRanks",
223
- value: function getRanks() {
224
- var page = (0, _kolmafia.visitUrl)("clan_whitelist.php");
225
- return (0, _kolmafia.xpath)(page, '//select[@name="level"]//option').map(option => {
226
- var validHtml = "<select>".concat(option, "</select>");
227
- var match = (0, _kolmafia.xpath)(validHtml, "//text()")[0].match(WHITELIST_DEGREE_PATTERN);
228
- var id = (0, _kolmafia.xpath)(validHtml, "//@value")[0];
229
- if (!match || !id) return null;
230
-
231
- var _match = _slicedToArray(match, 3),
232
- name = _match[1],
233
- degree = _match[2];
234
-
235
- return {
236
- name: name,
237
- degree: Number.parseInt(degree),
238
- id: Number.parseInt(id)
239
- };
240
- }).filter(_utils.notNull);
84
+ static join(clanIdOrName) {
85
+ let clanId;
86
+ if (typeof clanIdOrName === "string") {
87
+ const clanName = clanIdOrName.toLowerCase();
88
+ if (clanName === getClanName().toLowerCase()) {
89
+ return Clan.get();
90
+ }
91
+ if (!(clanName in clanIdCache)) {
92
+ const clan = Clan.getWhitelisted().find((c) => c.name.toLowerCase() === clanName);
93
+ if (!clan) {
94
+ throw new Error("Player is not whitelisted to clan");
95
+ }
96
+ clanIdCache[clanName] = clan.id;
97
+ }
98
+ clanId = clanIdCache[clanName];
99
+ }
100
+ else {
101
+ clanId = clanIdOrName;
102
+ if (clanId === getClanId()) {
103
+ return Clan.get();
104
+ }
105
+ }
106
+ return Clan._join(clanId);
241
107
  }
242
108
  /**
243
- * Add a player to the current clan's whitelist.
244
- * If the player is already in the whitelist this will change their rank or title.
245
- * @param player Player id or name
246
- * @param rankName Rank to give the player. If not provided they will be given the lowest rank
247
- * @param title Title to give the player. If not provided, will be blank
109
+ * Execute callback as a member of a clan
110
+ * and then restore prior membership
111
+ * @param clanIdOrName Clan id or name
248
112
  */
249
-
250
- }, {
251
- key: "addPlayerToWhitelist",
252
- value: function addPlayerToWhitelist(player, rankName) {
253
- var title = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "";
254
- var playerId = toPlayerId(player);
255
- var ranks = this.getRanks();
256
- var rank = rankName ? ranks.find(r => r.name === rankName) : ranks.sort((a, b) => a.degree - b.degree)[0];
257
- if (!rank) return false;
258
- var result = (0, _kolmafia.visitUrl)("clan_whitelist.php?action=add&pwd&addwho=".concat(playerId, "&level=").concat(rank.id, "&title=").concat(title));
259
- return result.includes("added to whitelist.") || result.includes("That player is already on the whitelist");
113
+ static with(clanIdOrName, callback) {
114
+ const startingClan = Clan.get();
115
+ const clan = Clan.join(clanIdOrName);
116
+ try {
117
+ return callback(clan);
118
+ }
119
+ finally {
120
+ startingClan.join();
121
+ }
260
122
  }
261
- /**
262
- * Remove a player from the current clan's whitelist
263
- * @param player Player id or name
264
- */
265
-
266
- }, {
267
- key: "removePlayerFromWhitelist",
268
- value: function removePlayerFromWhitelist(player) {
269
- var playerId = toPlayerId(player);
270
- var result = (0, _kolmafia.visitUrl)("clan_whitelist.php?action=updatewl&pwd&who=".concat(playerId, "&remove=Remove"));
271
- return result.includes("Whitelist updated.");
123
+ static withStash(clanIdOrName, items, // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
124
+ callback // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
125
+ ) {
126
+ return Clan._withStash(() => Clan.with(clanIdOrName, (clan) => clan.take(items)), (borrowed) => Clan.with(clanIdOrName, (clan) => clan.put(borrowed)), callback);
272
127
  }
273
128
  /**
274
- * Return the amount of meat in the current clan's coffer.
129
+ * Return player's current Clan
275
130
  */
276
-
277
- }, {
278
- key: "getMeatInCoffer",
279
- value: function getMeatInCoffer() {
280
- var page = (0, _kolmafia.visitUrl)("clan_stash.php");
281
-
282
- var _ref = page.match(/Your <b>Clan Coffer<\/b> contains ([\d,]+) Meat./) || ["0", "0"],
283
- _ref2 = _slicedToArray(_ref, 2),
284
- meat = _ref2[1];
285
-
286
- return (0, _utils.parseNumber)(meat);
131
+ static get() {
132
+ return new Clan(getClanId(), getClanName());
287
133
  }
288
134
  /**
289
- * Add the given amount of meat to the current clan's coffer.
290
- * @param amount Amount of meat to put in coffer
135
+ * Get list of clans to which the player is whitelisted
291
136
  */
292
-
293
- }, {
294
- key: "putMeatInCoffer",
295
- value: function putMeatInCoffer(amount) {
296
- var result = (0, _kolmafia.visitUrl)("clan_stash.php?pwd&action=contribute&howmuch=".concat(amount));
297
- return result.includes("You contributed");
137
+ static getWhitelisted() {
138
+ const page = visitUrl("clan_signup.php");
139
+ return xpath(page, '//select[@name="whichclan"]//option').map((option) => {
140
+ const validHtml = `<select>${option}</select>`;
141
+ const id = Number.parseInt(xpath(validHtml, "//@value")[0]);
142
+ const name = xpath(validHtml, "//text()")[0];
143
+ return new Clan(id, name);
144
+ });
298
145
  }
299
146
  /**
300
- * Take items from the stash
301
- *
302
- * This function will also take equivalent foldables if the original item cannot be found
303
- *
304
- * @param items Items to take
305
- * @returns Items successfully taken
147
+ * Join clan
306
148
  */
307
-
308
- }, {
309
- key: "take",
310
- value: function take(items) {
311
- var map = (0, _utils.arrayToCountedMap)(items);
312
- map.forEach((quantity, item) => {
313
- var needed = Math.max(0, quantity - (0, _kolmafia.availableAmount)(item));
314
-
315
- if (needed === 0) {
316
- return map.set(item, 0);
317
- }
318
-
319
- var foldGroup = (0, _lib.getFoldGroup)(item);
320
-
321
- var _iterator = _createForOfIteratorHelper(foldGroup),
322
- _step;
323
-
324
- try {
325
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
326
- var foldable = _step.value;
327
- var quantityToFold = Math.min(needed, (0, _kolmafia.availableAmount)(foldable));
328
-
329
- for (var _i3 = 0; _i3 < quantityToFold; _i3++) {
330
- (0, _kolmafia.cliExecute)("fold ".concat(item.name));
331
- needed--;
332
- }
333
-
334
- return map.set(item, needed);
335
- }
336
- } catch (err) {
337
- _iterator.e(err);
338
- } finally {
339
- _iterator.f();
340
- }
341
-
342
- (0, _kolmafia.refreshStash)();
343
-
344
- for (var _i2 = 0, _arr2 = [item].concat(_toConsumableArray(foldGroup)); _i2 < _arr2.length; _i2++) {
345
- var matchingItem = _arr2[_i2];
346
- var quantityToTake = Math.min(needed, (0, _kolmafia.stashAmount)(matchingItem));
347
- if (quantityToTake === 0) continue; // If we can't take from the stash, there's no sense in iterating through the whole fold group
348
-
349
- if (!(0, _kolmafia.takeStash)(quantityToTake, matchingItem)) return;
350
-
351
- if (matchingItem === item) {
352
- needed -= quantityToTake;
353
- } else {
354
- for (var i = 0; i < quantityToTake; i++) {
355
- (0, _kolmafia.cliExecute)("fold ".concat(matchingItem.name));
356
- needed--;
357
- }
358
- }
359
- }
360
- });
361
- return Array.isArray(items) ? (0, _utils.countedMapToArray)(map) : map;
149
+ join() {
150
+ return Clan._join(this.id);
362
151
  }
363
- /**
364
- * Put items in the stash
365
- * @param items Items to put in the stash
366
- * @returns Items successfully put in the stash
367
- */
368
-
369
- }, {
370
- key: "put",
371
- value: function put(items) {
372
- var map = (0, _utils.arrayToCountedMap)(items);
373
- if (!this.check()) throw new Error("Wanted to return ".concat((0, _utils.countedMapToString)(map), " to ").concat(this.name, " but KoLmafia's clan data is out of sync"));
374
- map.forEach((quantity, item) => {
375
- (0, _kolmafia.retrieveItem)(quantity, item);
376
- var returned = Math.min(quantity, (0, _kolmafia.availableAmount)(item));
377
- (0, _kolmafia.putStash)(returned, item);
378
- map.set(item, quantity - returned);
379
- });
380
- return Array.isArray(items) ? (0, _utils.countedMapToArray)(map) : map;
152
+ check() {
153
+ return visitUrl("clan_hall.php").includes(`<b>${this.name}</b>`);
381
154
  }
382
155
  /**
383
156
  * Return the monster that is currently in the current clan's fax machine if any
384
157
  */
385
-
386
- }, {
387
- key: "withStash",
388
- value: function withStash(items, callback) {
389
- var map = (0, _utils.arrayToCountedMap)(items);
390
- return Clan._withStash(() => this.take(map), borrowed => this.put(borrowed), callback);
391
- }
392
- }], [{
393
- key: "_join",
394
- value: function _join(id) {
395
- var result = (0, _kolmafia.visitUrl)("showclan.php?recruiter=1&whichclan=".concat(id, "&pwd&whichclan=").concat(id, "&action=joinclan&apply=Apply+to+this+Clan&confirm=on"));
396
-
397
- if (!result.includes("clanhalltop.gif")) {
398
- throw new Error("Could not join clan");
399
- }
400
-
401
- return Clan.get();
402
- }
403
- }, {
404
- key: "_withStash",
405
- value: function _withStash(borrowFn, // eslint-disable-next-line @typescript-eslint/no-explicit-any
406
- returnFn, // eslint-disable-next-line @typescript-eslint/no-explicit-any
407
- callback) {
408
- var borrowed = borrowFn();
409
- var map = (0, _utils.arrayToCountedMap)(borrowed);
410
-
411
- try {
412
- return callback(borrowed);
413
- } finally {
414
- if (map.size > 0) {
415
- var returned = (0, _utils.arrayToCountedMap)(returnFn(borrowed));
416
- map.forEach((quantity, item) => {
417
- var remaining = quantity - (returned.get(item) || 0);
418
-
419
- if (remaining > 0) {
420
- map.set(item, remaining);
421
- } else {
422
- map.delete(item);
423
- }
424
- });
425
-
426
- if (map.size > 0) {
427
- _logger.default.error("Failed to return <b>".concat((0, _utils.countedMapToString)(map), "</b> to <b>").concat(this.name, "</b> stash"));
428
- }
429
- }
430
- }
158
+ getCurrentFax() {
159
+ const logs = visitUrl("clan_log.php");
160
+ const lastFax = logs.match(LOG_FAX_PATTERN);
161
+ if (!lastFax)
162
+ return null;
163
+ const [, , , monsterName] = lastFax;
164
+ if (!monsterName)
165
+ return null;
166
+ return Monster.get(monsterName);
431
167
  }
432
168
  /**
433
- * Join a clan and return its instance
434
- * @param clanIdOrName Clan id or name
169
+ * List available ranks (name, degree and id) from the current clan
435
170
  */
436
-
437
- }, {
438
- key: "join",
439
- value: function join(clanIdOrName) {
440
- var clanId;
441
-
442
- if (typeof clanIdOrName === "string") {
443
- var _clanName = clanIdOrName.toLowerCase();
444
-
445
- if (_clanName === (0, _kolmafia.getClanName)().toLowerCase()) {
446
- return Clan.get();
447
- }
448
-
449
- if (!(_clanName in clanIdCache)) {
450
- var clan = Clan.getWhitelisted().find(c => c.name.toLowerCase() === _clanName);
451
-
452
- if (!clan) {
453
- throw new Error("Player is not whitelisted to clan");
454
- }
455
-
456
- clanIdCache[_clanName] = clan.id;
457
- }
458
-
459
- clanId = clanIdCache[_clanName];
460
- } else {
461
- clanId = clanIdOrName;
462
-
463
- if (clanId === (0, _kolmafia.getClanId)()) {
464
- return Clan.get();
465
- }
466
- }
467
-
468
- return Clan._join(clanId);
171
+ getRanks() {
172
+ const page = visitUrl("clan_whitelist.php");
173
+ return xpath(page, '//select[@name="level"]//option')
174
+ .map((option) => {
175
+ const validHtml = `<select>${option}</select>`;
176
+ const match = xpath(validHtml, "//text()")[0].match(WHITELIST_DEGREE_PATTERN);
177
+ const id = xpath(validHtml, "//@value")[0];
178
+ if (!match || !id)
179
+ return null;
180
+ const [, name, degree] = match;
181
+ return {
182
+ name,
183
+ degree: Number.parseInt(degree),
184
+ id: Number.parseInt(id),
185
+ };
186
+ })
187
+ .filter(notNull);
469
188
  }
470
189
  /**
471
- * Execute callback as a member of a clan
472
- * and then restore prior membership
473
- * @param clanIdOrName Clan id or name
190
+ * Add a player to the current clan's whitelist.
191
+ * If the player is already in the whitelist this will change their rank or title.
192
+ * @param player Player id or name
193
+ * @param rankName Rank to give the player. If not provided they will be given the lowest rank
194
+ * @param title Title to give the player. If not provided, will be blank
474
195
  */
475
-
476
- }, {
477
- key: "with",
478
- value: function _with(clanIdOrName, callback) {
479
- var startingClan = Clan.get();
480
- var clan = Clan.join(clanIdOrName);
481
-
482
- try {
483
- return callback(clan);
484
- } finally {
485
- startingClan.join();
486
- }
196
+ addPlayerToWhitelist(player, rankName, title = "") {
197
+ const playerId = toPlayerId(player);
198
+ const ranks = this.getRanks();
199
+ const rank = rankName
200
+ ? ranks.find((r) => r.name === rankName)
201
+ : ranks.sort((a, b) => a.degree - b.degree)[0];
202
+ if (!rank)
203
+ return false;
204
+ const result = visitUrl(`clan_whitelist.php?action=add&pwd&addwho=${playerId}&level=${rank.id}&title=${title}`);
205
+ return (result.includes("added to whitelist.") ||
206
+ result.includes("That player is already on the whitelist"));
487
207
  }
488
208
  /**
489
- * Execute callback with items from a clan stash
490
- * and then restore those items to the stash
491
- *
492
- * During the execution of the callback, player will not be in the stash clan
493
- *
494
- * @param clanIdOrName Clan id or name
209
+ * Remove a player from the current clan's whitelist
210
+ * @param player Player id or name
495
211
  */
496
-
497
- }, {
498
- key: "withStash",
499
- value: function withStash(clanIdOrName, items, // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
500
- callback) {
501
- return Clan._withStash(() => Clan.with(clanIdOrName, clan => clan.take(items)), borrowed => Clan.with(clanIdOrName, clan => clan.put(borrowed)), callback);
212
+ removePlayerFromWhitelist(player) {
213
+ const playerId = toPlayerId(player);
214
+ const result = visitUrl(`clan_whitelist.php?action=updatewl&pwd&who=${playerId}&remove=Remove`);
215
+ return result.includes("Whitelist updated.");
502
216
  }
503
217
  /**
504
- * Return player's current Clan
218
+ * Return the amount of meat in the current clan's coffer.
505
219
  */
506
-
507
- }, {
508
- key: "get",
509
- value: function get() {
510
- return new Clan((0, _kolmafia.getClanId)(), (0, _kolmafia.getClanName)());
220
+ getMeatInCoffer() {
221
+ const page = visitUrl("clan_stash.php");
222
+ const [, meat] = page.match(/Your <b>Clan Coffer<\/b> contains ([\d,]+) Meat./) || ["0", "0"];
223
+ return parseNumber(meat);
511
224
  }
512
225
  /**
513
- * Get list of clans to which the player is whitelisted
226
+ * Add the given amount of meat to the current clan's coffer.
227
+ * @param amount Amount of meat to put in coffer
514
228
  */
515
-
516
- }, {
517
- key: "getWhitelisted",
518
- value: function getWhitelisted() {
519
- var page = (0, _kolmafia.visitUrl)("clan_signup.php");
520
- return (0, _kolmafia.xpath)(page, '//select[@name="whichclan"]//option').map(option => {
521
- var validHtml = "<select>".concat(option, "</select>");
522
- var id = Number.parseInt((0, _kolmafia.xpath)(validHtml, "//@value")[0]);
523
- var name = (0, _kolmafia.xpath)(validHtml, "//text()")[0];
524
- return new Clan(id, name);
525
- });
229
+ putMeatInCoffer(amount) {
230
+ const result = visitUrl(`clan_stash.php?pwd&action=contribute&howmuch=${amount}`);
231
+ return result.includes("You contributed");
232
+ }
233
+ take(items) {
234
+ const map = arrayToCountedMap(items);
235
+ map.forEach((quantity, item) => {
236
+ let needed = Math.max(0, quantity - availableAmount(item));
237
+ if (needed === 0) {
238
+ return map.set(item, 0);
239
+ }
240
+ const foldGroup = getFoldGroup(item);
241
+ for (const foldable of foldGroup) {
242
+ const quantityToFold = Math.min(needed, availableAmount(foldable));
243
+ for (let i = 0; i < quantityToFold; i++) {
244
+ cliExecute(`fold ${item.name}`);
245
+ needed--;
246
+ }
247
+ return map.set(item, needed);
248
+ }
249
+ refreshStash();
250
+ for (const matchingItem of [item, ...foldGroup]) {
251
+ const quantityToTake = Math.min(needed, stashAmount(matchingItem));
252
+ if (quantityToTake === 0)
253
+ continue;
254
+ // If we can't take from the stash, there's no sense in iterating through the whole fold group
255
+ if (!takeStash(quantityToTake, matchingItem))
256
+ return;
257
+ if (matchingItem === item) {
258
+ needed -= quantityToTake;
259
+ }
260
+ else {
261
+ for (let i = 0; i < quantityToTake; i++) {
262
+ cliExecute(`fold ${matchingItem.name}`);
263
+ needed--;
264
+ }
265
+ }
266
+ }
267
+ });
268
+ return Array.isArray(items) ? countedMapToArray(map) : map;
269
+ }
270
+ put(items) {
271
+ const map = arrayToCountedMap(items);
272
+ if (!this.check())
273
+ throw new Error(`Wanted to return ${countedMapToString(map)} to ${this.name} but KoLmafia's clan data is out of sync`);
274
+ map.forEach((quantity, item) => {
275
+ retrieveItem(quantity, item);
276
+ const returned = Math.min(quantity, availableAmount(item));
277
+ putStash(returned, item);
278
+ map.set(item, quantity - returned);
279
+ });
280
+ return Array.isArray(items) ? countedMapToArray(map) : map;
526
281
  }
527
- }]);
528
-
529
- return Clan;
530
- }(), (_applyDecoratedDescriptor(_class.prototype, "getCurrentFax", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "getCurrentFax"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getRanks", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "getRanks"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "addPlayerToWhitelist", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "addPlayerToWhitelist"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "removePlayerFromWhitelist", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "removePlayerFromWhitelist"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "getMeatInCoffer", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "getMeatInCoffer"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "putMeatInCoffer", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "putMeatInCoffer"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "take", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "take"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "put", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "put"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "withStash", [validate], Object.getOwnPropertyDescriptor(_class.prototype, "withStash"), _class.prototype)), _class);
531
- exports.Clan = Clan;
282
+ withStash(items, callback // eslint-disable-line @typescript-eslint/no-explicit-any
283
+ ) {
284
+ const map = arrayToCountedMap(items);
285
+ return Clan._withStash(() => this.take(map), (borrowed) => this.put(borrowed), callback);
286
+ }
287
+ }
288
+ __decorate([
289
+ validate
290
+ ], Clan.prototype, "getCurrentFax", null);
291
+ __decorate([
292
+ validate
293
+ ], Clan.prototype, "getRanks", null);
294
+ __decorate([
295
+ validate
296
+ ], Clan.prototype, "addPlayerToWhitelist", null);
297
+ __decorate([
298
+ validate
299
+ ], Clan.prototype, "removePlayerFromWhitelist", null);
300
+ __decorate([
301
+ validate
302
+ ], Clan.prototype, "getMeatInCoffer", null);
303
+ __decorate([
304
+ validate
305
+ ], Clan.prototype, "putMeatInCoffer", null);
306
+ __decorate([
307
+ validate
308
+ ], Clan.prototype, "take", null);
309
+ __decorate([
310
+ validate
311
+ ], Clan.prototype, "put", null);
312
+ __decorate([
313
+ validate
314
+ ], Clan.prototype, "withStash", null);