Skip to content

Commit

Permalink
feat: add raid api (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 authored Sep 16, 2023
1 parent 3c43b9d commit fe84ae6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
20 changes: 20 additions & 0 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,26 @@ export const clear = functions.https.onCall(async (data, context) => {
throw new functions.https.HttpsError("invalid-argument", "invalid provider");
});

export const raid = functions.https.onCall(async (data, context) => {
if (!context.auth) {
throw new functions.https.HttpsError("permission-denied", "missing auth");
}
const provider = data?.provider;
const fromChannelId = data?.fromChannelId;
const toChannelId = data?.toChannelId;
if (!provider || !fromChannelId || !toChannelId) {
throw new functions.https.HttpsError(
"invalid-argument",
"missing provider, fromChannelId, toChannelId"
);
}

switch (provider) {
case "twitch":
return await twitch.raid(context.auth.uid, fromChannelId, toChannelId);
}
});

export const getStatistics = functions.https.onCall(async (data, context) => {
const provider = data?.provider;
const channelId = data?.channelId;
Expand Down
20 changes: 20 additions & 0 deletions functions/src/twitch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,23 @@ export async function deleteMessage(
);
return await response.json();
}

export async function raid(
uid: string,
fromBroadcasterId: string,
toBroadcasterId: string
) {
const profile = await admin.firestore().collection("profiles").doc(uid).get();
if (!profile.exists) {
return;
}

const response = await fetch(
`https://api.twitch.tv/helix/raids?from_broadcaster_id=${fromBroadcasterId}&to_broadcaster_id=${toBroadcasterId}`,
{
method: "POST",
headers: await getHeaders(uid),
}
);
return await response.json();
}

0 comments on commit fe84ae6

Please sign in to comment.