Skip to content

Commit

Permalink
The purge again (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinn committed Jun 1, 2024
1 parent 42f08c9 commit 0781e4e
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions packages/excavator-script/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
inMultiFight,
print,
printHtml,
visitUrl,
} from "kolmafia";
import { get, Kmail, set } from "libram";

Expand Down Expand Up @@ -111,6 +112,7 @@ export function sendSpadingData(projectName: string, data: object) {

if (success) {
flushSpadingData();
deleteSpadingKmail(recipient);
return;
}

Expand All @@ -126,3 +128,27 @@ export function sendSpadingData(projectName: string, data: object) {
`Excavator's project to spade ${projectName}`,
);
}

function deleteSpadingKmail(sentTo: string): void {
// Only delete from the first page
const buffer = visitUrl(
`messages.php?box=Outbox&begin=1&per_page=10`,
).toLowerCase();
const messageIds: string[] = buffer
.split("td valign=top")
.filter((s) =>
s.match(
`<a href="showplayer.php\\?who=(\\d+)">${sentTo.toLowerCase()}</a>`,
),
)
.map((s) => {
const match = s.match('checkbox name="sel(\\d+)"');
return match ? match[1] : "";
})
.filter((s) => s.length > 0);

if (messageIds.length > 0) {
const del = `messages.php?the_action=delete&box=Outbox&pwd${messageIds.map((id) => `&sel${id}=on`).join("")}`;
visitUrl(del);
}
}

0 comments on commit 0781e4e

Please sign in to comment.