Skip to content

Commit

Permalink
chore: remove updateChatStatus cloud function (#865)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevmo314 committed Jan 4, 2023
1 parent 7bb4110 commit e53ff5b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 55 deletions.
49 changes: 0 additions & 49 deletions functions/src/chat-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,6 @@ import fetch from "cross-fetch";
import { getAppAccessToken, TWITCH_CLIENT_ID } from "./oauth";
import { AccessToken } from "simple-oauth2";

async function getTwitchUserId(channel: string) {
// fetch the twitch user id from the database based on login.
const doc = await admin
.firestore()
.collection("profiles")
.where("twitch.login", "==", channel)
.limit(1)
.get();
if (doc.empty) {
return null;
}
return doc.docs[0].data()["twitch"]["id"];
}

export const updateChatStatus = functions.pubsub
.schedule("* * * * *") // every 1 minute
.onRun(async () => {
const promises: Promise<any>[] = [];
// fetch the active connections from realtime database
const connections =
(await admin.database().ref("connections").once("value")).val() || {};
for (const [provider, channels] of Object.entries(connections)) {
for (const channel of Object.keys(channels as any)) {
switch (provider) {
case "twitch":
const promise = fetch(
`https://tmi.twitch.tv/group/user/${channel}/chatters`
)
.then((res) => res.json() as any)
.then(async (json) => {
return admin
.firestore()
.collection("chat-status")
.add({
provider,
channel,
channelId: `twitch:${await getTwitchUserId(channel)}`,
...json["chatters"],
createdAt: admin.firestore.FieldValue.serverTimestamp(),
});
});
promises.push(promise);
}
}
}

await Promise.all(promises);
});

async function twitchLoginsToUserIds(token: AccessToken, logins: string[]) {
const twitchChannelIds: string[] = [];
for (let i = 0; i < logins.length; i += 100) {
Expand Down
7 changes: 1 addition & 6 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@ import { search } from "./search";
import { subscribe, unsubscribe } from "./subscriptions";
import { synthesize, getVoices } from "./tts";
import { getTwitchLogin, getChannelId } from "./twitch";
import {
updateChatStatus,
getViewerList,
updateFollowerAndViewerCount,
} from "./chat-status";
import { getViewerList, updateFollowerAndViewerCount } from "./chat-status";
import {
setRealTimeCashAddress,
alchemyWebhook,
Expand Down Expand Up @@ -450,7 +446,6 @@ export {
getEmotes,
synthesize,
getVoices,
updateChatStatus,
getViewerList,
setRealTimeCashAddress,
alchemyWebhook,
Expand Down

0 comments on commit e53ff5b

Please sign in to comment.