···11-#I'm hoping this is the parent?
22-[lavel-watcher.settings]
33-pds=['selfhosted.social']
11+[label-watcher.settings]
22+#PDSs to watch
33+pds = ['selfhosted.social']
4455-#I'm hoping this is another parent?
55+# Define the labeler
66[labeler.skywatch]
77-host="ozone.skywatch.blue"
77+host = "ozone.skywatch.blue"
88+99+# Can have multiple labels
1010+[labeler.skywatch.labels.test-label]
1111+label_name = "test-label"
1212+action = "notify"
1313+1414+1515+[labeler.bsky]
1616+host = "mod.bsky.app"
81799-# I'm hoping there will be multiple ones
1010-[labeler.skywatch.test-label]
1111-label_name="test-label"
1212-action="notify"
1818+# Can have multiple labels
1919+[labeler.bsky.labels.porn]
2020+label_name = "porn"
2121+action = "takedown"
+21
settings.toml.example
···11+[label-watcher.settings]
22+#PDSs to watch
33+pds = ['selfhosted.social']
44+55+# Define the labeler
66+[labeler.skywatch]
77+host = "ozone.skywatch.blue"
88+99+# Can have multiple labels
1010+[labeler.skywatch.labels.test-label]
1111+label_name = "test-label"
1212+action = "notify"
1313+1414+1515+[labeler.bsky]
1616+host = "mod.bsky.app"
1717+1818+# Can have multiple labels
1919+[labeler.bsky.labels.test-two]
2020+label_name = "test-two"
2121+action = "takedown"
+27-10
src/index.ts
···22import { ComAtprotoLabelSubscribeLabels } from "@atcute/atproto";
33import { db } from "./db/index.js";
44import { migrate } from "drizzle-orm/libsql/migrator";
55+import { readFileSync } from "node:fs";
66+import { parse } from "smol-toml";
77+import type { LabelerConfig, Settings } from "./types/settings.js";
5869// TODO
710// 1. Figure out a schema for settings we want. PDSs to watch.Labelers and their Labels
811// and which actions to do for them (notification/email) or auto takedown. thinking toml file maybe?
912// 2. Add a CLI argument to backfill PDS repos on start up. If finds a new active repo adds it
1010-// 3. Add a firehose listner that subsribes to the PDSs for new identies? (I say maybe not cause of bandwidth)
1313+// 3. Add a firehose listener that subscribes to the PDSs for new identities? (I say maybe not cause of bandwidth)
1414+// 4. We can save the last sen sequence from the labler to the db and restore it on startup for backfill
11151212-// Run Drizzle migrations on startup
1616+// Run Drizzle migrations on startup
1317migrate(db, { migrationsFolder: process.env.MIGRATIONS_FOLDER ?? "drizzle" });
14181515-const listner = async (id: string, wss: string) => {
1919+const settingsFile = readFileSync("./settings.toml", "utf-8");
2020+2121+//TODO I really really don't like this unknown to settings. Figure that out later
2222+const settings = parse(settingsFile) as unknown as Settings;
2323+2424+const labelers = settings.labeler;
2525+2626+const labelerSubscriber = async (config: LabelerConfig) => {
1627 const subscription = new FirehoseSubscription({
1717- service: wss,
2828+ service: `wss://${config.host}`,
1829 nsid: ComAtprotoLabelSubscribeLabels.mainSchema,
1930 });
20312121- console.log(`Listening to ${id}`);
3232+ console.log(`Listening to ${config.host}`);
2233 for await (const message of subscription) {
2334 switch (message.$type) {
2435 case "com.atproto.label.subscribeLabels#info": {
···2839 case "com.atproto.label.subscribeLabels#labels": {
2940 // repository commit (record creates, updates, deletes)
3041 for (const label of message.labels) {
3131- console.log(`From: ${id}`);
4242+ console.log(`From: ${config.host}`);
4343+4444+ if (config.labels[label.val]) {
4545+ console.log(
4646+ `Listed label found. Performing the action: ${config.labels[label.val]?.action}`,
4747+ );
4848+ console.log("\n");
4949+ }
3250 console.log("Label from: ", label.src);
3351 console.log("Label: ", label.val);
3452 console.log("Label for: ", label.uri);
···4058 }
4159};
42604343-Promise.all([
4444- listner("skywatch", "wss://ozone.skywatch.blue"),
4545- listner("bsky", "wss://mod.bsky.app"),
4646-]);
6161+Promise.all(
6262+ Object.entries(labelers).map(([_, config]) => labelerSubscriber(config)),
6363+);