Skip to content

Commit

Permalink
Don't send duplicate mumming trunk data (#73)
Browse files Browse the repository at this point in the history
* shouldDiscardData func

* don't send dupe mumming trunk data

* daily
  • Loading branch information
Rinn authored Apr 12, 2024
1 parent 319e4b2 commit 505c521
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
22 changes: 3 additions & 19 deletions packages/excavator-projects/projects/designerSweatpants.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import {
currentRound,
Item,
equippedItem,
Slot,
myLocation,
getProperty,
setProperty,
} from "kolmafia";
import { currentRound, Item, equippedItem, Slot, myLocation } from "kolmafia";

import { ExcavatorProject } from "../type";
import { toNormalisedString } from "../utils";
import { shouldDiscardData, toNormalisedString } from "../utils";

function spadeSweatpants(encounter: string, page: string) {
if (currentRound() !== 0) return null;
Expand All @@ -25,15 +17,7 @@ function spadeSweatpants(encounter: string, page: string) {
if (!sweat) return null;

const location = toNormalisedString(myLocation());
const reportedLocations = getProperty("excavatorSweatpantsLocations").split(
"|",
);
if (reportedLocations.includes(location)) return null;

setProperty(
"excavatorSweatpantsLocations",
[...reportedLocations, location].join("|"),
);
if (shouldDiscardData("_excavatorSweatpantsLocations", location)) return null;

return {
location,
Expand Down
4 changes: 3 additions & 1 deletion packages/excavator-projects/projects/mummingTrunk.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Item, availableAmount, getProperty, myFamiliar } from "kolmafia";

import { ExcavatorProject } from "../type";
import { notNull } from "../utils";
import { notNull, shouldDiscardData } from "../utils";

export const MUMMING_TRUNK: ExcavatorProject = {
name: "Mumming Trunk",
Expand Down Expand Up @@ -135,6 +135,8 @@ function spadeMummingTrunk(encounter: string, page: string) {
);

if (!match) return null;
if (shouldDiscardData("_excavatorMummingTrunk", `${fam.id}:${match[0]}`))
return null;

return {
attribute: match[0],
Expand Down
10 changes: 10 additions & 0 deletions packages/excavator-projects/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
canInteract,
Effect,
gamedayToInt,
getProperty,
haveEffect,
haveEquipped,
inHardcore,
Expand All @@ -15,6 +16,7 @@ import {
myLocation,
myPath,
Path,
setProperty,
} from "kolmafia";

const ALTERING_EFFECTS = Effect.get([
Expand Down Expand Up @@ -86,3 +88,11 @@ export function toNormalisedString(thing: Item | Monster | Location) {
export function notNull<T>(value: T | null): value is T {
return value !== null;
}

export function shouldDiscardData(property: string, data: string) {
const sentData = getProperty(property).split("|");
if (sentData.includes(data)) return true;

setProperty(property, [...sentData, data].join("|"));
return false;
}

0 comments on commit 505c521

Please sign in to comment.