roboherd 0.1.3__tar.gz → 0.1.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of roboherd might be problematic. Click here for more details.
- {roboherd-0.1.3 → roboherd-0.1.5}/.woodpecker/test.yml +16 -2
- {roboherd-0.1.3 → roboherd-0.1.5}/CHANGES.md +15 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/PKG-INFO +2 -1
- roboherd-0.1.5/docs/assets/bull-horns.png +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/index.md +28 -3
- {roboherd-0.1.3 → roboherd-0.1.5}/mkdocs.yml +2 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/pyproject.toml +3 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/resources/docker/Dockerfile +1 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/__main__.py +4 -2
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/annotations/__init__.py +22 -4
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/annotations/bovine.py +8 -8
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/annotations/common.py +3 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/__init__.py +51 -57
- roboherd-0.1.5/roboherd/cow/const.py +6 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/profile.py +19 -5
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/test_init.py +4 -3
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/test_profile.py +35 -3
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/types.py +17 -8
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/util.py +4 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/json_echo.py +1 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/moocow.py +4 -2
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/number.py +1 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/rooster.py +1 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/scarecrow.py +2 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/__init__.py +7 -7
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/manager/__init__.py +4 -2
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/manager/config.py +14 -7
- roboherd-0.1.5/roboherd/herd/manager/load.py +15 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/manager/test_config.py +18 -2
- roboherd-0.1.5/roboherd/herd/manager/test_load.py +19 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/manager/test_manager.py +1 -1
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/processor.py +2 -2
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/scheduler.py +1 -1
- roboherd-0.1.5/roboherd/test_validators.py +10 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/util.py +1 -51
- roboherd-0.1.5/roboherd/validators.py +6 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/uv.lock +189 -147
- roboherd-0.1.3/roboherd/test_util.py +0 -24
- {roboherd-0.1.3 → roboherd-0.1.5}/.gitignore +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/.woodpecker/create_release.yml +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/.woodpecker/publish_docker.yml +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/.woodpecker/publish_pypi.yml +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/.woodpecker/website.yml +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/README.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/annotations.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/assets/mastodon.png +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/cli.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/cow.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/herd.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/docs/util.md +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/resources/docker/build.sh +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/__init__.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/handlers.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/test_handlers.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/cow/test_util.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/__init__.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/dev_null.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/examples/meta.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/builder.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/test_herd.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/test_scheduler.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/herd/types.py +0 -0
- {roboherd-0.1.3 → roboherd-0.1.5}/roboherd/register.py +0 -0
|
@@ -2,21 +2,35 @@ when:
|
|
|
2
2
|
- branch: [main]
|
|
3
3
|
event: [pull_request, push]
|
|
4
4
|
|
|
5
|
+
matrix:
|
|
6
|
+
extras: ["--all-extras", ""]
|
|
7
|
+
|
|
5
8
|
steps:
|
|
6
9
|
build:
|
|
7
10
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
8
11
|
commands:
|
|
9
|
-
- uv sync
|
|
12
|
+
- uv sync ${extras}
|
|
10
13
|
test_format:
|
|
11
14
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
12
15
|
commands:
|
|
13
|
-
- uv run ruff format .
|
|
16
|
+
- uv run ruff format --check .
|
|
14
17
|
- uv run ruff check .
|
|
18
|
+
when:
|
|
19
|
+
- matrix: { extras: "--all-extras" }
|
|
15
20
|
test_pytest:
|
|
16
21
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
17
22
|
commands:
|
|
18
23
|
- uv run pytest
|
|
24
|
+
test_typing:
|
|
25
|
+
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
26
|
+
commands:
|
|
27
|
+
- apk add libstdc++ libgcc
|
|
28
|
+
- uv run pyright roboherd
|
|
29
|
+
when:
|
|
30
|
+
- matrix: { extras: "--all-extras" }
|
|
19
31
|
build_docs:
|
|
20
32
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
21
33
|
commands:
|
|
22
34
|
- uv run mkdocs build
|
|
35
|
+
when:
|
|
36
|
+
- matrix: { extras: "--all-extras" }
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changes to roboherd
|
|
2
2
|
|
|
3
|
+
## 0.1.5 ([Milestone](https://codeberg.org/bovine/roboherd/milestone/10581))
|
|
4
|
+
|
|
5
|
+
- Allow overriding the base_url [roboherd#12](https://codeberg.org/bovine/roboherd/issues/12)
|
|
6
|
+
- Separate out the internal state of a RoboCow
|
|
7
|
+
- If no preferredUsername is set and handle is updated, send Update Service [roboherd#33](https://codeberg.org/bovine/roboherd/issues/33)
|
|
8
|
+
- Add an icon property [roboherd#10](https://codeberg.org/bovine/roboherd/issues/10)
|
|
9
|
+
- Added a logo [roboherd#32](https://codeberg.org/bovine/roboherd/issues/32)
|
|
10
|
+
- Add PublishActivity annotation [roboherd#30](https://codeberg.org/bovine/roboherd/issues/30)
|
|
11
|
+
|
|
12
|
+
## 0.1.4 ([Milestone](https://codeberg.org/bovine/roboherd/milestone/10442))
|
|
13
|
+
|
|
14
|
+
- Type check the project
|
|
15
|
+
- No longer require bovine [roboherd#26](https://codeberg.org/bovine/roboherd/issues/26)
|
|
16
|
+
- Fixed typo in Dockerfile [roboherd#28](https://codeberg.org/bovine/roboherd/issues/28)
|
|
17
|
+
|
|
3
18
|
## 0.1.3 ([Milestone](https://codeberg.org/bovine/roboherd/milestone/10441))
|
|
4
19
|
|
|
5
20
|
- Add information about developement [roboherd#24](https://codeberg.org/bovine/roboherd/issues/24)
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: roboherd
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: A Fediverse bot framework
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: aiohttp>=3.11.12
|
|
6
7
|
Requires-Dist: almabtrieb[mqtt]>=0.1.0a1
|
|
7
8
|
Requires-Dist: apscheduler>=3.11.0
|
|
8
9
|
Requires-Dist: click>=8.1.8
|
|
Binary file
|
|
@@ -93,8 +93,23 @@ Setting me as the author and the source code is contained in [meta_information][
|
|
|
93
93
|
--8<-- "roboherd/examples/meta.py"
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
By setting to `icon` property of [roboherd.cow.types.Information][], one can
|
|
97
|
+
change the profile picture.
|
|
98
|
+
|
|
99
|
+
### Config overrides
|
|
100
|
+
|
|
101
|
+
By running
|
|
102
|
+
|
|
103
|
+
```toml title="roboherd.toml"
|
|
104
|
+
base_url = "https://dev.bovine.social"
|
|
105
|
+
|
|
106
|
+
[cow.devnull]
|
|
107
|
+
bot = "roboherd.examples.dev_null:bot"
|
|
108
|
+
handle = "nothingness"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
one would instead create a bot with the handle `acct:nothingness@dev.bovine.social`.
|
|
112
|
+
Similarly, one can override the name and the `base_url` to use.
|
|
98
113
|
|
|
99
114
|
### Posting on startup
|
|
100
115
|
|
|
@@ -103,7 +118,8 @@ By adding
|
|
|
103
118
|
```python
|
|
104
119
|
@bot.startup
|
|
105
120
|
async def startup(publish_object: PublishObject, object_factory: ObjectFactory):
|
|
106
|
-
|
|
121
|
+
note = object_factory.note(content="Booo! 🐦").as_public().build()
|
|
122
|
+
await publish_object(note)
|
|
107
123
|
```
|
|
108
124
|
|
|
109
125
|
one can post on startup. Here [PublishObject][roboherd.annotations.PublishObject]
|
|
@@ -119,6 +135,11 @@ ObjectFactory injects an [ObjectFactory][bovine.activitystreams.object_factory.O
|
|
|
119
135
|
--8<-- "roboherd/examples/scarecrow.py"
|
|
120
136
|
```
|
|
121
137
|
|
|
138
|
+
!!! hint
|
|
139
|
+
Similarly to PublishObject, one can use
|
|
140
|
+
[PublishActivity][roboherd.annotations.PublishActivity]
|
|
141
|
+
to post activities.
|
|
142
|
+
|
|
122
143
|
### Replying to messages
|
|
123
144
|
|
|
124
145
|
By adding a block such as
|
|
@@ -322,3 +343,7 @@ version, have a [milestone](https://codeberg.org/bovine/roboherd/milestones)
|
|
|
322
343
|
matching the new version, and appropriate entries in
|
|
323
344
|
`CHANGES.md`. Then once a pull request with this is merged,
|
|
324
345
|
the rest happens automatically.
|
|
346
|
+
|
|
347
|
+
## Acknowledgements
|
|
348
|
+
|
|
349
|
+
Logo via [Lorc](https://game-icons.net/1x1/lorc/bull-horns.html).
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "roboherd"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.5"
|
|
4
4
|
description = "A Fediverse bot framework"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.11"
|
|
7
7
|
dependencies = [
|
|
8
|
+
"aiohttp>=3.11.12",
|
|
8
9
|
"almabtrieb[mqtt]>=0.1.0a1",
|
|
9
10
|
"apscheduler>=3.11.0",
|
|
10
11
|
"click>=8.1.8",
|
|
@@ -37,6 +38,7 @@ dev-dependencies = [
|
|
|
37
38
|
"griffe-fieldz>=0.2.1",
|
|
38
39
|
"mkdocs-click>=0.8.1",
|
|
39
40
|
"ruff>=0.9.6",
|
|
41
|
+
"pyright>=1.1.394",
|
|
40
42
|
]
|
|
41
43
|
|
|
42
44
|
[tool.pytest.ini_options]
|
|
@@ -10,6 +10,7 @@ from roboherd.herd import RoboHerd
|
|
|
10
10
|
from roboherd.herd.manager import HerdManager
|
|
11
11
|
from roboherd.util import create_connection
|
|
12
12
|
from roboherd.register import register as run_register
|
|
13
|
+
from roboherd.validators import validators
|
|
13
14
|
|
|
14
15
|
logging.basicConfig(level=logging.INFO)
|
|
15
16
|
|
|
@@ -32,6 +33,7 @@ def main(ctx, connection_string, base_url, config_file):
|
|
|
32
33
|
settings = dynaconf.Dynaconf(
|
|
33
34
|
settings_files=[config_file],
|
|
34
35
|
envvar_prefix="ROBOHERD",
|
|
36
|
+
validators=validators,
|
|
35
37
|
)
|
|
36
38
|
ctx.ensure_object(dict)
|
|
37
39
|
|
|
@@ -41,12 +43,12 @@ def main(ctx, connection_string, base_url, config_file):
|
|
|
41
43
|
if connection_string:
|
|
42
44
|
ctx.obj["connection_string"] = connection_string
|
|
43
45
|
else:
|
|
44
|
-
ctx.obj["connection_string"] = settings.
|
|
46
|
+
ctx.obj["connection_string"] = settings.connection_string
|
|
45
47
|
|
|
46
48
|
if base_url:
|
|
47
49
|
ctx.obj["base_url"] = base_url
|
|
48
50
|
else:
|
|
49
|
-
ctx.obj["base_url"] = settings.
|
|
51
|
+
ctx.obj["base_url"] = settings.base_url
|
|
50
52
|
|
|
51
53
|
|
|
52
54
|
@main.command()
|
|
@@ -5,11 +5,11 @@ from almabtrieb import Almabtrieb
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def get_raw(data: dict) -> dict:
|
|
8
|
-
return data.get("data").get("raw")
|
|
8
|
+
return data.get("data", {}).get("raw")
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
def get_parsed(data: dict) -> dict:
|
|
12
|
-
result = data.get("data").get("parsed")
|
|
12
|
+
result = data.get("data", {}).get("parsed")
|
|
13
13
|
if result is None:
|
|
14
14
|
raise ValueError("No parsed data found")
|
|
15
15
|
return result
|
|
@@ -23,11 +23,17 @@ ParsedData = Annotated[dict, Depends(get_parsed)]
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def get_activity(parsed: ParsedData) -> dict:
|
|
26
|
-
|
|
26
|
+
result = parsed.get("activity")
|
|
27
|
+
if not result:
|
|
28
|
+
raise ValueError("No activity found")
|
|
29
|
+
return result
|
|
27
30
|
|
|
28
31
|
|
|
29
32
|
def get_embedded_object(parsed: ParsedData) -> dict:
|
|
30
|
-
|
|
33
|
+
result = parsed.get("embeddedObject")
|
|
34
|
+
if not result:
|
|
35
|
+
raise ValueError("No embedded object found")
|
|
36
|
+
return result
|
|
31
37
|
|
|
32
38
|
|
|
33
39
|
Activity = Annotated[dict, Depends(get_activity)]
|
|
@@ -37,6 +43,7 @@ EmbeddedObject = Annotated[dict, Depends(get_embedded_object)]
|
|
|
37
43
|
"""The embedded object in the activity as parsed by muck_out"""
|
|
38
44
|
|
|
39
45
|
Publisher = Callable[[dict], Awaitable[None]]
|
|
46
|
+
"""Type returned by the publishing functions"""
|
|
40
47
|
|
|
41
48
|
|
|
42
49
|
def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher:
|
|
@@ -46,5 +53,16 @@ def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher
|
|
|
46
53
|
return publish
|
|
47
54
|
|
|
48
55
|
|
|
56
|
+
def construct_publish_activity(connection: Almabtrieb, actor_id: str) -> Publisher:
|
|
57
|
+
async def publish(data: dict):
|
|
58
|
+
await connection.trigger("publish_activity", {"actor": actor_id, "data": data})
|
|
59
|
+
|
|
60
|
+
return publish
|
|
61
|
+
|
|
62
|
+
|
|
49
63
|
PublishObject = Annotated[Publisher, Depends(construct_publish_object)]
|
|
50
64
|
"""Allows one to publish an object as the actor. Assumes cattle_grid has the extension `simple_object_storage` or equivalent"""
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
PublishActivity = Annotated[Publisher, Depends(construct_publish_activity)]
|
|
68
|
+
"""Allows one to publish an activity as the actor. Assumes cattle_grid has the extension `simple_object_storage` or equivalent"""
|
|
@@ -7,19 +7,19 @@ from .common import Profile
|
|
|
7
7
|
try:
|
|
8
8
|
from bovine.activitystreams import factories_for_actor_object
|
|
9
9
|
from bovine.activitystreams.activity_factory import (
|
|
10
|
-
ActivityFactory as BovineActivityFactory,
|
|
10
|
+
ActivityFactory as BovineActivityFactory, # type: ignore
|
|
11
11
|
)
|
|
12
12
|
from bovine.activitystreams.object_factory import (
|
|
13
|
-
ObjectFactory as BovineObjectFactory,
|
|
13
|
+
ObjectFactory as BovineObjectFactory, # type: ignore
|
|
14
14
|
)
|
|
15
15
|
|
|
16
|
-
def get_activity_factory(profile: Profile) -> BovineActivityFactory:
|
|
16
|
+
def get_activity_factory(profile: Profile) -> BovineActivityFactory: # type: ignore
|
|
17
17
|
activity_factory, _ = factories_for_actor_object(profile)
|
|
18
|
-
return activity_factory
|
|
18
|
+
return activity_factory # type: ignore
|
|
19
19
|
|
|
20
|
-
def get_object_factory(profile: Profile) -> BovineObjectFactory:
|
|
20
|
+
def get_object_factory(profile: Profile) -> BovineObjectFactory: # type: ignore
|
|
21
21
|
_, object_factory = factories_for_actor_object(profile)
|
|
22
|
-
return object_factory
|
|
22
|
+
return object_factory # type: ignore
|
|
23
23
|
|
|
24
24
|
except ImportError:
|
|
25
25
|
|
|
@@ -34,8 +34,8 @@ except ImportError:
|
|
|
34
34
|
raise ImportError("bovine not installed")
|
|
35
35
|
|
|
36
36
|
|
|
37
|
-
ActivityFactory = Annotated[BovineActivityFactory, Depends(get_activity_factory)]
|
|
37
|
+
ActivityFactory = Annotated[BovineActivityFactory, Depends(get_activity_factory)] # type: ignore
|
|
38
38
|
"""The activity factory of type [bovine.activitystreams.activity_factory.ActivityFactory][]"""
|
|
39
39
|
|
|
40
|
-
ObjectFactory = Annotated[BovineObjectFactory, Depends(get_object_factory)]
|
|
40
|
+
ObjectFactory = Annotated[BovineObjectFactory, Depends(get_object_factory)] # type: ignore
|
|
41
41
|
"""The object factory of type [bovine.activitystreams.object_factory.ObjectFactory][]"""
|
|
@@ -5,7 +5,9 @@ from roboherd.cow import RoboCow
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def get_profile(cow: RoboCow) -> dict:
|
|
8
|
-
|
|
8
|
+
if cow.internals.profile is None:
|
|
9
|
+
raise ValueError("Cow has no profile")
|
|
10
|
+
return cow.internals.profile
|
|
9
11
|
|
|
10
12
|
|
|
11
13
|
Profile = Annotated[dict, Depends(get_profile)]
|
|
@@ -25,17 +25,8 @@ class CronEntry:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
@dataclass
|
|
28
|
-
class
|
|
29
|
-
|
|
30
|
-
metadata=dict(description="Information about the cow")
|
|
31
|
-
)
|
|
32
|
-
|
|
33
|
-
auto_follow: bool = field(
|
|
34
|
-
default=True,
|
|
35
|
-
metadata=dict(
|
|
36
|
-
description="""Whether to automatically accept follow requests"""
|
|
37
|
-
),
|
|
38
|
-
)
|
|
28
|
+
class RoboCowInternals:
|
|
29
|
+
"""Internal data for the cow"""
|
|
39
30
|
|
|
40
31
|
profile: dict | None = field(
|
|
41
32
|
default=None,
|
|
@@ -69,6 +60,27 @@ class RoboCow:
|
|
|
69
60
|
|
|
70
61
|
startup_routine: Callable | None = None
|
|
71
62
|
|
|
63
|
+
base_url: str | None = field(default=None)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass
|
|
67
|
+
class RoboCow:
|
|
68
|
+
information: Information = field(
|
|
69
|
+
metadata=dict(description="Information about the cow")
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
auto_follow: bool = field(
|
|
73
|
+
default=True,
|
|
74
|
+
metadata=dict(
|
|
75
|
+
description="""Whether to automatically accept follow requests"""
|
|
76
|
+
),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
internals: RoboCowInternals = field(
|
|
80
|
+
default_factory=RoboCowInternals,
|
|
81
|
+
metadata=dict(description="Internal data for the cow"),
|
|
82
|
+
)
|
|
83
|
+
|
|
72
84
|
def action(self, action: str = "*", activity_type: str = "*"):
|
|
73
85
|
"""Adds a handler for an event. Use "*" as a wildcard.
|
|
74
86
|
|
|
@@ -90,15 +102,15 @@ class RoboCow:
|
|
|
90
102
|
|
|
91
103
|
def inner(func):
|
|
92
104
|
config.func = func
|
|
93
|
-
self.handlers.add_handler(config, func)
|
|
94
|
-
self.handler_configuration.append(config)
|
|
105
|
+
self.internals.handlers.add_handler(config, func)
|
|
106
|
+
self.internals.handler_configuration.append(config)
|
|
95
107
|
return func
|
|
96
108
|
|
|
97
109
|
return inner
|
|
98
110
|
|
|
99
111
|
def cron(self, crontab):
|
|
100
112
|
def inner(func):
|
|
101
|
-
self.cron_entries.append(CronEntry(crontab, func))
|
|
113
|
+
self.internals.cron_entries.append(CronEntry(crontab, func))
|
|
102
114
|
|
|
103
115
|
return func
|
|
104
116
|
|
|
@@ -119,7 +131,7 @@ class RoboCow:
|
|
|
119
131
|
action="incoming",
|
|
120
132
|
activity_type="*",
|
|
121
133
|
)
|
|
122
|
-
self.handlers.add_handler(config, func)
|
|
134
|
+
self.internals.handlers.add_handler(config, func)
|
|
123
135
|
return func
|
|
124
136
|
|
|
125
137
|
def incoming_create(self, func):
|
|
@@ -137,75 +149,57 @@ class RoboCow:
|
|
|
137
149
|
config = HandlerConfiguration(
|
|
138
150
|
action="incoming", activity_type="Create", func=func
|
|
139
151
|
)
|
|
140
|
-
self.handler_configuration.append(config)
|
|
141
|
-
self.handlers.add_handler(config, func)
|
|
152
|
+
self.internals.handler_configuration.append(config)
|
|
153
|
+
self.internals.handlers.add_handler(config, func)
|
|
142
154
|
return func
|
|
143
155
|
|
|
144
156
|
def startup(self, func):
|
|
145
157
|
"""Adds a startup routine to be run when the cow is started."""
|
|
146
158
|
|
|
147
|
-
self.startup_routine = func
|
|
159
|
+
self.internals.startup_routine = func
|
|
148
160
|
|
|
149
161
|
def needs_update(self):
|
|
150
162
|
"""Checks if the cow needs to be updated"""
|
|
151
|
-
if self.profile is None:
|
|
163
|
+
if self.internals.profile is None:
|
|
152
164
|
return True
|
|
153
165
|
|
|
154
|
-
if self.information.name != self.profile.get("name"):
|
|
166
|
+
if self.information.name != self.internals.profile.get("name"):
|
|
155
167
|
return True
|
|
156
168
|
|
|
157
|
-
if self.information.description != self.profile.get("summary"):
|
|
169
|
+
if self.information.description != self.internals.profile.get("summary"):
|
|
158
170
|
return True
|
|
159
171
|
|
|
160
172
|
return False
|
|
161
173
|
|
|
162
|
-
def update_data(self):
|
|
163
|
-
"""
|
|
164
|
-
Returns the update_actor message to send to cattle_grid
|
|
165
|
-
|
|
166
|
-
```pycon
|
|
167
|
-
>>> info = Information(handle="moocow", name="name", description="description")
|
|
168
|
-
>>> cow = RoboCow(information=info, actor_id="http://host.example/actor/1")
|
|
169
|
-
>>> cow.update_data()
|
|
170
|
-
{'actor': 'http://host.example/actor/1',
|
|
171
|
-
'profile': {'name': 'name',
|
|
172
|
-
'summary': 'description'},
|
|
173
|
-
'automaticallyUpdateFollowers': True}
|
|
174
|
-
|
|
175
|
-
```
|
|
176
|
-
"""
|
|
177
|
-
return {
|
|
178
|
-
"actor": self.actor_id,
|
|
179
|
-
"profile": {
|
|
180
|
-
"name": self.information.name,
|
|
181
|
-
"summary": self.information.description,
|
|
182
|
-
},
|
|
183
|
-
"automaticallyUpdateFollowers": self.auto_follow,
|
|
184
|
-
}
|
|
185
|
-
|
|
186
174
|
async def run_startup(self, connection: Almabtrieb):
|
|
187
175
|
"""Runs when the cow is birthed"""
|
|
188
176
|
|
|
189
|
-
if self.profile is None:
|
|
190
|
-
|
|
191
|
-
|
|
177
|
+
if self.internals.profile is None:
|
|
178
|
+
if not self.internals.actor_id:
|
|
179
|
+
raise ValueError("Actor ID is not set")
|
|
180
|
+
result = await connection.fetch(
|
|
181
|
+
self.internals.actor_id, self.internals.actor_id
|
|
182
|
+
)
|
|
183
|
+
if not result.data:
|
|
184
|
+
raise ValueError("Could not retrieve profile")
|
|
185
|
+
self.internals.profile = result.data
|
|
192
186
|
|
|
193
|
-
if self.cron_entries:
|
|
187
|
+
if self.internals.cron_entries:
|
|
194
188
|
frequency = ", ".join(
|
|
195
|
-
get_description(entry.crontab) for entry in self.cron_entries
|
|
189
|
+
get_description(entry.crontab) for entry in self.internals.cron_entries
|
|
196
190
|
)
|
|
197
191
|
self.information.frequency = frequency
|
|
198
192
|
|
|
199
|
-
update = determine_profile_update(self.information, self.profile)
|
|
193
|
+
update = determine_profile_update(self.information, self.internals.profile)
|
|
200
194
|
|
|
201
195
|
if update:
|
|
202
196
|
logger.info("Updating profile for %s", self.information.handle)
|
|
203
197
|
|
|
204
198
|
await connection.trigger("update_actor", update)
|
|
205
199
|
|
|
206
|
-
if self.startup_routine:
|
|
207
|
-
await inject(self.startup_routine)(
|
|
208
|
-
cow=self,
|
|
209
|
-
connection=connection,
|
|
210
|
-
actor_id=self.actor_id,
|
|
211
|
-
)
|
|
200
|
+
if self.internals.startup_routine:
|
|
201
|
+
await inject(self.internals.startup_routine)(
|
|
202
|
+
cow=self, # type:ignore
|
|
203
|
+
connection=connection, # type:ignore
|
|
204
|
+
actor_id=self.internals.actor_id, # type:ignore
|
|
205
|
+
) # type:ignore
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
from urllib.parse import urlparse
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
try:
|
|
4
|
+
from bovine.activitystreams.utils import as_list
|
|
5
|
+
except ImportError:
|
|
6
|
+
|
|
7
|
+
def as_list(value):
|
|
8
|
+
if isinstance(value, list):
|
|
9
|
+
return value
|
|
10
|
+
|
|
11
|
+
return [value]
|
|
12
|
+
|
|
3
13
|
|
|
4
14
|
from .types import Information
|
|
5
15
|
|
|
@@ -14,6 +24,9 @@ def profile_part_needs_update(information: Information, profile: dict) -> bool:
|
|
|
14
24
|
if information.type != profile.get("type"):
|
|
15
25
|
return True
|
|
16
26
|
|
|
27
|
+
if information.icon != profile.get("icon"):
|
|
28
|
+
return True
|
|
29
|
+
|
|
17
30
|
return False
|
|
18
31
|
|
|
19
32
|
|
|
@@ -27,7 +40,7 @@ def key_index_from_attachment(attachments: list[dict], key: str) -> int | None:
|
|
|
27
40
|
|
|
28
41
|
|
|
29
42
|
def determine_action_for_key_and_value(
|
|
30
|
-
attachments: list[dict], key: str, value: str
|
|
43
|
+
attachments: list[dict], key: str, value: str | None
|
|
31
44
|
) -> dict | None:
|
|
32
45
|
idx = key_index_from_attachment(attachments, key)
|
|
33
46
|
if idx is None:
|
|
@@ -78,19 +91,19 @@ def determine_actions(information: Information, profile: dict) -> list[dict] | N
|
|
|
78
91
|
"identifier": "acct:"
|
|
79
92
|
+ information.handle
|
|
80
93
|
+ "@"
|
|
81
|
-
+ urlparse(profile.get("id")).netloc,
|
|
94
|
+
+ str(urlparse(profile.get("id")).netloc),
|
|
82
95
|
"primary": True,
|
|
83
96
|
}
|
|
84
97
|
)
|
|
85
98
|
|
|
86
|
-
actions =
|
|
99
|
+
actions = [x for x in actions if x is not None]
|
|
87
100
|
|
|
88
101
|
if len(actions) == 0:
|
|
89
102
|
return None
|
|
90
103
|
return actions
|
|
91
104
|
|
|
92
105
|
|
|
93
|
-
def determine_profile_update(information: Information, profile: dict) -> dict:
|
|
106
|
+
def determine_profile_update(information: Information, profile: dict) -> dict | None:
|
|
94
107
|
"""Returns the update for the profile"""
|
|
95
108
|
|
|
96
109
|
update = {"actor": profile.get("id")}
|
|
@@ -100,6 +113,7 @@ def determine_profile_update(information: Information, profile: dict) -> dict:
|
|
|
100
113
|
"type": information.type,
|
|
101
114
|
"name": information.name,
|
|
102
115
|
"summary": information.description,
|
|
116
|
+
"icon": information.icon,
|
|
103
117
|
}
|
|
104
118
|
|
|
105
119
|
actions = determine_actions(information, profile)
|
|
@@ -27,7 +27,8 @@ def test_needs_update(name, summary, profile, expected):
|
|
|
27
27
|
name=name,
|
|
28
28
|
description=summary,
|
|
29
29
|
)
|
|
30
|
-
cow = RoboCow(information=info
|
|
30
|
+
cow = RoboCow(information=info)
|
|
31
|
+
cow.internals.profile = profile
|
|
31
32
|
|
|
32
33
|
assert cow.needs_update() == expected
|
|
33
34
|
|
|
@@ -40,13 +41,13 @@ def test_cron():
|
|
|
40
41
|
async def test_func():
|
|
41
42
|
pass
|
|
42
43
|
|
|
43
|
-
assert len(cow.cron_entries) == 1
|
|
44
|
+
assert len(cow.internals.cron_entries) == 1
|
|
44
45
|
|
|
45
46
|
|
|
46
47
|
async def test_startup():
|
|
47
48
|
info = Information(handle="testcow")
|
|
48
49
|
cow = RoboCow(information=info)
|
|
49
|
-
cow.profile = {"id": "http://host.test/actor/cow"}
|
|
50
|
+
cow.internals.profile = {"id": "http://host.test/actor/cow"}
|
|
50
51
|
mock = AsyncMock()
|
|
51
52
|
|
|
52
53
|
cow.startup(mock)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
3
|
from .types import Information, MetaInformation
|
|
4
|
-
|
|
4
|
+
from .const import default_icon
|
|
5
5
|
from .profile import determine_profile_update
|
|
6
6
|
|
|
7
7
|
|
|
@@ -14,6 +14,7 @@ from .profile import determine_profile_update
|
|
|
14
14
|
],
|
|
15
15
|
)
|
|
16
16
|
def test_determine_profile_update_no_update(info_params, profile):
|
|
17
|
+
profile["icon"] = default_icon
|
|
17
18
|
info = Information(**info_params)
|
|
18
19
|
|
|
19
20
|
assert determine_profile_update(info, profile) is None
|
|
@@ -27,13 +28,22 @@ def test_determine_profile_update():
|
|
|
27
28
|
|
|
28
29
|
assert result == {
|
|
29
30
|
"actor": "http://host.test/actor/1",
|
|
30
|
-
"profile": {
|
|
31
|
+
"profile": {
|
|
32
|
+
"type": "Service",
|
|
33
|
+
"name": "name",
|
|
34
|
+
"summary": "description",
|
|
35
|
+
"icon": default_icon,
|
|
36
|
+
},
|
|
31
37
|
}
|
|
32
38
|
|
|
33
39
|
|
|
34
40
|
def test_determine_profile_update_author():
|
|
35
41
|
info = Information(meta_information=MetaInformation(author="acct:author@host.test"))
|
|
36
|
-
profile = {
|
|
42
|
+
profile = {
|
|
43
|
+
"id": "http://host.test/actor/1",
|
|
44
|
+
"type": "Service",
|
|
45
|
+
"icon": default_icon,
|
|
46
|
+
}
|
|
37
47
|
|
|
38
48
|
result = determine_profile_update(info, profile)
|
|
39
49
|
|
|
@@ -47,3 +57,25 @@ def test_determine_profile_update_author():
|
|
|
47
57
|
}
|
|
48
58
|
],
|
|
49
59
|
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_profile_update_for_new_preferredUsername():
|
|
63
|
+
info = Information(handle="handle")
|
|
64
|
+
profile = {
|
|
65
|
+
"id": "http://host.test/actor/1",
|
|
66
|
+
"type": "Service",
|
|
67
|
+
"icon": default_icon,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
result = determine_profile_update(info, profile)
|
|
71
|
+
|
|
72
|
+
assert result == {
|
|
73
|
+
"actor": "http://host.test/actor/1",
|
|
74
|
+
"actions": [
|
|
75
|
+
{
|
|
76
|
+
"action": "add_identifier",
|
|
77
|
+
"identifier": "acct:handle@host.test",
|
|
78
|
+
"primary": True,
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
}
|