Skip to content

Commit

Permalink
feat: rebrand package to proto_rune
Browse files Browse the repository at this point in the history
  • Loading branch information
zoedsoupe committed Sep 15, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent b644b9f commit 1fcf3cc
Showing 23 changed files with 156 additions and 88 deletions.
87 changes: 79 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,92 @@
# Atproto
# ProtoRune

**TODO: Add description**
**ProtoRune** is an Elixir framework and client library for building applications on top of the ATProtocol, including **Bluesky** integration. Whether you're developing **bots**, **labelers**, **moderators**, or custom **app views**, ProtoRune provides a flexible and powerful way to interact with the protocol using Elixir.

## Features

- **XRPC Client**: Interact with ATProto services through a simple, extensible XRPC client.
- **Schema Generation**: Automatically generate schemas from ATProto `defs.json` files.
- **Bots & Labelers**: Create bots for content moderation, automated interactions, and more.
- **Moderation Tools**: Build labelers and moderation tools integrated with ATProto's labeling system.
- **Flexible Framework**: Use ProtoRune to build custom ATProto applications, including custom feeds, notifications, and more.

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `atproto` to your list of dependencies in `mix.exs`:
Add ProtoRune to your `mix.exs`:

```elixir
def deps do
[
{:atproto, "~> 0.1.0"}
{:proto_rune, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/atproto>.
Run `mix deps.get` to install it.

## Getting Started

### 1. Setting Up a Simple Query

```elixir
defmodule MyApp.ProfileFetcher do
alias ProtoRune.Session
alias ProtoRune.Bsky.Actor.Defs.Profile

@spec get_profile(Session.t, actor: String.t) :: {:ok, Profile.t} | {:error, term}
def get_profile(%Session{} = session, actor: actor) do
ProtoRune.Bsky.Actor.get_profile(session, actor: actor)
end
end
```

### 2. Creating a Bot

```elixir
defmodule MyBot do
use ProtoRune.Bot

@impl true
def handle_message(%{text: "Hello"}) do
"Hi there!"
end
end
```

### 3. Building Moderation Tools

```elixir
defmodule MyModerator do
use ProtoRune.Moderator

def label_inappropriate_content(content) do
# Custom logic to label content
ProtoRune.Label.apply_label(content, :inappropriate)
end
end
```

## Dynamic Schema Generation

ProtoRune includes tools for dynamically generating Elixir modules for ATProto schemas:

1. **Generate Schemas from defs.json**
- Use the built-in Mix task to generate Elixir structs and typespecs for the schemas defined in the `defs.json` file.
```bash
mix proto_rune.gen.schemas
```

2. **Customizable Structs and Typespecs**
- ProtoRune generates user-friendly typespecs for all query and procedure parameters, ensuring type safety and ease of use.

## Contributing

1. Fork the repository.
2. Create your feature branch (`git checkout -b feature/my-feature`).
3. Commit your changes (`git commit -am 'Add new feature'`).
4. Push to the branch (`git push origin feature/my-feature`).
5. Create a new pull request.

## License

ProtoRune is licensed under the MIT License.
20 changes: 0 additions & 20 deletions lib/atproto/application.ex

This file was deleted.

15 changes: 15 additions & 0 deletions lib/proto_rune/application.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ProtoRune.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false

use Application

@impl true
def start(_type, _args) do
children = []

opts = [strategy: :one_for_one, name: ProtoRune.Supervisor]
Supervisor.start_link(children, opts)
end
end
4 changes: 2 additions & 2 deletions lib/atproto/admin.ex → lib/proto_rune/atproto/admin.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Atproto.Admin do
defmodule ProtoRune.Atproto.Admin do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Delete a user account as an administrator.
4 changes: 2 additions & 2 deletions lib/atproto/server.ex → lib/proto_rune/atproto/server.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Atproto.Server do
defmodule ProtoRune.Atproto.Server do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Activates a currently deactivated account. Used to finalize account migration after the account's repo is imported and identity is setup.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Atproto.Session do
defmodule ProtoRune.Atproto.Session do
@moduledoc false

@t %{
4 changes: 2 additions & 2 deletions lib/bsky/actor.ex → lib/proto_rune/bsky/actor.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Actor do
defmodule ProtoRune.Bsky.Actor do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Get private preferences attached to the current account. Expected use is synchronization between multiple devices, and import/export during account migration. Requires auth.
4 changes: 2 additions & 2 deletions lib/bsky/chat/actor.ex → lib/proto_rune/bsky/chat/actor.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Chat.Actor do
defmodule ProtoRune.Bsky.Chat.Actor do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
https://docs.bsky.app/docs/api/chat-bsky-actor-delete-account
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Chat.Moderation do
defmodule ProtoRune.Bsky.Chat.Moderation do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
https://docs.bsky.app/docs/api/chat-bsky-moderation-get-actor-metadata
4 changes: 2 additions & 2 deletions lib/bsky/feed.ex → lib/proto_rune/bsky/feed.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Feed do
defmodule ProtoRune.Bsky.Feed do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Get information about a feed generator, including policies and offered feed URIs. Does not require auth; implemented by Feed Generator services (not App View).
4 changes: 2 additions & 2 deletions lib/bsky/graph.ex → lib/proto_rune/bsky/graph.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Graph do
defmodule ProtoRune.Bsky.Graph do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Get a list of starter packs created by the actor.
4 changes: 2 additions & 2 deletions lib/bsky/labeler.ex → lib/proto_rune/bsky/labeler.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Labeler do
defmodule ProtoRune.Bsky.Labeler do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Get information about a list of labeler services.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Notification do
defmodule ProtoRune.Bsky.Notification do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Count the number of unread notifications for the requesting account. Requires auth.
2 changes: 1 addition & 1 deletion lib/bsky/profile.ex → lib/proto_rune/bsky/profile.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule Bsky.Profile do
defmodule ProtoRune.Bsky.Profile do
@moduledoc false

defstruct [:handle, :did]
4 changes: 2 additions & 2 deletions lib/bsky/video.ex → lib/proto_rune/bsky/video.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bsky.Video do
defmodule ProtoRune.Bsky.Video do
@moduledoc false

import XRPC.DSL
import ProtoRune.XRPC.DSL

@doc """
Get status details for a video processing job.
2 changes: 1 addition & 1 deletion lib/xrpc/case.ex → lib/proto_rune/xrpc/case.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule XRPC.Case do
defmodule ProtoRune.XRPC.Case do
@moduledoc """
Yeah, in house string casing
"""
12 changes: 6 additions & 6 deletions lib/xrpc/client.ex → lib/proto_rune/xrpc/client.ex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule XRPC.Client do
defmodule ProtoRune.XRPC.Client do
@moduledoc """
The `XRPC.Client` module handles executing queries and procedures in the XRPC system. It interacts with external services through HTTP requests and performs response validation and schema parsing. The client supports both GET and POST requests, depending on whether the request is a query or a procedure.
@@ -19,8 +19,8 @@ defmodule XRPC.Client do
- For **procedures**, it performs a `POST` request and validates the request body.
"""

alias XRPC.Procedure
alias XRPC.Query
alias ProtoRune.XRPC.Procedure
alias ProtoRune.XRPC.Query

def execute(%Query{} = query) do
with {:ok, _} <- Peri.validate(query.parser, query.params) do
@@ -34,7 +34,7 @@ defmodule XRPC.Client do

def execute(%Procedure{} = proc) do
with {:ok, body} <- Peri.validate(proc.parser, proc.body) do
body = apply_case_map(body, &XRPC.Case.camelize/1)
body = apply_case_map(body, &ProtoRune.XRPC.Case.camelize/1)

proc
|> to_string()
@@ -49,12 +49,12 @@ defmodule XRPC.Client do
defp parse_http({:ok, %{status: 404}}), do: {:error, :not_found}

defp parse_http({:ok, %{status: 400, body: error}}) do
{:error, apply_case_map(error, &XRPC.Case.snakelize/1)}
{:error, apply_case_map(error, &ProtoRune.XRPC.Case.snakelize/1)}
end

defp parse_http({:ok, %{status: status, body: body}})
when status in [200, 201] do
{:ok, apply_case_map(body, &XRPC.Case.snakelize/1)}
{:ok, apply_case_map(body, &ProtoRune.XRPC.Case.snakelize/1)}
end

defp parse_schema({:error, _err} = err, _), do: err
6 changes: 3 additions & 3 deletions lib/xrpc/config.ex → lib/proto_rune/xrpc/config.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
defmodule XRPC.Config do
defmodule ProtoRune.XRPC.Config do
@moduledoc false

def get(key) when is_atom(key) do
env = Application.get_env(:atproto, :env, :dev)
env = Application.get_env(:proto_rune, :env, :dev)

xrpc_config(env, key)
end
@@ -16,6 +16,6 @@ defmodule XRPC.Config do
end

defp xrpc_config(:prod, key) do
Application.get_env(:atproto, key)
Application.get_env(:proto_rune, key)
end
end
Loading

0 comments on commit 1fcf3cc

Please sign in to comment.