Something went wrong. Try again.
A streaming bot for Streamplace forked from bot.timtinkers.online/streamplace-bot
Something went wrong. Try again.
streamplace-bot main.ts
2.3 kB · 68 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869import { App, staticFiles } from "fresh";import { type State } from "./utils.ts";import { isHandle } from "@atcute/lexicons/syntax";import { AtprotoClient, getDidDocument, resolveHandle,} from "./utils/atcuteUtils.ts";import { filterByStreamplace, getBacklinks,} from "./utils/constellationUtils.ts";import StreamplaceBot from "./utils/streamplaceBot.ts";import { streamplaceWS } from "./utils/websocket.ts";import { BOT_CREDENTIALS, BOT_SERVICE, FOLLOWER_MODE } from "./env.ts";import { ResourceUri } from "@atcute/lexicons";import { OnlineTimtinkersBotVariable } from "./utils/lexicons/index.ts";
export const app = new App<State>();
export const botInstances: Map<Did, StreamplaceBot> = new Map();export const followerAtUris: Map<Did, string> = new Map();export const customVariablesAtUris: Map< ResourceUri, OnlineTimtinkersBotVariable.Main> = new Map();
// Logging unhandled rejections and uncaught errorsglobalThis.addEventListener("unhandledrejection", (event) => { console.error("Unhandled rejection — this may crash the server:"); console.error(event.reason);});globalThis.addEventListener("error", (event) => { console.error("Uncaught error:", event.message, event.error);});
// Initialize for selfexport const atprotoClient = new AtprotoClient(BOT_CREDENTIALS, BOT_SERVICE);const botDid = isHandle(BOT_CREDENTIALS.identifier) ? await resolveHandle(BOT_CREDENTIALS.identifier) : BOT_CREDENTIALS.identifier;const botDocument = await getDidDocument(botDid);const streamplaceBot = new StreamplaceBot(botDocument);streamplaceBot.init();botInstances.set(botDid, streamplaceBot);
if (FOLLOWER_MODE) { // Get bot followers const backlinks = await getBacklinks( botDid, "app.bsky.graph.follow", ".subject", 100, // I should fetch all of them, but I also don't know if I can handle that many ); const filteredBacklinks = await filterByStreamplace(backlinks); for (const backlink of filteredBacklinks) { const streamerDocument = await getDidDocument(backlink.did); const streamplaceBot = new StreamplaceBot(streamerDocument); streamplaceBot.init(); botInstances.set(backlink.did, streamplaceBot); followerAtUris.set(backlink.did, backlink.atUri); }}streamplaceWS.start();app.use(staticFiles());
// Include file-system based routes hereapp.fsRoutes();