For those who call Bluesky "BlueSky"
1import { AppBskyFeedPost } from "@atcute/bluesky";
2import { JetstreamSubscription } from "@atcute/jetstream";
3import { is } from "@atcute/lexicons";
4import { LabelerServer } from "@skyware/labeler";
5
6const server = new LabelerServer({
7 did: process.env.LABELER_DID,
8 signingKey: process.env.SIGNING_KEY,
9});
10
11server.start(14831, (error) => {
12 if (error) {
13 console.error("Failed to start server:", error);
14 } else {
15 console.log("Labeler server running on port 14831");
16 }
17});
18
19const subscription = new JetstreamSubscription({
20 url: "wss://jetstream2.us-east.bsky.network",
21 wantedCollections: ["app.bsky.feed.post"],
22});
23
24for await (const event of subscription) {
25 if (event.kind === "commit") {
26 const commit = event.commit;
27
28 if (commit.collection !== "app.bsky.feed.post") {
29 continue;
30 }
31
32 if (commit.operation === "create") {
33 const record = commit.record;
34 if (!is(AppBskyFeedPost.mainSchema, record)) {
35 continue;
36 }
37
38 try {
39 if (record.text.includes("BlueSky")) {
40 console.log("Labeling: ", JSON.stringify(event.commit));
41 await server.createLabel({
42 uri: event.did,
43 val: "blue-sky",
44 });
45 }
46 } catch (e) {
47 console.error(
48 `Error occured on record ${commit.cid}: `,
49 (e as Error).toString(),
50 );
51 }
52 }
53 }
54}