An implementation of an e621 watch bot as an excuse to learn BEAM programming
Find a file
2025-11-09 16:03:20 -07:00
src (feat): Configure root level supervisor 2025-11-09 16:03:20 -07:00
test (feat): Add ability to delete tag groups 2025-11-09 15:37:43 -07:00
.gitignore (feat): Telegram bot command handling 2025-11-09 15:37:58 -07:00
gleam.toml (feat): Telegram bot command handling 2025-11-09 15:37:58 -07:00
manifest.toml (feat): Telegram bot command handling 2025-11-09 15:37:58 -07:00
README.md (feat): Telegram bot command handling 2025-11-09 15:37:58 -07:00

stag_net

This is a project to listen to an image repository for new posts. A post is a file that consists of a list of tags applied to it. This application allows users to register tag_groups which are either a Watch group or a Block group. Images which match a user's Watch group and do not match a Block group are sent to the user.

Notification Architecture

Note: this is not the most efficient way to do this. I just want to play with the OTP model

  • A root level notification engine
  • A user notification engine per user
  • A tag_group notification engine per user's tag groups

root notification has many children, user notification has many children, tag_group has no children

Post received from image API -> root notification engine -> user 1 -> tag_group 1
                                                                   -> tag_group 2
                                                         -> user 2 -> tag_group 3
                                                                   -> tag_group 4

tag_group Noticification Engine

State:

  • a set of tags that are the members of a given tag_group

Subjects:

  • (in) receives a set of tags which represent a post
  • (out) emits a boolean of whether or not a post's tags are a superset of the tag_group

user Notification Engine

State:

  • The associated user
  • Subject registry for all child tag_group notification
  • Subject to emit telegram notifications via if post matches rules

Subjects:

  • (in) receives a Post from the image repository API
  • (in) receives booleans from tag_group notifications
  • (out) emits a PostNotification object to the telegram notifaction actor

root Notification Engine

The root notification engine manages a dynamic set of actors. New user actors are created when new users register with the application. user actors are removed when the user deactivates the application

State:

  • A map of user.id -> user notification subject

Subjects:

  • (in) receives a Post from the image repository API
  • (in) receives application events to start or stop user agents

Development

gleam run   # Run the project
gleam test  # Run the tests

Environment Variables

The project has several required environment variables:

  • TG_BOT_TOKEN -> The API token from telegram for the bot account
  • TG_BOT_SECRET_TOKEN -> A randomly generated secret to prevent request spoofing
  • WEBHOOK_PATH -> The "endpoint" path that TG will send webhook events to
  • SERVER_URL -> The domain that TG will send webhook events to

There are also optional environment variables:

  • DATABASE_PATH -> The path to the SQLite database. If not set, then the default path will be used