Skip to content

Commit

Permalink
start working on ebs-side redeems
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexejhero committed Jun 15, 2024
1 parent 5fe02e6 commit d68b480
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ebs/src/modules/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ app.post(
};
}
try {
// TODO: special handling for different types of redeems

const resMsg = await connection.redeem(redeem, cart, userInfo, transaction.token);
if (resMsg?.success) {
console.log(`[${resMsg.guid}] Redeem succeeded: ${JSON.stringify(resMsg)}`);
Expand All @@ -230,7 +232,7 @@ app.post(
logContext.important = false;
logMessage.header = "Redeem did not succeed";
logMessage.content = resMsg;
sendToLogger(logContext);
sendToLogger(logContext).then();
res.status(500).send(resMsg?.message ?? "Redeem failed");
}
} catch (error) {
Expand Down
38 changes: 38 additions & 0 deletions ebs/src/util/pishock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const apiUrl: string = "https://do.pishock.com/api/apioperate/";

async function sendOperation(op: number, intensity: number, duration: number) {
try {
const data = {
Username: process.env.PISHOCK_USERNAME,
Apikey: process.env.PISHOCK_APIKEY,
Code: process.env.PISHOCK_CODE,
Name: "Swarm Control",

Op: op,
Intensity: intensity,
Duration: duration,
};

console.log(`Sending PiShock operation: ${op} ${intensity} ${duration}`);

const response = await fetch(apiUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});

if (!response.ok) {
console.error("Failed to send PiShock operation");
console.error(response.status, await response.text());
}
} catch (e: any) {
console.error("Failed to send PiShock operation");
console.error(e);
}
}

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

0 comments on commit d68b480

Please sign in to comment.