diff --git a/ebs/src/modules/transactions.ts b/ebs/src/modules/transactions.ts index 70dc367..153baae 100644 --- a/ebs/src/modules/transactions.ts +++ b/ebs/src/modules/transactions.ts @@ -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", @@ -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) { diff --git a/ebs/src/util/pishock.ts b/ebs/src/util/pishock.ts index 20d509b..0cf00b8 100644 --- a/ebs/src/util/pishock.ts +++ b/ebs/src/util/pishock.ts @@ -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); }