aurival 0.1.0__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.
- aurival-0.1.0/LICENSE +202 -0
- aurival-0.1.0/PKG-INFO +166 -0
- aurival-0.1.0/README.md +138 -0
- aurival-0.1.0/aurival/__init__.py +134 -0
- aurival-0.1.0/aurival/auth.py +416 -0
- aurival-0.1.0/aurival/bot.py +316 -0
- aurival-0.1.0/aurival/cli.py +130 -0
- aurival-0.1.0/aurival/errors.py +269 -0
- aurival-0.1.0/aurival/events.py +138 -0
- aurival-0.1.0/aurival/http.py +192 -0
- aurival-0.1.0/aurival/socket.py +366 -0
- aurival-0.1.0/aurival.egg-info/PKG-INFO +166 -0
- aurival-0.1.0/aurival.egg-info/SOURCES.txt +32 -0
- aurival-0.1.0/aurival.egg-info/dependency_links.txt +1 -0
- aurival-0.1.0/aurival.egg-info/entry_points.txt +2 -0
- aurival-0.1.0/aurival.egg-info/requires.txt +7 -0
- aurival-0.1.0/aurival.egg-info/top_level.txt +1 -0
- aurival-0.1.0/pyproject.toml +56 -0
- aurival-0.1.0/setup.cfg +4 -0
- aurival-0.1.0/tests/test_auth.py +538 -0
- aurival-0.1.0/tests/test_auth_coalescing.py +180 -0
- aurival-0.1.0/tests/test_bot.py +396 -0
- aurival-0.1.0/tests/test_bye_table.py +260 -0
- aurival-0.1.0/tests/test_cli.py +151 -0
- aurival-0.1.0/tests/test_e2e.py +305 -0
- aurival-0.1.0/tests/test_e2e_matrix.py +738 -0
- aurival-0.1.0/tests/test_errors.py +210 -0
- aurival-0.1.0/tests/test_http.py +460 -0
- aurival-0.1.0/tests/test_keyfile.py +162 -0
- aurival-0.1.0/tests/test_readme.py +149 -0
- aurival-0.1.0/tests/test_redaction.py +136 -0
- aurival-0.1.0/tests/test_reply_and_conflicts.py +271 -0
- aurival-0.1.0/tests/test_socket.py +625 -0
- aurival-0.1.0/tests/test_socket_redaction.py +86 -0
aurival-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
aurival-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aurival
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Write a bot for Aurival. Declare commands, call run(), we handle the rest.
|
|
5
|
+
Author: Nullspire LLC
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://bots.aurival.com/docs
|
|
8
|
+
Project-URL: Repository, https://github.com/Nullspire-LLC/aurival-sdk
|
|
9
|
+
Project-URL: Issues, https://github.com/Nullspire-LLC/aurival-sdk/issues
|
|
10
|
+
Keywords: aurival,bot,chat
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: aiohttp==3.14.3
|
|
22
|
+
Requires-Dist: cryptography==50.0.1
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest==9.1.1; extra == "dev"
|
|
25
|
+
Requires-Dist: pytest-asyncio==1.4.0; extra == "dev"
|
|
26
|
+
Requires-Dist: ruff==0.16.6; extra == "dev"
|
|
27
|
+
Dynamic: license-file
|
|
28
|
+
|
|
29
|
+
<p align="center">
|
|
30
|
+
<a href="https://bots.aurival.com/docs"><img src="https://raw.githubusercontent.com/Nullspire-LLC/aurival-sdk/main/assets/aurival-banner.png" alt="Aurival" width="100%"></a>
|
|
31
|
+
</p>
|
|
32
|
+
<p align="center">Write a bot for Aurival. Declare commands, call <code>run()</code>, and the SDK holds the socket.</p>
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://pypi.org/project/aurival/"><img src="https://img.shields.io/pypi/v/aurival.svg" alt="PyPI version"></a>
|
|
35
|
+
<a href="https://www.npmjs.com/package/aurival"><img src="https://img.shields.io/npm/v/aurival.svg" alt="npm version"></a>
|
|
36
|
+
<a href="https://github.com/Nullspire-LLC/aurival-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
|
|
37
|
+
</p>
|
|
38
|
+
|
|
39
|
+
```python
|
|
40
|
+
from aurival import Bot
|
|
41
|
+
|
|
42
|
+
bot = Bot()
|
|
43
|
+
|
|
44
|
+
@bot.command("ping", "Check that the bot is alive")
|
|
45
|
+
async def ping(ctx):
|
|
46
|
+
await ctx.reply("pong")
|
|
47
|
+
|
|
48
|
+
bot.run()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Python 3.10+.
|
|
52
|
+
|
|
53
|
+
## Getting started
|
|
54
|
+
|
|
55
|
+
`pip install aurival`, then `aurival init` in your project directory: it pairs this
|
|
56
|
+
machine and writes the `bot.py` above for you. Run `python bot.py` when it's done.
|
|
57
|
+
|
|
58
|
+
## First run
|
|
59
|
+
|
|
60
|
+
There is nothing to configure. The first `run()` pairs this machine:
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
aurival: pairing code K7QP-2M4X
|
|
64
|
+
aurival: fingerprint 018R-6WAC
|
|
65
|
+
Compare the fingerprint in the app, then approve. Waiting...
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Compare the fingerprint in the app before you approve — it is what makes a stolen code
|
|
69
|
+
useless. The key lands in `./.aurival/machine.json` (mode `0600`, in a `0700` directory,
|
|
70
|
+
with a `.gitignore` beside it so it can never be committed). Every later run just starts.
|
|
71
|
+
|
|
72
|
+
The key deploys with the project, like a `.env`. Each bot has its own. A leaked key is one
|
|
73
|
+
machine you revoke; a leaked token would be the bot.
|
|
74
|
+
|
|
75
|
+
## What a handler gets
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
@bot.command("say")
|
|
79
|
+
async def say(ctx):
|
|
80
|
+
ctx.command # "say"
|
|
81
|
+
ctx.arguments # the raw rest of the line, unparsed, possibly ""
|
|
82
|
+
ctx.chat # Chat(id, type, name)
|
|
83
|
+
ctx.sender # User(id, handle, name)
|
|
84
|
+
await ctx.reply("…")
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`ctx.message` is the id of the message that invoked the command, or `None` for an event
|
|
88
|
+
that carries none. `ctx.reply()` quotes that message by default, so an answer never floats
|
|
89
|
+
free in a busy chat — there is no flag; on the rare event with no message id it sends a
|
|
90
|
+
plain message instead.
|
|
91
|
+
|
|
92
|
+
Handlers run concurrently, and an event is acked only after its handler returns — so a
|
|
93
|
+
crash mid-handler redelivers rather than loses. **Do not block inside a handler.** A
|
|
94
|
+
synchronous call (`requests.get`, `time.sleep`, a busy loop) starves the heartbeat on the
|
|
95
|
+
same event loop, and the server reaps a socket that has gone quiet for three intervals.
|
|
96
|
+
Use `await`, or hand the work to a thread.
|
|
97
|
+
|
|
98
|
+
An exception in a handler is logged with its traceback, the bot stays up, and the event is
|
|
99
|
+
still acked:
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
@bot.on_error
|
|
103
|
+
async def on_error(error, ctx):
|
|
104
|
+
... # ctx is None for anything that did not come from a handler
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
The hook also sees the two things that are not a handler's fault: a `problem`
|
|
108
|
+
frame from the server (your socket stays open), and a `backlog.overflowed` event
|
|
109
|
+
telling you how many events you missed while you were away and where delivery
|
|
110
|
+
resumed. Neither reaches a command handler.
|
|
111
|
+
|
|
112
|
+
## Environment
|
|
113
|
+
|
|
114
|
+
| variable | what it does |
|
|
115
|
+
|---|---|
|
|
116
|
+
| `AURIVAL_API` | point at another host. Must be `https://` unless it is loopback. The SDK prints the host it is using, so a redirect is visible. |
|
|
117
|
+
| `AURIVAL_KEY_PATH` | put `machine.json` somewhere else. No `.gitignore` is written beside an override — that is your directory, not ours. |
|
|
118
|
+
|
|
119
|
+
## Errors
|
|
120
|
+
|
|
121
|
+
One class per error type, one subclass per code the SDK acts on, and `code` and `doc_url`
|
|
122
|
+
on every instance:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from aurival import RateLimitError, KeyRevoked
|
|
126
|
+
|
|
127
|
+
try:
|
|
128
|
+
await ctx.reply("…")
|
|
129
|
+
except RateLimitError as exc:
|
|
130
|
+
print(exc.code, exc.retry_after, exc.doc_url)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`KeyRevoked`, `SessionSuperseded` and `BotSuspended` end the process on purpose — each one
|
|
134
|
+
means something a reconnect cannot fix. Everything else the SDK handles for you:
|
|
135
|
+
token expiry, deploys, network faults, redelivery.
|
|
136
|
+
|
|
137
|
+
## Dependencies
|
|
138
|
+
|
|
139
|
+
Two, and each is here for a reason:
|
|
140
|
+
|
|
141
|
+
| package | version | why |
|
|
142
|
+
|---|---|---|
|
|
143
|
+
| [`aiohttp`](https://pypi.org/project/aiohttp/) | `3.14.3` | HTTP **and** the websocket, one library doing both. Two libraries where one would do is a dependency we would be choosing. |
|
|
144
|
+
| [`cryptography`](https://pypi.org/project/cryptography/) | `50.0.1` | Ed25519 signing. PyCA-maintained with prebuilt wheels and first-class Ed25519 — hand-rolling it would be a security review we do not want to own. |
|
|
145
|
+
|
|
146
|
+
Development only: `pytest 9.1.1`, `pytest-asyncio 1.4.0`, `ruff 0.16.6`, `setuptools 84.0.0`.
|
|
147
|
+
|
|
148
|
+
Every version was resolved from PyPI at build time (2026-09-05) and pinned. None came from
|
|
149
|
+
memory.
|
|
150
|
+
|
|
151
|
+
## Tests
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
pytest tests
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The end-to-end test runs a real bot against the real Go service through
|
|
158
|
+
`backend-go/cmd/bot-api-testbed`, which needs a throwaway Postgres:
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
MIGRATE_TEST_DATABASE_URL='postgres://postgres@127.0.0.1:5432/postgres?sslmode=disable' \
|
|
162
|
+
pytest tests
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
**Without that variable the end-to-end test announces that it skipped.** It never passes
|
|
166
|
+
quietly — a suite reporting green when it never reached the service is worse than no suite.
|
aurival-0.1.0/README.md
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://bots.aurival.com/docs"><img src="https://raw.githubusercontent.com/Nullspire-LLC/aurival-sdk/main/assets/aurival-banner.png" alt="Aurival" width="100%"></a>
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">Write a bot for Aurival. Declare commands, call <code>run()</code>, and the SDK holds the socket.</p>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://pypi.org/project/aurival/"><img src="https://img.shields.io/pypi/v/aurival.svg" alt="PyPI version"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/aurival"><img src="https://img.shields.io/npm/v/aurival.svg" alt="npm version"></a>
|
|
8
|
+
<a href="https://github.com/Nullspire-LLC/aurival-sdk/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-Apache--2.0-blue.svg" alt="License: Apache-2.0"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
```python
|
|
12
|
+
from aurival import Bot
|
|
13
|
+
|
|
14
|
+
bot = Bot()
|
|
15
|
+
|
|
16
|
+
@bot.command("ping", "Check that the bot is alive")
|
|
17
|
+
async def ping(ctx):
|
|
18
|
+
await ctx.reply("pong")
|
|
19
|
+
|
|
20
|
+
bot.run()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Python 3.10+.
|
|
24
|
+
|
|
25
|
+
## Getting started
|
|
26
|
+
|
|
27
|
+
`pip install aurival`, then `aurival init` in your project directory: it pairs this
|
|
28
|
+
machine and writes the `bot.py` above for you. Run `python bot.py` when it's done.
|
|
29
|
+
|
|
30
|
+
## First run
|
|
31
|
+
|
|
32
|
+
There is nothing to configure. The first `run()` pairs this machine:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
aurival: pairing code K7QP-2M4X
|
|
36
|
+
aurival: fingerprint 018R-6WAC
|
|
37
|
+
Compare the fingerprint in the app, then approve. Waiting...
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Compare the fingerprint in the app before you approve — it is what makes a stolen code
|
|
41
|
+
useless. The key lands in `./.aurival/machine.json` (mode `0600`, in a `0700` directory,
|
|
42
|
+
with a `.gitignore` beside it so it can never be committed). Every later run just starts.
|
|
43
|
+
|
|
44
|
+
The key deploys with the project, like a `.env`. Each bot has its own. A leaked key is one
|
|
45
|
+
machine you revoke; a leaked token would be the bot.
|
|
46
|
+
|
|
47
|
+
## What a handler gets
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
@bot.command("say")
|
|
51
|
+
async def say(ctx):
|
|
52
|
+
ctx.command # "say"
|
|
53
|
+
ctx.arguments # the raw rest of the line, unparsed, possibly ""
|
|
54
|
+
ctx.chat # Chat(id, type, name)
|
|
55
|
+
ctx.sender # User(id, handle, name)
|
|
56
|
+
await ctx.reply("…")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`ctx.message` is the id of the message that invoked the command, or `None` for an event
|
|
60
|
+
that carries none. `ctx.reply()` quotes that message by default, so an answer never floats
|
|
61
|
+
free in a busy chat — there is no flag; on the rare event with no message id it sends a
|
|
62
|
+
plain message instead.
|
|
63
|
+
|
|
64
|
+
Handlers run concurrently, and an event is acked only after its handler returns — so a
|
|
65
|
+
crash mid-handler redelivers rather than loses. **Do not block inside a handler.** A
|
|
66
|
+
synchronous call (`requests.get`, `time.sleep`, a busy loop) starves the heartbeat on the
|
|
67
|
+
same event loop, and the server reaps a socket that has gone quiet for three intervals.
|
|
68
|
+
Use `await`, or hand the work to a thread.
|
|
69
|
+
|
|
70
|
+
An exception in a handler is logged with its traceback, the bot stays up, and the event is
|
|
71
|
+
still acked:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
@bot.on_error
|
|
75
|
+
async def on_error(error, ctx):
|
|
76
|
+
... # ctx is None for anything that did not come from a handler
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The hook also sees the two things that are not a handler's fault: a `problem`
|
|
80
|
+
frame from the server (your socket stays open), and a `backlog.overflowed` event
|
|
81
|
+
telling you how many events you missed while you were away and where delivery
|
|
82
|
+
resumed. Neither reaches a command handler.
|
|
83
|
+
|
|
84
|
+
## Environment
|
|
85
|
+
|
|
86
|
+
| variable | what it does |
|
|
87
|
+
|---|---|
|
|
88
|
+
| `AURIVAL_API` | point at another host. Must be `https://` unless it is loopback. The SDK prints the host it is using, so a redirect is visible. |
|
|
89
|
+
| `AURIVAL_KEY_PATH` | put `machine.json` somewhere else. No `.gitignore` is written beside an override — that is your directory, not ours. |
|
|
90
|
+
|
|
91
|
+
## Errors
|
|
92
|
+
|
|
93
|
+
One class per error type, one subclass per code the SDK acts on, and `code` and `doc_url`
|
|
94
|
+
on every instance:
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from aurival import RateLimitError, KeyRevoked
|
|
98
|
+
|
|
99
|
+
try:
|
|
100
|
+
await ctx.reply("…")
|
|
101
|
+
except RateLimitError as exc:
|
|
102
|
+
print(exc.code, exc.retry_after, exc.doc_url)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
`KeyRevoked`, `SessionSuperseded` and `BotSuspended` end the process on purpose — each one
|
|
106
|
+
means something a reconnect cannot fix. Everything else the SDK handles for you:
|
|
107
|
+
token expiry, deploys, network faults, redelivery.
|
|
108
|
+
|
|
109
|
+
## Dependencies
|
|
110
|
+
|
|
111
|
+
Two, and each is here for a reason:
|
|
112
|
+
|
|
113
|
+
| package | version | why |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| [`aiohttp`](https://pypi.org/project/aiohttp/) | `3.14.3` | HTTP **and** the websocket, one library doing both. Two libraries where one would do is a dependency we would be choosing. |
|
|
116
|
+
| [`cryptography`](https://pypi.org/project/cryptography/) | `50.0.1` | Ed25519 signing. PyCA-maintained with prebuilt wheels and first-class Ed25519 — hand-rolling it would be a security review we do not want to own. |
|
|
117
|
+
|
|
118
|
+
Development only: `pytest 9.1.1`, `pytest-asyncio 1.4.0`, `ruff 0.16.6`, `setuptools 84.0.0`.
|
|
119
|
+
|
|
120
|
+
Every version was resolved from PyPI at build time (2026-09-05) and pinned. None came from
|
|
121
|
+
memory.
|
|
122
|
+
|
|
123
|
+
## Tests
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
pytest tests
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The end-to-end test runs a real bot against the real Go service through
|
|
130
|
+
`backend-go/cmd/bot-api-testbed`, which needs a throwaway Postgres:
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
MIGRATE_TEST_DATABASE_URL='postgres://postgres@127.0.0.1:5432/postgres?sslmode=disable' \
|
|
134
|
+
pytest tests
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Without that variable the end-to-end test announces that it skipped.** It never passes
|
|
138
|
+
quietly — a suite reporting green when it never reached the service is worse than no suite.
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"""Aurival bot SDK.
|
|
2
|
+
|
|
3
|
+
Declare commands, call run(), and the SDK holds the socket::
|
|
4
|
+
|
|
5
|
+
from aurival import Bot
|
|
6
|
+
|
|
7
|
+
bot = Bot()
|
|
8
|
+
|
|
9
|
+
@bot.command("ping")
|
|
10
|
+
async def ping(ctx):
|
|
11
|
+
await ctx.reply("pong")
|
|
12
|
+
|
|
13
|
+
bot.run()
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from .bot import Bot
|
|
19
|
+
from .errors import (
|
|
20
|
+
CODE_CLASSES,
|
|
21
|
+
DOC_URL_PREFIX,
|
|
22
|
+
TYPE_CLASSES,
|
|
23
|
+
AccessTokenExpired,
|
|
24
|
+
AccessTokenInvalid,
|
|
25
|
+
AckUnknownEvent,
|
|
26
|
+
APIError,
|
|
27
|
+
AssertionExpired,
|
|
28
|
+
AssertionReplay,
|
|
29
|
+
AurivalAPIError,
|
|
30
|
+
AurivalError,
|
|
31
|
+
AuthenticationError,
|
|
32
|
+
BadAssertion,
|
|
33
|
+
BadProof,
|
|
34
|
+
BadPublicKey,
|
|
35
|
+
BotLinkNotAllowed,
|
|
36
|
+
BotPlaygroundOnly,
|
|
37
|
+
BotSuspended,
|
|
38
|
+
EmptyText,
|
|
39
|
+
FrameInvalid,
|
|
40
|
+
FrameTooLarge,
|
|
41
|
+
IdempotencyKeyInvalid,
|
|
42
|
+
IdempotencyKeyReused,
|
|
43
|
+
IdleTimeout,
|
|
44
|
+
InternalError,
|
|
45
|
+
InvalidCommandName,
|
|
46
|
+
InvalidJSON,
|
|
47
|
+
InvalidRequestError,
|
|
48
|
+
KeyAlreadyPaired,
|
|
49
|
+
KeyRevoked,
|
|
50
|
+
NotFound,
|
|
51
|
+
PairRateLimited,
|
|
52
|
+
ParameterInvalid,
|
|
53
|
+
ParameterMissing,
|
|
54
|
+
PermissionDeniedError,
|
|
55
|
+
ProtocolError,
|
|
56
|
+
RateLimited,
|
|
57
|
+
RateLimitError,
|
|
58
|
+
ServerRestarting,
|
|
59
|
+
SessionSuperseded,
|
|
60
|
+
SyncRateLimited,
|
|
61
|
+
TextTooLong,
|
|
62
|
+
TooManyProblems,
|
|
63
|
+
TransportError,
|
|
64
|
+
UnknownOperation,
|
|
65
|
+
UnknownParameter,
|
|
66
|
+
from_envelope,
|
|
67
|
+
)
|
|
68
|
+
from .events import Chat, Command, Context, Event, User
|
|
69
|
+
from .socket import BYE_ACTIONS, ByeAction, action_for_bye
|
|
70
|
+
|
|
71
|
+
__version__ = "0.1.0"
|
|
72
|
+
|
|
73
|
+
# Everything a developer can name. The JS package mirrors this list file for file
|
|
74
|
+
# (SDK-7), so a name missing here becomes a permanent asymmetry: adding an export
|
|
75
|
+
# later is free, removing one is a break.
|
|
76
|
+
__all__ = [
|
|
77
|
+
"BYE_ACTIONS",
|
|
78
|
+
"CODE_CLASSES",
|
|
79
|
+
"DOC_URL_PREFIX",
|
|
80
|
+
"TYPE_CLASSES",
|
|
81
|
+
"APIError",
|
|
82
|
+
"AccessTokenExpired",
|
|
83
|
+
"AccessTokenInvalid",
|
|
84
|
+
"AckUnknownEvent",
|
|
85
|
+
"AssertionExpired",
|
|
86
|
+
"AssertionReplay",
|
|
87
|
+
"AurivalAPIError",
|
|
88
|
+
"AurivalError",
|
|
89
|
+
"AuthenticationError",
|
|
90
|
+
"BadAssertion",
|
|
91
|
+
"BadProof",
|
|
92
|
+
"BadPublicKey",
|
|
93
|
+
"Bot",
|
|
94
|
+
"BotLinkNotAllowed",
|
|
95
|
+
"BotPlaygroundOnly",
|
|
96
|
+
"BotSuspended",
|
|
97
|
+
"ByeAction",
|
|
98
|
+
"Chat",
|
|
99
|
+
"Command",
|
|
100
|
+
"Context",
|
|
101
|
+
"EmptyText",
|
|
102
|
+
"Event",
|
|
103
|
+
"FrameInvalid",
|
|
104
|
+
"FrameTooLarge",
|
|
105
|
+
"IdempotencyKeyInvalid",
|
|
106
|
+
"IdempotencyKeyReused",
|
|
107
|
+
"IdleTimeout",
|
|
108
|
+
"InternalError",
|
|
109
|
+
"InvalidCommandName",
|
|
110
|
+
"InvalidJSON",
|
|
111
|
+
"InvalidRequestError",
|
|
112
|
+
"KeyAlreadyPaired",
|
|
113
|
+
"KeyRevoked",
|
|
114
|
+
"NotFound",
|
|
115
|
+
"PairRateLimited",
|
|
116
|
+
"ParameterInvalid",
|
|
117
|
+
"ParameterMissing",
|
|
118
|
+
"PermissionDeniedError",
|
|
119
|
+
"ProtocolError",
|
|
120
|
+
"RateLimitError",
|
|
121
|
+
"RateLimited",
|
|
122
|
+
"ServerRestarting",
|
|
123
|
+
"SessionSuperseded",
|
|
124
|
+
"SyncRateLimited",
|
|
125
|
+
"TextTooLong",
|
|
126
|
+
"TooManyProblems",
|
|
127
|
+
"TransportError",
|
|
128
|
+
"UnknownOperation",
|
|
129
|
+
"UnknownParameter",
|
|
130
|
+
"User",
|
|
131
|
+
"__version__",
|
|
132
|
+
"action_for_bye",
|
|
133
|
+
"from_envelope",
|
|
134
|
+
]
|