Skip to content

Commit

Permalink
pishock integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero committed Jun 15, 2024
1 parent bdc89da commit 86711be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 10 additions & 1 deletion ebs/src/modules/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { connection } from "./game";
import { TwitchUser } from "./game/messages";
import { getHelixUser } from "../util/twitch";
import { asyncCatch } from "../util/middleware";
import { sendShock } from "../util/pishock";

app.post(
"/public/prepurchase",
Expand Down Expand Up @@ -216,7 +217,15 @@ app.post(
};
}
try {
// TODO: special handling for different types of redeems
if (redeem.id == "redeem_pishock") {
const success = await sendShock(50, 100);
if (success) {
res.status(200).send("Your transaction was successful!");
} else {
res.status(500).send("Redeem failed");
}
return;
}

const resMsg = await connection.redeem(redeem, cart, userInfo, transaction.token);
if (resMsg?.success) {
Expand Down
8 changes: 6 additions & 2 deletions ebs/src/util/pishock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ async function sendOperation(op: number, intensity: number, duration: number) {
if (!response.ok) {
console.error("Failed to send PiShock operation");
console.error(response.status, await response.text());
return false;
}

return true;
} catch (e: any) {
console.error("Failed to send PiShock operation");
console.error(e);
return false;
}
}

export async function sendShock(intensity: number, duration: number) {
await sendOperation(0, intensity, duration);
export function sendShock(intensity: number, duration: number) {
return sendOperation(0, intensity, duration);
}

0 comments on commit 86711be

Please sign in to comment.