Skip to content

Commit

Permalink
Revert "Delete excavator kmails (#77)" (#79)
Browse files Browse the repository at this point in the history
This reverts commit 27614a4.
  • Loading branch information
gausie committed Jun 1, 2024
1 parent 27614a4 commit 42f08c9
Showing 1 changed file with 0 additions and 44 deletions.
44 changes: 0 additions & 44 deletions packages/excavator-script/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ import {
inMultiFight,
print,
printHtml,
sessionStorage,
todayToString,
visitUrl,
} from "kolmafia";
import { get, Kmail, set } from "libram";

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

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

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

function deleteSpadingKmail(sentTo: string): void {
// Check all Outbox pages once a day, then only the first page
const maxPage =
(sessionStorage.getItem("LastOutboxPurge") ?? "") !== todayToString()
? Infinity
: 1;

let currentPage = 1;
while (currentPage <= maxPage) {
const buffer = visitUrl(
`messages.php?box=Outbox&begin=${currentPage}&per_page=10`,
).toLowerCase();
if (!buffer.includes("toid")) break;
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) {
currentPage += 1;
continue;
}

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

if (maxPage === Infinity) {
sessionStorage.setItem("LastOutboxPurge", todayToString());
}
}

0 comments on commit 42f08c9

Please sign in to comment.