roboherd 0.1.4__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.4 → roboherd-0.1.5}/.woodpecker/test.yml +3 -1
- {roboherd-0.1.4 → roboherd-0.1.5}/CHANGES.md +9 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/PKG-INFO +1 -1
- roboherd-0.1.5/docs/assets/bull-horns.png +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/index.md +28 -3
- {roboherd-0.1.4 → roboherd-0.1.5}/mkdocs.yml +2 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/pyproject.toml +1 -1
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/annotations/__init__.py +12 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/annotations/common.py +2 -2
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/__init__.py +48 -58
- roboherd-0.1.5/roboherd/cow/const.py +6 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/profile.py +4 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/test_init.py +4 -3
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/test_profile.py +35 -3
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/types.py +7 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/moocow.py +4 -2
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/scarecrow.py +2 -1
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/__init__.py +4 -4
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/manager/__init__.py +1 -1
- {roboherd-0.1.4 → 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.4 → roboherd-0.1.5}/roboherd/herd/manager/test_config.py +16 -0
- roboherd-0.1.5/roboherd/herd/manager/test_load.py +19 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/processor.py +2 -2
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/scheduler.py +1 -1
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/util.py +2 -51
- {roboherd-0.1.4 → roboherd-0.1.5}/uv.lock +166 -150
- roboherd-0.1.4/roboherd/test_util.py +0 -24
- {roboherd-0.1.4 → roboherd-0.1.5}/.gitignore +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/.woodpecker/create_release.yml +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/.woodpecker/publish_docker.yml +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/.woodpecker/publish_pypi.yml +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/.woodpecker/website.yml +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/README.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/annotations.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/assets/mastodon.png +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/cli.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/cow.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/herd.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/docs/util.md +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/resources/docker/Dockerfile +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/resources/docker/build.sh +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/__init__.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/__main__.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/annotations/bovine.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/handlers.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/test_handlers.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/test_util.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/cow/util.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/__init__.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/dev_null.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/json_echo.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/meta.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/number.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/examples/rooster.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/builder.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/manager/test_manager.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/test_herd.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/test_scheduler.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/herd/types.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/register.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/test_validators.py +0 -0
- {roboherd-0.1.4 → roboherd-0.1.5}/roboherd/validators.py +0 -0
|
@@ -13,8 +13,10 @@ steps:
|
|
|
13
13
|
test_format:
|
|
14
14
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
15
15
|
commands:
|
|
16
|
-
- uv run ruff format .
|
|
16
|
+
- uv run ruff format --check .
|
|
17
17
|
- uv run ruff check .
|
|
18
|
+
when:
|
|
19
|
+
- matrix: { extras: "--all-extras" }
|
|
18
20
|
test_pytest:
|
|
19
21
|
image: ghcr.io/astral-sh/uv:python3.11-alpine
|
|
20
22
|
commands:
|
|
@@ -1,5 +1,14 @@
|
|
|
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
|
+
|
|
3
12
|
## 0.1.4 ([Milestone](https://codeberg.org/bovine/roboherd/milestone/10442))
|
|
4
13
|
|
|
5
14
|
- Type check the project
|
|
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).
|
|
@@ -43,6 +43,7 @@ EmbeddedObject = Annotated[dict, Depends(get_embedded_object)]
|
|
|
43
43
|
"""The embedded object in the activity as parsed by muck_out"""
|
|
44
44
|
|
|
45
45
|
Publisher = Callable[[dict], Awaitable[None]]
|
|
46
|
+
"""Type returned by the publishing functions"""
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher:
|
|
@@ -52,5 +53,16 @@ def construct_publish_object(connection: Almabtrieb, actor_id: str) -> Publisher
|
|
|
52
53
|
return publish
|
|
53
54
|
|
|
54
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
|
+
|
|
55
63
|
PublishObject = Annotated[Publisher, Depends(construct_publish_object)]
|
|
56
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"""
|
|
@@ -5,9 +5,9 @@ from roboherd.cow import RoboCow
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
def get_profile(cow: RoboCow) -> dict:
|
|
8
|
-
if cow.profile is None:
|
|
8
|
+
if cow.internals.profile is None:
|
|
9
9
|
raise ValueError("Cow has no profile")
|
|
10
|
-
return cow.profile
|
|
10
|
+
return cow.internals.profile
|
|
11
11
|
|
|
12
12
|
|
|
13
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,79 +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
|
-
if not self.actor_id:
|
|
177
|
+
if self.internals.profile is None:
|
|
178
|
+
if not self.internals.actor_id:
|
|
191
179
|
raise ValueError("Actor ID is not set")
|
|
192
|
-
result = await connection.fetch(
|
|
180
|
+
result = await connection.fetch(
|
|
181
|
+
self.internals.actor_id, self.internals.actor_id
|
|
182
|
+
)
|
|
193
183
|
if not result.data:
|
|
194
184
|
raise ValueError("Could not retrieve profile")
|
|
195
|
-
self.profile = result.data
|
|
185
|
+
self.internals.profile = result.data
|
|
196
186
|
|
|
197
|
-
if self.cron_entries:
|
|
187
|
+
if self.internals.cron_entries:
|
|
198
188
|
frequency = ", ".join(
|
|
199
|
-
get_description(entry.crontab) for entry in self.cron_entries
|
|
189
|
+
get_description(entry.crontab) for entry in self.internals.cron_entries
|
|
200
190
|
)
|
|
201
191
|
self.information.frequency = frequency
|
|
202
192
|
|
|
203
|
-
update = determine_profile_update(self.information, self.profile)
|
|
193
|
+
update = determine_profile_update(self.information, self.internals.profile)
|
|
204
194
|
|
|
205
195
|
if update:
|
|
206
196
|
logger.info("Updating profile for %s", self.information.handle)
|
|
207
197
|
|
|
208
198
|
await connection.trigger("update_actor", update)
|
|
209
199
|
|
|
210
|
-
if self.startup_routine:
|
|
211
|
-
await inject(self.startup_routine)(
|
|
212
|
-
cow=self,
|
|
213
|
-
connection=connection,
|
|
214
|
-
actor_id=self.actor_id,
|
|
215
|
-
)
|
|
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
|
|
@@ -24,6 +24,9 @@ def profile_part_needs_update(information: Information, profile: dict) -> bool:
|
|
|
24
24
|
if information.type != profile.get("type"):
|
|
25
25
|
return True
|
|
26
26
|
|
|
27
|
+
if information.icon != profile.get("icon"):
|
|
28
|
+
return True
|
|
29
|
+
|
|
27
30
|
return False
|
|
28
31
|
|
|
29
32
|
|
|
@@ -110,6 +113,7 @@ def determine_profile_update(information: Information, profile: dict) -> dict |
|
|
|
110
113
|
"type": information.type,
|
|
111
114
|
"name": information.name,
|
|
112
115
|
"summary": information.description,
|
|
116
|
+
"icon": information.icon,
|
|
113
117
|
}
|
|
114
118
|
|
|
115
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
|
+
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
from pydantic import BaseModel, Field
|
|
2
2
|
|
|
3
|
+
from .const import default_icon
|
|
4
|
+
|
|
3
5
|
|
|
4
6
|
class MetaInformation(BaseModel):
|
|
5
7
|
"""Meta Information about the bot. This includes
|
|
@@ -48,6 +50,11 @@ class Information(BaseModel):
|
|
|
48
50
|
description="The description of the cow, used as summary of the actor",
|
|
49
51
|
)
|
|
50
52
|
|
|
53
|
+
icon: dict = Field(
|
|
54
|
+
default=default_icon,
|
|
55
|
+
description="The profile image",
|
|
56
|
+
)
|
|
57
|
+
|
|
51
58
|
frequency: str | None = Field(
|
|
52
59
|
default=None,
|
|
53
60
|
examples=["daily"],
|
|
@@ -21,7 +21,9 @@ See <a href="https://codeberg.org/helge/roboherd">codeberg.org</a>.""",
|
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
@moocow.incoming_create
|
|
24
|
-
async def on_incoming_create(
|
|
24
|
+
async def on_incoming_create(
|
|
25
|
+
obj: EmbeddedObject, publisher: PublishObject, actor_id: str
|
|
26
|
+
):
|
|
25
27
|
recipient = obj.get("attributedTo")
|
|
26
28
|
|
|
27
29
|
logger.info("Replying to %s", recipient)
|
|
@@ -29,7 +31,7 @@ async def on_incoming_create(obj: EmbeddedObject, publisher: PublishObject):
|
|
|
29
31
|
obj = {
|
|
30
32
|
"@context": "https://www.w3.org/ns/activitystreams",
|
|
31
33
|
"type": "Note",
|
|
32
|
-
"attributedTo":
|
|
34
|
+
"attributedTo": actor_id,
|
|
33
35
|
"to": [recipient],
|
|
34
36
|
"cc": ["https://www.w3.org/ns/activitystreams#Public"],
|
|
35
37
|
"content": "moo",
|
|
@@ -18,4 +18,5 @@ bot = RoboCow(
|
|
|
18
18
|
|
|
19
19
|
@bot.startup
|
|
20
20
|
async def startup(publish_object: PublishObject, object_factory: ObjectFactory):
|
|
21
|
-
|
|
21
|
+
note = object_factory.note(content="Booo! 🐦").as_public().build() # type: ignore
|
|
22
|
+
await publish_object(note)
|
|
@@ -41,12 +41,12 @@ class RoboHerd:
|
|
|
41
41
|
cow = cow_config.load()
|
|
42
42
|
result = await connection.create_actor(
|
|
43
43
|
name=f"{self.manager.prefix}{cow_config.name}",
|
|
44
|
-
base_url=self.base_url,
|
|
44
|
+
base_url=cow.internals.base_url or self.base_url,
|
|
45
45
|
preferred_username=cow.information.handle,
|
|
46
46
|
profile={"type": "Service"},
|
|
47
47
|
automatically_accept_followers=True,
|
|
48
48
|
)
|
|
49
|
-
cow.actor_id = result.get("id")
|
|
49
|
+
cow.internals.actor_id = result.get("id")
|
|
50
50
|
|
|
51
51
|
self.cows.append(cow)
|
|
52
52
|
|
|
@@ -81,7 +81,7 @@ class RoboHerd:
|
|
|
81
81
|
|
|
82
82
|
result = []
|
|
83
83
|
for cow in self.cows:
|
|
84
|
-
for cron_entry in cow.cron_entries:
|
|
84
|
+
for cron_entry in cow.internals.cron_entries:
|
|
85
85
|
result.append((cow, cron_entry))
|
|
86
86
|
|
|
87
87
|
return result
|
|
@@ -89,6 +89,6 @@ class RoboHerd:
|
|
|
89
89
|
def incoming_handlers(self) -> List[RoboCow]:
|
|
90
90
|
result = []
|
|
91
91
|
for cow in self.cows:
|
|
92
|
-
if cow.handlers.has_handlers:
|
|
92
|
+
if cow.internals.handlers.has_handlers:
|
|
93
93
|
result.append(cow)
|
|
94
94
|
return result
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from dataclasses import dataclass, field
|
|
2
2
|
|
|
3
3
|
from roboherd.cow import RoboCow
|
|
4
|
-
from
|
|
4
|
+
from .load import load_cow
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
@dataclass
|
|
@@ -9,19 +9,26 @@ class CowConfig:
|
|
|
9
9
|
name: str = field(metadata={"description": "Name of the cow, must be unique"})
|
|
10
10
|
module: str
|
|
11
11
|
attribute: str
|
|
12
|
+
config: dict
|
|
12
13
|
|
|
13
14
|
@staticmethod
|
|
14
15
|
def from_name_and_dict(name, cow: dict) -> "CowConfig":
|
|
15
16
|
module, attribute = cow["bot"].split(":")
|
|
16
17
|
|
|
17
|
-
return CowConfig(
|
|
18
|
-
name=name,
|
|
19
|
-
module=module,
|
|
20
|
-
attribute=attribute,
|
|
21
|
-
)
|
|
18
|
+
return CowConfig(name=name, module=module, attribute=attribute, config=cow)
|
|
22
19
|
|
|
23
20
|
def load(self) -> RoboCow:
|
|
24
|
-
|
|
21
|
+
cow = load_cow(self.module, self.attribute)
|
|
22
|
+
|
|
23
|
+
if "name" in self.config:
|
|
24
|
+
cow.information.name = self.config["name"]
|
|
25
|
+
if "handle" in self.config:
|
|
26
|
+
cow.information.handle = self.config["handle"]
|
|
27
|
+
|
|
28
|
+
if "base_url" in self.config:
|
|
29
|
+
cow.internals.base_url = self.config["base_url"]
|
|
30
|
+
|
|
31
|
+
return cow
|
|
25
32
|
|
|
26
33
|
def __hash__(self):
|
|
27
34
|
return hash(self.name)
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import copy
|
|
2
|
+
import importlib
|
|
3
|
+
from importlib import import_module
|
|
4
|
+
|
|
5
|
+
from roboherd.cow import RoboCow
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def load_cow(module_name: str, attribute: str) -> RoboCow:
|
|
9
|
+
"""Loads a cow from module name and attribute"""
|
|
10
|
+
module = import_module(module_name)
|
|
11
|
+
importlib.reload(module)
|
|
12
|
+
|
|
13
|
+
cow = getattr(module, attribute)
|
|
14
|
+
|
|
15
|
+
return copy.deepcopy(cow)
|
|
@@ -38,6 +38,22 @@ def test_from_name_and_dict():
|
|
|
38
38
|
assert cow.attribute == "attribute"
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
def test_from_name_and_dict_with_new_name():
|
|
42
|
+
name = "cow"
|
|
43
|
+
value = {
|
|
44
|
+
"bot": "roboherd.examples.moocow:moocow",
|
|
45
|
+
"handle": "new_handle",
|
|
46
|
+
"name": "new name",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
config = CowConfig.from_name_and_dict(name, value)
|
|
50
|
+
|
|
51
|
+
cow = config.load()
|
|
52
|
+
|
|
53
|
+
assert cow.information.name == "new name"
|
|
54
|
+
assert cow.information.handle == "new_handle"
|
|
55
|
+
|
|
56
|
+
|
|
41
57
|
def test_load_config(test_config):
|
|
42
58
|
herd = HerdConfig.from_settings(test_config)
|
|
43
59
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
from roboherd.cow import RoboCow
|
|
2
|
+
|
|
3
|
+
from .load import load_cow
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def test_load_cow():
|
|
7
|
+
cow = load_cow("roboherd.examples.moocow", "moocow")
|
|
8
|
+
assert isinstance(cow, RoboCow)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def test_load_cow_can_overwrite_variables():
|
|
12
|
+
one = load_cow("roboherd.examples.moocow", "moocow")
|
|
13
|
+
|
|
14
|
+
one.information.name = "A cow eating watermelons"
|
|
15
|
+
|
|
16
|
+
two = load_cow("roboherd.examples.moocow", "moocow")
|
|
17
|
+
|
|
18
|
+
assert two.information.name == "The mooing cow 🐮"
|
|
19
|
+
assert one.information.name == "A cow eating watermelons"
|
|
@@ -26,7 +26,7 @@ class HerdProcessor:
|
|
|
26
26
|
async def process_incoming(self, connection):
|
|
27
27
|
actor_id_to_cow_map = {}
|
|
28
28
|
for cow in self.incoming_handlers:
|
|
29
|
-
actor_id_to_cow_map[cow.actor_id] = cow
|
|
29
|
+
actor_id_to_cow_map[cow.internals.actor_id] = cow
|
|
30
30
|
|
|
31
31
|
async for msg in connection.incoming():
|
|
32
32
|
actor_id = msg["actor"]
|
|
@@ -34,6 +34,6 @@ class HerdProcessor:
|
|
|
34
34
|
cow = actor_id_to_cow_map.get(actor_id)
|
|
35
35
|
logger.info(cow)
|
|
36
36
|
if cow:
|
|
37
|
-
await cow.handlers.handle(
|
|
37
|
+
await cow.internals.handlers.handle(
|
|
38
38
|
msg, "incoming", connection, actor_id, cow=cow
|
|
39
39
|
)
|