Skip to content

Commit

Permalink
Report greenbox errors, make them only happen once if they do error
Browse files Browse the repository at this point in the history
  • Loading branch information
gausie committed Jul 26, 2024
1 parent e928bd3 commit a990e61
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/oaf/src/greenbox.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import { type KoLMessage } from "kol.js";

import { isRecordNotFoundError, prisma } from "./clients/database.js";
import { discordClient } from "./clients/discord.js";
import { kolClient } from "./clients/kol.js";

export async function handleGreenboxKmail(message: KoLMessage) {
if (message.type !== "kmail") return;

// Remove spaces - KoL adds weird spaces to long messages.
const text = message.msg.replace(/ /g, "").slice(9);

if (text === "WIPE") return await wipe(message.who.id);
switch (text) {
case "WIPE":
await wipe(message.who.id);
break;
default:
await update(message.who.id, message.who.name, text);
break;
}

// If we don't recognise a command, this is a submission
return await update(message.who.id, message.who.name, text);
await kolClient.deleteKmails([message.id]);
}

async function update(
Expand All @@ -37,6 +46,11 @@ async function update(
});
}
} catch (error) {
await discordClient.alert(
"Error processing greenbox submission",
undefined,
error,
);
await kolClient.kmail(
playerId,
"There was an error processing your greenbox submission",
Expand All @@ -56,6 +70,11 @@ async function wipe(playerId: number) {
});
} catch (error) {
if (!isRecordNotFoundError(error)) {
await discordClient.alert(
"Error processing greenbox submission",
undefined,
error,
);
return await kolClient.kmail(
playerId,
"There was an error wiping your public greenbox profile",
Expand Down

0 comments on commit a990e61

Please sign in to comment.