libram 0.8.26 → 0.8.28

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 (195) hide show
  1. package/package.json +9 -8
  2. package/dist/Clan.d.ts +0 -128
  3. package/dist/Clan.js +0 -300
  4. package/dist/Copier.d.ts +0 -9
  5. package/dist/Copier.js +0 -15
  6. package/dist/Dungeon.d.ts +0 -45
  7. package/dist/Dungeon.js +0 -115
  8. package/dist/Kmail.d.ts +0 -104
  9. package/dist/Kmail.js +0 -182
  10. package/dist/actions/ActionSource.d.ts +0 -131
  11. package/dist/actions/ActionSource.js +0 -177
  12. package/dist/actions/Banish.d.ts +0 -16
  13. package/dist/actions/Banish.js +0 -121
  14. package/dist/actions/FreeKill.d.ts +0 -16
  15. package/dist/actions/FreeKill.js +0 -94
  16. package/dist/actions/FreeRun.d.ts +0 -16
  17. package/dist/actions/FreeRun.js +0 -77
  18. package/dist/actions/index.d.ts +0 -4
  19. package/dist/actions/index.js +0 -4
  20. package/dist/ascend.d.ts +0 -83
  21. package/dist/ascend.js +0 -268
  22. package/dist/challengePaths/2014/HeavyRains.d.ts +0 -22
  23. package/dist/challengePaths/2014/HeavyRains.js +0 -75
  24. package/dist/challengePaths/2015/CommunityService.d.ts +0 -125
  25. package/dist/challengePaths/2015/CommunityService.js +0 -334
  26. package/dist/challengePaths/2016/NuclearAutumn.d.ts +0 -13
  27. package/dist/challengePaths/2016/NuclearAutumn.js +0 -21
  28. package/dist/challengePaths/index.d.ts +0 -4
  29. package/dist/challengePaths/index.js +0 -4
  30. package/dist/combat.d.ts +0 -414
  31. package/dist/combat.js +0 -711
  32. package/dist/console.d.ts +0 -12
  33. package/dist/console.js +0 -14
  34. package/dist/counter.d.ts +0 -22
  35. package/dist/counter.js +0 -37
  36. package/dist/diet/index.d.ts +0 -80
  37. package/dist/diet/index.js +0 -662
  38. package/dist/diet/knapsack.d.ts +0 -8
  39. package/dist/diet/knapsack.js +0 -128
  40. package/dist/index.d.ts +0 -29
  41. package/dist/index.js +0 -26
  42. package/dist/lib.d.ts +0 -497
  43. package/dist/lib.js +0 -958
  44. package/dist/logger.d.ts +0 -35
  45. package/dist/logger.js +0 -62
  46. package/dist/maximize.d.ts +0 -121
  47. package/dist/maximize.js +0 -525
  48. package/dist/modifier.d.ts +0 -41
  49. package/dist/modifier.js +0 -160
  50. package/dist/modifierTypes.d.ts +0 -16
  51. package/dist/modifierTypes.js +0 -9
  52. package/dist/mood.d.ts +0 -105
  53. package/dist/mood.js +0 -349
  54. package/dist/moonSign.d.ts +0 -13
  55. package/dist/moonSign.js +0 -25
  56. package/dist/overlappingNames.d.ts +0 -3
  57. package/dist/overlappingNames.js +0 -42
  58. package/dist/property.d.ts +0 -222
  59. package/dist/property.js +0 -385
  60. package/dist/propertyTypes.d.ts +0 -19
  61. package/dist/propertyTypes.js +0 -10
  62. package/dist/propertyTyping.d.ts +0 -65
  63. package/dist/propertyTyping.js +0 -91
  64. package/dist/resources/2007/CandyHearts.d.ts +0 -9
  65. package/dist/resources/2007/CandyHearts.js +0 -24
  66. package/dist/resources/2008/DivineFavors.d.ts +0 -9
  67. package/dist/resources/2008/DivineFavors.js +0 -27
  68. package/dist/resources/2008/Stickers.d.ts +0 -49
  69. package/dist/resources/2008/Stickers.js +0 -84
  70. package/dist/resources/2009/Bandersnatch.d.ts +0 -56
  71. package/dist/resources/2009/Bandersnatch.js +0 -93
  72. package/dist/resources/2009/LoveSongs.d.ts +0 -9
  73. package/dist/resources/2009/LoveSongs.js +0 -24
  74. package/dist/resources/2009/SpookyPutty.d.ts +0 -31
  75. package/dist/resources/2009/SpookyPutty.js +0 -49
  76. package/dist/resources/2010/Brickos.d.ts +0 -9
  77. package/dist/resources/2010/Brickos.js +0 -21
  78. package/dist/resources/2010/CrownOfThrones.d.ts +0 -68
  79. package/dist/resources/2010/CrownOfThrones.js +0 -418
  80. package/dist/resources/2010/LookingGlass.d.ts +0 -29
  81. package/dist/resources/2010/LookingGlass.js +0 -89
  82. package/dist/resources/2011/Gygaxian.d.ts +0 -9
  83. package/dist/resources/2011/Gygaxian.js +0 -24
  84. package/dist/resources/2011/ObtuseAngel.d.ts +0 -33
  85. package/dist/resources/2011/ObtuseAngel.js +0 -51
  86. package/dist/resources/2011/StompingBoots.d.ts +0 -37
  87. package/dist/resources/2011/StompingBoots.js +0 -57
  88. package/dist/resources/2012/RainDoh.d.ts +0 -25
  89. package/dist/resources/2012/RainDoh.js +0 -37
  90. package/dist/resources/2012/ReagnimatedGnome.d.ts +0 -31
  91. package/dist/resources/2012/ReagnimatedGnome.js +0 -46
  92. package/dist/resources/2012/Resolutions.d.ts +0 -9
  93. package/dist/resources/2012/Resolutions.js +0 -28
  94. package/dist/resources/2013/Florist.d.ts +0 -81
  95. package/dist/resources/2013/Florist.js +0 -245
  96. package/dist/resources/2013/JungMan.d.ts +0 -33
  97. package/dist/resources/2013/JungMan.js +0 -69
  98. package/dist/resources/2013/PulledTaffy.d.ts +0 -9
  99. package/dist/resources/2013/PulledTaffy.js +0 -33
  100. package/dist/resources/2014/CrimboShrub.d.ts +0 -42
  101. package/dist/resources/2014/CrimboShrub.js +0 -89
  102. package/dist/resources/2014/DNALab.d.ts +0 -56
  103. package/dist/resources/2014/DNALab.js +0 -162
  104. package/dist/resources/2014/WinterGarden.d.ts +0 -23
  105. package/dist/resources/2014/WinterGarden.js +0 -35
  106. package/dist/resources/2015/BarrelShrine.d.ts +0 -8
  107. package/dist/resources/2015/BarrelShrine.js +0 -25
  108. package/dist/resources/2015/ChateauMantegna.d.ts +0 -52
  109. package/dist/resources/2015/ChateauMantegna.js +0 -99
  110. package/dist/resources/2015/DeckOfEveryCard.d.ts +0 -29
  111. package/dist/resources/2015/DeckOfEveryCard.js +0 -122
  112. package/dist/resources/2015/Dinseylandfill.d.ts +0 -89
  113. package/dist/resources/2015/Dinseylandfill.js +0 -205
  114. package/dist/resources/2015/MayoClinic.d.ts +0 -23
  115. package/dist/resources/2015/MayoClinic.js +0 -49
  116. package/dist/resources/2016/GingerBread.d.ts +0 -32
  117. package/dist/resources/2016/GingerBread.js +0 -73
  118. package/dist/resources/2016/SourceTerminal.d.ts +0 -181
  119. package/dist/resources/2016/SourceTerminal.js +0 -275
  120. package/dist/resources/2016/Witchess.d.ts +0 -17
  121. package/dist/resources/2016/Witchess.js +0 -47
  122. package/dist/resources/2017/AsdonMartin.d.ts +0 -59
  123. package/dist/resources/2017/AsdonMartin.js +0 -238
  124. package/dist/resources/2017/Horsery.d.ts +0 -19
  125. package/dist/resources/2017/Horsery.js +0 -42
  126. package/dist/resources/2017/MummingTrunk.d.ts +0 -8
  127. package/dist/resources/2017/MummingTrunk.js +0 -33
  128. package/dist/resources/2017/Pantogram.d.ts +0 -92
  129. package/dist/resources/2017/Pantogram.js +0 -174
  130. package/dist/resources/2017/Robortender.d.ts +0 -30
  131. package/dist/resources/2017/Robortender.js +0 -90
  132. package/dist/resources/2017/Spacegate.d.ts +0 -86
  133. package/dist/resources/2017/Spacegate.js +0 -178
  134. package/dist/resources/2017/TunnelOfLove.d.ts +0 -39
  135. package/dist/resources/2017/TunnelOfLove.js +0 -120
  136. package/dist/resources/2018/LatteLoversMembersMug.d.ts +0 -392
  137. package/dist/resources/2018/LatteLoversMembersMug.js +0 -303
  138. package/dist/resources/2018/SongBoom.d.ts +0 -33
  139. package/dist/resources/2018/SongBoom.js +0 -55
  140. package/dist/resources/2019/BeachComb.d.ts +0 -72
  141. package/dist/resources/2019/BeachComb.js +0 -118
  142. package/dist/resources/2019/CampAway.d.ts +0 -39
  143. package/dist/resources/2019/CampAway.js +0 -72
  144. package/dist/resources/2019/Snapper.d.ts +0 -33
  145. package/dist/resources/2019/Snapper.js +0 -73
  146. package/dist/resources/2020/Cartography.d.ts +0 -16
  147. package/dist/resources/2020/Cartography.js +0 -48
  148. package/dist/resources/2020/Guzzlr.d.ts +0 -160
  149. package/dist/resources/2020/Guzzlr.js +0 -275
  150. package/dist/resources/2020/RetroCape.d.ts +0 -51
  151. package/dist/resources/2020/RetroCape.js +0 -115
  152. package/dist/resources/2021/CrystalBall.d.ts +0 -14
  153. package/dist/resources/2021/CrystalBall.js +0 -39
  154. package/dist/resources/2021/DaylightShavings.d.ts +0 -40
  155. package/dist/resources/2021/DaylightShavings.js +0 -74
  156. package/dist/resources/2022/AutumnAton.d.ts +0 -78
  157. package/dist/resources/2022/AutumnAton.js +0 -182
  158. package/dist/resources/2022/CombatLoversLocket.d.ts +0 -44
  159. package/dist/resources/2022/CombatLoversLocket.js +0 -82
  160. package/dist/resources/2022/GreyGoose.d.ts +0 -59
  161. package/dist/resources/2022/GreyGoose.js +0 -90
  162. package/dist/resources/2022/JuneCleaver.d.ts +0 -47
  163. package/dist/resources/2022/JuneCleaver.js +0 -69
  164. package/dist/resources/2022/TrainSet.d.ts +0 -146
  165. package/dist/resources/2022/TrainSet.js +0 -228
  166. package/dist/resources/2023/AugustScepter.d.ts +0 -25
  167. package/dist/resources/2023/AugustScepter.js +0 -40
  168. package/dist/resources/2023/BurningLeaves.d.ts +0 -25
  169. package/dist/resources/2023/BurningLeaves.js +0 -74
  170. package/dist/resources/2023/CinchoDeMayo.d.ts +0 -25
  171. package/dist/resources/2023/CinchoDeMayo.js +0 -45
  172. package/dist/resources/2023/ClosedCircuitPayphone.d.ts +0 -80
  173. package/dist/resources/2023/ClosedCircuitPayphone.js +0 -129
  174. package/dist/resources/2023/CursedMonkeyPaw.d.ts +0 -46
  175. package/dist/resources/2023/CursedMonkeyPaw.js +0 -113
  176. package/dist/resources/2024/AprilingBandHelmet.d.ts +0 -50
  177. package/dist/resources/2024/AprilingBandHelmet.js +0 -103
  178. package/dist/resources/2024/ChestMimic.d.ts +0 -35
  179. package/dist/resources/2024/ChestMimic.js +0 -108
  180. package/dist/resources/LibramSummon.d.ts +0 -18
  181. package/dist/resources/LibramSummon.js +0 -74
  182. package/dist/resources/index.d.ts +0 -54
  183. package/dist/resources/index.js +0 -54
  184. package/dist/resources/putty-likes.d.ts +0 -21
  185. package/dist/resources/putty-likes.js +0 -33
  186. package/dist/session.d.ts +0 -169
  187. package/dist/session.js +0 -284
  188. package/dist/since.d.ts +0 -51
  189. package/dist/since.js +0 -108
  190. package/dist/template-string.d.ts +0 -324
  191. package/dist/template-string.js +0 -265
  192. package/dist/url.d.ts +0 -35
  193. package/dist/url.js +0 -67
  194. package/dist/utils.d.ts +0 -178
  195. package/dist/utils.js +0 -255
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "libram",
3
- "version": "0.8.26",
3
+ "version": "0.8.28",
4
4
  "description": "JavaScript helper library for KoLmafia",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "repository": "https://github.com/loathers/libram",
8
8
  "author": "Samuel Gaus <sam@gaus.co.uk>",
9
9
  "license": "MIT",
10
- "private": false,
11
10
  "scripts": {
12
11
  "build": "yarn run updateOverlappingItemSkillNames && yarn run build:tsc && yarn run build:bundled",
13
12
  "build:tsc": "tsc",
@@ -16,6 +15,7 @@
16
15
  "docs": "yarn run typedoc",
17
16
  "format": "yarn run prettier --write .",
18
17
  "lint": "yarn run eslint src tools --ext .ts && yarn run prettier --check .",
18
+ "test": "yarn run jest",
19
19
  "prepublishOnly": "yarn run build",
20
20
  "updateProps": "yarn run ts-node ./tools/parseDefaultProperties.ts",
21
21
  "updateOverlappingItemSkillNames": "yarn run ts-node ./tools/parseItemSkillNames.ts"
@@ -35,7 +35,7 @@
35
35
  "@babel/preset-env": "^7.16.11",
36
36
  "@babel/preset-typescript": "^7.15.0",
37
37
  "@tsconfig/node16": "^1.0.2",
38
- "@types/jest": "^27.0.1",
38
+ "@types/jest": "^29.5.12",
39
39
  "@types/lodash-es": "^4.17.4",
40
40
  "@types/node": "^16.11.11",
41
41
  "@types/node-fetch": "^2.5.7",
@@ -52,12 +52,12 @@
52
52
  "eslint-plugin-libram": "^0.4.5",
53
53
  "husky": "^4.3.6",
54
54
  "java-parser": "^1.4.0",
55
- "jest": "^27.1.0",
56
- "kolmafia": "^5.27668.0",
55
+ "jest": "^29.7.0",
56
+ "kolmafia": "^5.27916.0",
57
57
  "lint-staged": ">=10",
58
58
  "node-fetch": "^2.6.1",
59
59
  "prettier": "^2.1.2",
60
- "ts-jest": "^27.0.5",
60
+ "ts-jest": "^29.1.2",
61
61
  "ts-node": "^10.4.0",
62
62
  "typedoc": "^0.22.10",
63
63
  "typescript": "^4.5.2"
@@ -73,5 +73,6 @@
73
73
  "lint-staged": {
74
74
  "src/**/*.{ts,js}": "prettier --write"
75
75
  },
76
- "sideEffects": false
77
- }
76
+ "sideEffects": false,
77
+ "packageManager": "yarn@4.1.1"
78
+ }
package/dist/Clan.d.ts DELETED
@@ -1,128 +0,0 @@
1
- import { Item, Monster } from "kolmafia";
2
- export interface Rank {
3
- name: string;
4
- degree: number;
5
- id: number;
6
- }
7
- export declare class Clan {
8
- readonly id: number;
9
- readonly name: string;
10
- private static _join;
11
- private static _withStash;
12
- /**
13
- * Join a clan
14
- *
15
- * @param clanIdOrName Clan id or name
16
- * @returns Instance of joined clan
17
- */
18
- static join(clanIdOrName: string | number): Clan;
19
- /**
20
- * Execute callback as a member of a clan and then restore prior membership
21
- *
22
- * @param clanIdOrName Clan id or name
23
- * @param callback Actions to carry out while member of specified can
24
- * @returns Return value from callback
25
- */
26
- static with<T>(clanIdOrName: string | number, callback: (clan: Clan) => T): T;
27
- /**
28
- * Execute callback with items from a clan stash
29
- * and then restore those items to the stash
30
- *
31
- * During the execution of the callback, player will not be in the stash clan
32
- *
33
- * @param clanIdOrName Clan id or name
34
- */
35
- static withStash<T>(clanIdOrName: string | number, items: Item[], callback: (borrowedItems: Item[]) => T): T;
36
- static withStash<T>(clanIdOrName: string | number, items: Map<Item, number>, callback: (borrowedItems: Map<Item, number>) => T): T;
37
- /**
38
- * Get the player's current clan
39
- *
40
- * @returns Player's clan
41
- */
42
- static get(): Clan;
43
- /**
44
- * Get list of clans to which the player is whitelisted
45
- *
46
- * @returns List of clans
47
- */
48
- static getWhitelisted(): Clan[];
49
- private constructor();
50
- private _check;
51
- /**
52
- * Join clan
53
- *
54
- * @returns Joined clan
55
- */
56
- join(): Clan;
57
- /**
58
- * Check that this clan is the player's current clan
59
- *
60
- * @returns Whether this is the current clan
61
- */
62
- check(): boolean;
63
- /**
64
- * Determine the monster that is currently in the current clan's fax machine if any
65
- *
66
- * @returns The current fax monster
67
- */
68
- getCurrentFax(): Monster | null;
69
- /**
70
- * List available ranks (name, degree and id) from the current clan
71
- *
72
- * @returns List of ranks
73
- */
74
- getRanks(): Rank[];
75
- /**
76
- * Add a player to the current clan's whitelist.
77
- * If the player is already in the whitelist this will change their rank or title.
78
- *
79
- * @param player Player id or name
80
- * @param rankName Rank to give the player. If not provided they will be given the lowest rank
81
- * @param title Title to give the player. If not provided, will be blank
82
- * @returns Success
83
- */
84
- addPlayerToWhitelist(player: string | number, rankName?: string, title?: string): boolean;
85
- /**
86
- * Remove a player from the current clan's whitelist
87
- *
88
- * @param player Player id or name
89
- * @returns Success
90
- */
91
- removePlayerFromWhitelist(player: string | number): boolean;
92
- /**
93
- * Return the amount of meat in the current clan's coffer
94
- *
95
- * @returns Amount of meat
96
- */
97
- getMeatInCoffer(): number;
98
- /**
99
- * Add the given amount of meat to the current clan's coffer.
100
- *
101
- * @param amount Amount of meat to put in coffer
102
- * @returns Success
103
- */
104
- putMeatInCoffer(amount: number): boolean;
105
- /**
106
- * Take items from the stash
107
- *
108
- * This function will also take equivalent foldables if the original item cannot be found
109
- *
110
- * @param items Items to take
111
- * @returns Items successfully taken
112
- */
113
- take(items: Item[]): Item[];
114
- take(items: Map<Item, number>): Map<Item, number>;
115
- /**
116
- * Put items in the stash
117
- *
118
- * @param items Items to put in the stash
119
- * @returns Items successfully put in the stash
120
- */
121
- put(items: Item[]): Item[];
122
- put(items: Map<Item, number>): Map<Item, number>;
123
- /**
124
- * Return the monster that is currently in the current clan's fax machine if any
125
- */
126
- withStash<T>(items: Item[], callback: (borrowedItems: Item[]) => T): T;
127
- withStash<T>(items: Map<Item, number>, callback: (borrowedItems: Map<Item, number>) => T): T;
128
- }
package/dist/Clan.js DELETED
@@ -1,300 +0,0 @@
1
- import { decode as decodeEntities } from "html-entities";
2
- import { availableAmount, cliExecute, getClanId, getClanName, getPlayerId, Monster, putStash, refreshStash, retrieveItem, stashAmount, takeStash, visitUrl, xpath, } from "kolmafia";
3
- import { getFoldGroup } from "./lib";
4
- import logger from "./logger";
5
- import { arrayToCountedMap, countedMapToArray, countedMapToString, notNull, parseNumber, } from "./utils";
6
- const clanIdCache = {};
7
- const toPlayerId = (player) => typeof player === "string" ? getPlayerId(player) : player;
8
- const LOG_FAX_PATTERN = /(\d{2}\/\d{2}\/\d{2}, \d{2}:\d{2}(?:AM|PM): )<a [^>]+>([^<]+)<\/a>(?: faxed in a (?<monster>.*?))<br>/;
9
- const WHITELIST_DEGREE_PATTERN = /(?<name>.*?) \(°(?<degree>\d+)\)/;
10
- export class Clan {
11
- id;
12
- name;
13
- static _join(id) {
14
- const result = visitUrl(`showclan.php?recruiter=1&whichclan=${id}&pwd&whichclan=${id}&action=joinclan&apply=Apply+to+this+Clan&confirm=on`);
15
- if (!result.includes("clanhalltop.gif")) {
16
- throw new Error("Could not join clan");
17
- }
18
- return Clan.get();
19
- }
20
- static _withStash(borrowFn,
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- returnFn,
23
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
- callback) {
25
- const borrowed = borrowFn();
26
- const map = arrayToCountedMap(borrowed);
27
- try {
28
- return callback(borrowed);
29
- }
30
- finally {
31
- if (map.size > 0) {
32
- const returned = arrayToCountedMap(returnFn(borrowed));
33
- map.forEach((quantity, item) => {
34
- const remaining = quantity - (returned.get(item) || 0);
35
- if (remaining > 0) {
36
- map.set(item, remaining);
37
- }
38
- else {
39
- map.delete(item);
40
- }
41
- });
42
- if (map.size > 0) {
43
- logger.error(`Failed to return <b>${countedMapToString(map)}</b> to <b>${this.name}</b> stash`);
44
- }
45
- }
46
- }
47
- }
48
- /**
49
- * Join a clan
50
- *
51
- * @param clanIdOrName Clan id or name
52
- * @returns Instance of joined clan
53
- */
54
- static join(clanIdOrName) {
55
- let clanId;
56
- if (typeof clanIdOrName === "string") {
57
- const clanName = clanIdOrName.toLowerCase();
58
- if (clanName === getClanName().toLowerCase()) {
59
- return Clan.get();
60
- }
61
- if (!(clanName in clanIdCache)) {
62
- const clan = Clan.getWhitelisted().find((c) => c.name.toLowerCase() === clanName);
63
- if (!clan) {
64
- throw new Error("Player is not whitelisted to clan");
65
- }
66
- clanIdCache[clanName] = clan.id;
67
- }
68
- clanId = clanIdCache[clanName];
69
- }
70
- else {
71
- clanId = clanIdOrName;
72
- if (clanId === getClanId()) {
73
- return Clan.get();
74
- }
75
- }
76
- return Clan._join(clanId);
77
- }
78
- /**
79
- * Execute callback as a member of a clan and then restore prior membership
80
- *
81
- * @param clanIdOrName Clan id or name
82
- * @param callback Actions to carry out while member of specified can
83
- * @returns Return value from callback
84
- */
85
- static with(clanIdOrName, callback) {
86
- const startingClan = Clan.get();
87
- const clan = Clan.join(clanIdOrName);
88
- try {
89
- return callback(clan);
90
- }
91
- finally {
92
- startingClan.join();
93
- }
94
- }
95
- static withStash(clanIdOrName, items, // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
96
- callback // eslint-disable-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
97
- ) {
98
- return Clan._withStash(() => Clan.with(clanIdOrName, (clan) => clan.take(items)), (borrowed) => Clan.with(clanIdOrName, (clan) => clan.put(borrowed)), callback);
99
- }
100
- /**
101
- * Get the player's current clan
102
- *
103
- * @returns Player's clan
104
- */
105
- static get() {
106
- return new Clan(getClanId(), getClanName());
107
- }
108
- /**
109
- * Get list of clans to which the player is whitelisted
110
- *
111
- * @returns List of clans
112
- */
113
- static getWhitelisted() {
114
- const page = visitUrl("clan_signup.php");
115
- return xpath(page, '//select[@name="whichclan"]//option').map((option) => {
116
- const validHtml = `<select>${option}</select>`;
117
- const id = Number.parseInt(xpath(validHtml, "//@value")[0]);
118
- const name = decodeEntities(xpath(validHtml, "//text()")[0]);
119
- return new Clan(id, name);
120
- });
121
- }
122
- constructor(id, name) {
123
- this.id = id;
124
- this.name = name;
125
- }
126
- _check() {
127
- if (this.id !== getClanId()) {
128
- throw new Error("You are no longer a member of this clan");
129
- }
130
- }
131
- /**
132
- * Join clan
133
- *
134
- * @returns Joined clan
135
- */
136
- join() {
137
- return Clan.join(this.id);
138
- }
139
- /**
140
- * Check that this clan is the player's current clan
141
- *
142
- * @returns Whether this is the current clan
143
- */
144
- check() {
145
- return visitUrl("clan_hall.php").includes(`<b>${this.name}</b>`);
146
- }
147
- /**
148
- * Determine the monster that is currently in the current clan's fax machine if any
149
- *
150
- * @returns The current fax monster
151
- */
152
- getCurrentFax() {
153
- this._check();
154
- const logs = visitUrl("clan_log.php");
155
- const lastFax = logs.match(LOG_FAX_PATTERN);
156
- if (!lastFax)
157
- return null;
158
- const [, , , monsterName] = lastFax;
159
- if (!monsterName)
160
- return null;
161
- return Monster.get(monsterName);
162
- }
163
- /**
164
- * List available ranks (name, degree and id) from the current clan
165
- *
166
- * @returns List of ranks
167
- */
168
- getRanks() {
169
- this._check();
170
- const page = visitUrl("clan_whitelist.php");
171
- return xpath(page, '//select[@name="level"]//option')
172
- .map((option) => {
173
- const validHtml = `<select>${option}</select>`;
174
- const match = xpath(validHtml, "//text()")[0].match(WHITELIST_DEGREE_PATTERN);
175
- const id = xpath(validHtml, "//@value")[0];
176
- if (!match || !id)
177
- return null;
178
- const [, encodedName, degree] = match;
179
- return {
180
- name: decodeEntities(encodedName),
181
- degree: Number.parseInt(degree),
182
- id: Number.parseInt(id),
183
- };
184
- })
185
- .filter(notNull);
186
- }
187
- /**
188
- * Add a player to the current clan's whitelist.
189
- * If the player is already in the whitelist this will change their rank or title.
190
- *
191
- * @param player Player id or name
192
- * @param rankName Rank to give the player. If not provided they will be given the lowest rank
193
- * @param title Title to give the player. If not provided, will be blank
194
- * @returns Success
195
- */
196
- addPlayerToWhitelist(player, rankName, title = "") {
197
- this._check();
198
- const playerId = toPlayerId(player);
199
- const ranks = this.getRanks();
200
- const rank = rankName
201
- ? ranks.find((r) => r.name === rankName)
202
- : ranks.sort((a, b) => a.degree - b.degree)[0];
203
- if (!rank)
204
- return false;
205
- const result = visitUrl(`clan_whitelist.php?action=add&pwd&addwho=${playerId}&level=${rank.id}&title=${title}`);
206
- return (result.includes("added to whitelist.") ||
207
- result.includes("That player is already on the whitelist"));
208
- }
209
- /**
210
- * Remove a player from the current clan's whitelist
211
- *
212
- * @param player Player id or name
213
- * @returns Success
214
- */
215
- removePlayerFromWhitelist(player) {
216
- this._check();
217
- const playerId = toPlayerId(player);
218
- const result = visitUrl(`clan_whitelist.php?action=updatewl&pwd&who=${playerId}&remove=Remove`);
219
- return result.includes("Whitelist updated.");
220
- }
221
- /**
222
- * Return the amount of meat in the current clan's coffer
223
- *
224
- * @returns Amount of meat
225
- */
226
- getMeatInCoffer() {
227
- this._check();
228
- const page = visitUrl("clan_stash.php");
229
- const [, meat] = page.match(/Your <b>Clan Coffer<\/b> contains ([\d,]+) Meat./) || ["0", "0"];
230
- return parseNumber(meat);
231
- }
232
- /**
233
- * Add the given amount of meat to the current clan's coffer.
234
- *
235
- * @param amount Amount of meat to put in coffer
236
- * @returns Success
237
- */
238
- putMeatInCoffer(amount) {
239
- this._check();
240
- const result = visitUrl(`clan_stash.php?pwd&action=contribute&howmuch=${amount}`);
241
- return result.includes("You contributed");
242
- }
243
- take(items) {
244
- this._check();
245
- const map = arrayToCountedMap(items);
246
- map.forEach((quantity, item) => {
247
- let needed = Math.max(0, quantity - availableAmount(item));
248
- if (needed === 0) {
249
- return map.set(item, 0);
250
- }
251
- const foldGroup = getFoldGroup(item);
252
- for (const foldable of foldGroup) {
253
- const quantityToFold = Math.min(needed, availableAmount(foldable));
254
- for (let i = 0; i < quantityToFold; i++) {
255
- cliExecute(`fold ${item.name}`);
256
- needed--;
257
- }
258
- return map.set(item, needed);
259
- }
260
- refreshStash();
261
- for (const matchingItem of [item, ...foldGroup]) {
262
- const quantityToTake = Math.min(needed, stashAmount(matchingItem));
263
- if (quantityToTake === 0)
264
- continue;
265
- // If we can't take from the stash, there's no sense in iterating through the whole fold group
266
- if (!takeStash(quantityToTake, matchingItem))
267
- return;
268
- if (matchingItem === item) {
269
- needed -= quantityToTake;
270
- }
271
- else {
272
- for (let i = 0; i < quantityToTake; i++) {
273
- cliExecute(`fold ${matchingItem.name}`);
274
- needed--;
275
- }
276
- }
277
- }
278
- });
279
- return Array.isArray(items) ? countedMapToArray(map) : map;
280
- }
281
- put(items) {
282
- this._check();
283
- const map = arrayToCountedMap(items);
284
- if (!this.check())
285
- throw new Error(`Wanted to return ${countedMapToString(map)} to ${this.name} but KoLmafia's clan data is out of sync`);
286
- map.forEach((quantity, item) => {
287
- retrieveItem(quantity, item);
288
- const returned = Math.min(quantity, availableAmount(item));
289
- putStash(returned, item);
290
- map.set(item, quantity - returned);
291
- });
292
- return Array.isArray(items) ? countedMapToArray(map) : map;
293
- }
294
- withStash(items, callback // eslint-disable-line @typescript-eslint/no-explicit-any
295
- ) {
296
- this._check();
297
- const map = arrayToCountedMap(items);
298
- return Clan._withStash(() => this.take(map), (borrowed) => this.put(borrowed), callback);
299
- }
300
- }
package/dist/Copier.d.ts DELETED
@@ -1,9 +0,0 @@
1
- import { Monster } from "kolmafia";
2
- export declare class Copier {
3
- readonly couldCopy: () => boolean;
4
- readonly prepare: (() => boolean) | null;
5
- readonly canCopy: () => boolean;
6
- readonly copiedMonster: () => Monster | null;
7
- readonly fightCopy: (() => boolean) | null;
8
- constructor(couldCopy: () => boolean, prepare: (() => boolean) | null, canCopy: () => boolean, copiedMonster: () => Monster | null, fightCopy?: () => boolean);
9
- }
package/dist/Copier.js DELETED
@@ -1,15 +0,0 @@
1
- export class Copier {
2
- couldCopy;
3
- prepare;
4
- canCopy;
5
- copiedMonster;
6
- fightCopy = null;
7
- constructor(couldCopy, prepare, canCopy, copiedMonster, fightCopy) {
8
- this.couldCopy = couldCopy;
9
- this.prepare = prepare;
10
- this.canCopy = canCopy;
11
- this.copiedMonster = copiedMonster;
12
- if (fightCopy)
13
- this.fightCopy = fightCopy;
14
- }
15
- }
package/dist/Dungeon.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import { Item } from "kolmafia";
2
- export declare class Dungeon {
3
- private name_;
4
- private loot;
5
- private openAction;
6
- private closeAction;
7
- private openCost;
8
- private openImage;
9
- private closedImage;
10
- get possibleLoot(): Item[];
11
- get name(): string;
12
- /**
13
- * Creates dungeon object for managing clan dungeons
14
- *
15
- * @param name_ name_ of the dungeon in question
16
- * @param loot Distributable loot dropped by bosses in dungeon
17
- * @param openAction String action used in form submission to open dungeon
18
- * @param closeAction String action used in form submission to close dungeon
19
- * @param openCost Meat cost of opening dungeon
20
- * @param openImage Image text to search clan_basement.php for to check if dungeon is open
21
- * @param closedImage Image text to search clan_basement.php for to check if dungeon is closed
22
- */
23
- constructor(name_: string, loot: Item[], openAction: string, closeAction: string, openCost: number, openImage: string, closedImage: string);
24
- distribute(idOrname_: number | string, loot?: Item | Item[] | Map<Item, number>, distributeAllOfAGivenItem?: boolean): void;
25
- /**
26
- * Close this dungeon
27
- *
28
- * @returns Whether the dungeon is now closed
29
- */
30
- close(): boolean;
31
- /**
32
- * Open an instance of this dungeon
33
- *
34
- * @param paymentPolicy How much meat should we put into the clan stash to open this dungeon?
35
- * @returns Whether the dungeon is now open
36
- */
37
- open(paymentPolicy?: "None" | "All" | "Difference"): boolean;
38
- /**
39
- * @returns A counted map of all loot from this dungeon eligible for distribution
40
- */
41
- findLoot(): Map<Item, number>;
42
- }
43
- export declare const Dreadsylvania: Dungeon;
44
- export declare const Hobopolis: Dungeon;
45
- export declare const SlimeTube: Dungeon;
package/dist/Dungeon.js DELETED
@@ -1,115 +0,0 @@
1
- import { getClanName, toItem, visitUrl, xpath } from "kolmafia";
2
- import { Clan } from "./Clan";
3
- import { getPlayerFromIdOrName } from "./lib";
4
- import { $items } from "./template-string";
5
- import { countedMapToArray } from "./utils";
6
- export class Dungeon {
7
- name_;
8
- loot;
9
- openAction;
10
- closeAction;
11
- openCost;
12
- openImage;
13
- closedImage;
14
- get possibleLoot() {
15
- return [...this.loot];
16
- }
17
- get name() {
18
- return this.name_;
19
- }
20
- /**
21
- * Creates dungeon object for managing clan dungeons
22
- *
23
- * @param name_ name_ of the dungeon in question
24
- * @param loot Distributable loot dropped by bosses in dungeon
25
- * @param openAction String action used in form submission to open dungeon
26
- * @param closeAction String action used in form submission to close dungeon
27
- * @param openCost Meat cost of opening dungeon
28
- * @param openImage Image text to search clan_basement.php for to check if dungeon is open
29
- * @param closedImage Image text to search clan_basement.php for to check if dungeon is closed
30
- */
31
- constructor(name_, loot, openAction, closeAction, openCost, openImage, closedImage) {
32
- this.name_ = name_;
33
- this.loot = loot;
34
- this.openAction = openAction;
35
- this.closeAction = closeAction;
36
- this.openCost = openCost;
37
- this.openImage = openImage;
38
- this.closedImage = closedImage;
39
- }
40
- distribute(idOrname_, loot = this.loot, distributeAllOfAGivenItem = !(loot instanceof Map)) {
41
- const player = getPlayerFromIdOrName(idOrname_);
42
- const lootList = loot instanceof Map
43
- ? countedMapToArray(loot)
44
- : Array.isArray(loot)
45
- ? loot
46
- : [loot];
47
- const badLoot = lootList.find((lootItem) => !this.loot.includes(lootItem));
48
- if (badLoot) {
49
- throw new Error(`${badLoot} is not a valid piece of dungeon loot`);
50
- }
51
- const pageText = visitUrl("clan_basement.php");
52
- if (!pageText.match(new RegExp(player.name, "i"))) {
53
- throw new Error(`${player.name} cannot be distributed loot from ${getClanName()}`);
54
- }
55
- const itemname_s = xpath(pageText, "//tr/td[2]/b/text()");
56
- const whichLoots = xpath(pageText, '//form[@action="clan_basement.php"]//input[@type="hidden"][@name_="whichloot"]/@value');
57
- itemname_s.forEach((itemname_, index) => {
58
- if (lootList.includes(toItem(itemname_))) {
59
- visitUrl(`clan_basement.php?whichloot=${whichLoots[index]}&recipient=${player.id}`);
60
- if (!distributeAllOfAGivenItem)
61
- lootList.splice(lootList.indexOf(toItem(itemname_)));
62
- }
63
- });
64
- }
65
- /**
66
- * Close this dungeon
67
- *
68
- * @returns Whether the dungeon is now closed
69
- */
70
- close() {
71
- visitUrl(`clan_basement.php?action=${this.closeAction}&confirm=true`, true);
72
- const pageText = visitUrl("clan_basement.php");
73
- return pageText.includes(this.closedImage);
74
- }
75
- /**
76
- * Open an instance of this dungeon
77
- *
78
- * @param paymentPolicy How much meat should we put into the clan stash to open this dungeon?
79
- * @returns Whether the dungeon is now open
80
- */
81
- open(paymentPolicy = "Difference") {
82
- const pageText = visitUrl("clan_basement.php");
83
- if (pageText.includes(this.openImage))
84
- return true;
85
- const clan = Clan.get();
86
- if (paymentPolicy === "All") {
87
- clan.putMeatInCoffer(this.openCost);
88
- }
89
- else {
90
- const stashMeat = clan.getMeatInCoffer();
91
- const payDifference = this.openCost - stashMeat;
92
- if (payDifference > 0) {
93
- if (paymentPolicy === "None")
94
- return false;
95
- clan.putMeatInCoffer(payDifference);
96
- }
97
- }
98
- visitUrl(`clan_basement.php?action=${this.openAction}`, true);
99
- return visitUrl("clan_basement.php").includes(this.openImage);
100
- }
101
- /**
102
- * @returns A counted map of all loot from this dungeon eligible for distribution
103
- */
104
- findLoot() {
105
- const result = new Map();
106
- const pageText = visitUrl("clan_basement.php");
107
- for (const lootItem of this.loot) {
108
- result.set(lootItem, pageText.match(new RegExp(lootItem.name, "g"))?.length ?? 0);
109
- }
110
- return result;
111
- }
112
- }
113
- export const Dreadsylvania = new Dungeon("Dreadsylvania", $items `Great Wolf's headband, Great Wolf's right paw, Great Wolf's left paw, Great Wolf's lice, Great Wolf's rocket launcher, Great Wolf's beastly trousers, Drapes-You-Regally, Warms-Your-Tush, Covers-Your-Head, Protects-Your-Junk, Quiets-Your-Steps, Helps-You-Sleep, Mayor Ghost's khakis, Mayor Ghost's cloak, Mayor Ghost's toupee, Mayor Ghost's scissors, Mayor Ghost's sash, Mayor Ghost's gavel, zombie mariachi hat, zombie accordion, zombie mariachi pants, HOA regulation book, HOA zombie eyes, HOA citation pad, Unkillable Skeleton's skullcap, Unkillable Skeleton's shinguards, Unkillable Skeleton's breastplate, Unkillable Skeleton's shield, Unkillable Skeleton's sawsword, Unkillable Skeleton's restless leg, skull capacitor, Thunkula's drinking cap, Drunkula's silky pants, Drunkula's cape, Drunkula's ring of haze, Drunkula's wineglass, Drunkula's bell, bottle of Bloodweiser, bottle of Bloodweiser, bottle of Bloodweiser, bottle of Bloodweiser, electric Kool-Aid, electric Kool-Aid, electric Kool-Aid, electric Kool-Aid, ghost pepper, ghost pepper, ghost pepper, ghost pepper, Gets-You-Drunk, Gets-You-Drunk, Gets-You-Drunk, Gets-You-Drunk, wriggling severed nose, wriggling severed nose, wriggling severed nose, wriggling severed nose, Hunger™ Sauce, Hunger™ Sauce, Hunger™ Sauce, Hunger™ Sauce`, "translatemap", "foldmap", 1000000, "dvmap.gif", "foldmap.gif");
114
- export const Hobopolis = new Dungeon("Hobopolis", $items `Ol' Scratch's ash can, Ol' Scratch's ol' britches, Ol' Scratch's stovepipe hat, Ol' Scratch's infernal pitchfork, Ol' Scratch's manacles, Ol' Scratch's stove door, Frosty's carrot, Frosty's nailbat, Frosty's old silk hat, Frosty's arm, Frosty's iceball, Frosty's snowball sack, Oscus's dumpster waders, Oscus's pelt, Wand of Oscus, Oscus's flypaper pants, Oscus's garbage can lid, Oscus's neverending soda, Zombo's grievous greaves, Zombo's shield, Zombo's skullcap, Zombo's empty eye, Zombo's shoulder blade, Zombo's skull ring, Chester's bag of candy, Chester's cutoffs, Chester's moustache, Chester's Aquarius medallion, Chester's muscle shirt, Chester's sunglasses, Hodgman's bow tie, Hodgman's porkpie hat, Hodgman's lobsterskin pants, Hodgman's almanac, Hodgman's lucky sock, Hodgman's metal detector, Hodgman's varcolac paw, Hodgman's harmonica, Hodgman's garbage sticker, Hodgman's cane, Hodgman's whackin' stick, Hodgman's disgusting technicolor overcoat, Hodgman's imaginary hamster`, "cleansewer", "floodsewer", 1000000, "opengrate.gif", "sewergrate.gif");
115
- export const SlimeTube = new Dungeon("The Slime Tube", $items `slime-soaked brain, slime-soaked hypophysis, slime-soaked sweat gland, squirming Slime larva, caustic slime nodule, caustic slime nodule, hardened slime belt, hardened slime hat, hardened slime pants`, "cleanspot", "sealtube", 250000, "slimehole.gif", "greasespot.gif");