matrix-python 1.4.4a0__py3-none-any.whl → 1.4.6a0__py3-none-any.whl
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.
- matrix/_version.py +2 -2
- matrix/bot.py +2 -3
- matrix/config.py +108 -44
- {matrix_python-1.4.4a0.dist-info → matrix_python-1.4.6a0.dist-info}/METADATA +12 -11
- {matrix_python-1.4.4a0.dist-info → matrix_python-1.4.6a0.dist-info}/RECORD +7 -7
- {matrix_python-1.4.4a0.dist-info → matrix_python-1.4.6a0.dist-info}/WHEEL +0 -0
- {matrix_python-1.4.4a0.dist-info → matrix_python-1.4.6a0.dist-info}/top_level.txt +0 -0
matrix/_version.py
CHANGED
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '1.4.
|
|
22
|
-
__version_tuple__ = version_tuple = (1, 4,
|
|
21
|
+
__version__ = version = '1.4.6a0'
|
|
22
|
+
__version_tuple__ = version_tuple = (1, 4, 6, 'a0')
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
matrix/bot.py
CHANGED
|
@@ -245,8 +245,7 @@ class Bot(Registry):
|
|
|
245
245
|
:func:`asyncio.run`, and ensures the client is closed gracefully
|
|
246
246
|
on interruption.
|
|
247
247
|
"""
|
|
248
|
-
|
|
249
|
-
self._load_config(config)
|
|
248
|
+
self._load_config(config)
|
|
250
249
|
|
|
251
250
|
try:
|
|
252
251
|
asyncio.run(self.run())
|
|
@@ -264,7 +263,7 @@ class Bot(Registry):
|
|
|
264
263
|
calls the :meth:`on_ready` hook, and starts the long-running
|
|
265
264
|
sync loop for receiving events.
|
|
266
265
|
"""
|
|
267
|
-
self.client.user = self.config.
|
|
266
|
+
self.client.user = self.config.username
|
|
268
267
|
|
|
269
268
|
self.start_at = time.time()
|
|
270
269
|
self.log.info("starting – timestamp=%s", self.start_at)
|
matrix/config.py
CHANGED
|
@@ -1,61 +1,125 @@
|
|
|
1
|
-
import
|
|
1
|
+
from typing import Any
|
|
2
|
+
|
|
3
|
+
from envyaml import EnvYAML
|
|
4
|
+
|
|
2
5
|
from .errors import ConfigError
|
|
3
|
-
from typing import Optional
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
class Config:
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
:raises FileNotFoundError: If the configuration file does not exist.
|
|
24
|
-
:raises yaml.YAMLError: If the configuration file cannot be parsed.
|
|
25
|
-
:raises ConfigError: If neither password or token has been provided.
|
|
9
|
+
"""Configuration handler for Matrix client settings.
|
|
10
|
+
|
|
11
|
+
Manages all settings required to connect and authenticate with a Matrix
|
|
12
|
+
homeserver. Configuration can be loaded from a YAML file or provided
|
|
13
|
+
directly via constructor parameters. At least one authentication method
|
|
14
|
+
must be provided.
|
|
15
|
+
|
|
16
|
+
# Example
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
# Load from file
|
|
20
|
+
config = Config(config_path="path/to/config..yaml")
|
|
21
|
+
|
|
22
|
+
# Manual configuration
|
|
23
|
+
config = Config(username="@bot:matrix.org", password="secret")
|
|
24
|
+
```
|
|
26
25
|
"""
|
|
27
26
|
|
|
28
27
|
def __init__(
|
|
29
28
|
self,
|
|
30
|
-
config_path:
|
|
29
|
+
config_path: str | None = None,
|
|
31
30
|
*,
|
|
32
|
-
homeserver:
|
|
33
|
-
username:
|
|
34
|
-
password:
|
|
35
|
-
token:
|
|
36
|
-
prefix:
|
|
31
|
+
homeserver: str | None = None,
|
|
32
|
+
username: str | None = None,
|
|
33
|
+
password: str | None = None,
|
|
34
|
+
token: str | None = None,
|
|
35
|
+
prefix: str | None = None,
|
|
37
36
|
) -> None:
|
|
37
|
+
"""Initialize the bot configuration.
|
|
38
|
+
|
|
39
|
+
Loads configuration from a YAML file if provided, otherwise uses
|
|
40
|
+
the provided parameters directly. At least one of password or token
|
|
41
|
+
must be supplied.
|
|
42
|
+
|
|
43
|
+
# Example
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
config = Config(
|
|
47
|
+
username="@bot:matrix.org",
|
|
48
|
+
password="secret",
|
|
49
|
+
prefix="!",
|
|
50
|
+
)
|
|
51
|
+
```
|
|
52
|
+
"""
|
|
53
|
+
self._data: dict[str, Any] = {}
|
|
54
|
+
|
|
38
55
|
self.homeserver: str = homeserver or "https://matrix.org"
|
|
39
|
-
self.
|
|
40
|
-
self.password:
|
|
41
|
-
self.token:
|
|
56
|
+
self.username: str | None = username
|
|
57
|
+
self.password: str | None = password
|
|
58
|
+
self.token: str | None = token
|
|
42
59
|
self.prefix: str = prefix or "!"
|
|
43
60
|
|
|
44
61
|
if config_path:
|
|
45
62
|
self.load_from_file(config_path)
|
|
46
|
-
|
|
47
|
-
|
|
63
|
+
else:
|
|
64
|
+
if not self.password and not self.token:
|
|
65
|
+
raise ConfigError("username and password or token")
|
|
66
|
+
|
|
67
|
+
self._data = {
|
|
68
|
+
"HOMESERVER": self.homeserver,
|
|
69
|
+
"USERNAME": self.username,
|
|
70
|
+
"PASSWORD": self.password,
|
|
71
|
+
"TOKEN": self.token,
|
|
72
|
+
"PREFIX": self.prefix,
|
|
73
|
+
}
|
|
48
74
|
|
|
49
75
|
def load_from_file(self, config_path: str) -> None:
|
|
50
|
-
"""Load Matrix client settings
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
76
|
+
"""Load Matrix client settings from a YAML config file.
|
|
77
|
+
|
|
78
|
+
Supports environment variable substitution via EnvYAML. Values in
|
|
79
|
+
the YAML file can reference environment variables using ${VAR} syntax.
|
|
80
|
+
|
|
81
|
+
# Example
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
config = Config()
|
|
85
|
+
config.load_from_file("path/to/config.yaml")
|
|
86
|
+
```
|
|
87
|
+
"""
|
|
88
|
+
self._data = dict(EnvYAML(config_path))
|
|
89
|
+
|
|
90
|
+
password = self._data.get("PASSWORD", None)
|
|
91
|
+
token = self._data.get("TOKEN", None)
|
|
92
|
+
|
|
93
|
+
if not password and not token:
|
|
94
|
+
raise ConfigError("USERNAME and PASSWORD or TOKEN")
|
|
95
|
+
|
|
96
|
+
self.homeserver = self._data.get("HOMESERVER", "https://matrix.org")
|
|
97
|
+
self.username = self._data.get("USERNAME")
|
|
98
|
+
self.password = password
|
|
99
|
+
self.token = token
|
|
100
|
+
self.prefix = self._data.get("PREFIX", "!")
|
|
101
|
+
|
|
102
|
+
def get(self, key: str, *, section: str | None = None, default: Any = None) -> Any:
|
|
103
|
+
"""Access a config value by key, optionally scoped to a section.
|
|
104
|
+
|
|
105
|
+
# Example
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
config.get(key="main_channel", section="bot")
|
|
109
|
+
config.get(key="log_level", default="INFO")
|
|
110
|
+
```
|
|
111
|
+
"""
|
|
112
|
+
if section in self._data:
|
|
113
|
+
return self._data.get(section, {}).get(key, default)
|
|
114
|
+
return self._data.get(key, default)
|
|
115
|
+
|
|
116
|
+
def __getitem__(self, key: str) -> Any:
|
|
117
|
+
"""Access a config value by key, raising KeyError if not found.
|
|
118
|
+
|
|
119
|
+
# Example
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
config["bot"]["main_channel"]
|
|
123
|
+
```
|
|
124
|
+
"""
|
|
125
|
+
return self._data[key]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.6a0
|
|
4
4
|
Summary: An easy-to-use Matrix bot framework designed for quick development and minimal setup
|
|
5
5
|
Author: Simon Roy, Chris Dedman Rollet
|
|
6
6
|
Maintainer-email: Code Society Lab <admin@codesociety.xyz>
|
|
@@ -684,18 +684,19 @@ Project-URL: Source, https://github.com/Code-Society-Lab/matrixpy
|
|
|
684
684
|
Project-URL: Issues, https://github.com/Code-Society-Lab/matrixpy/issues
|
|
685
685
|
Requires-Python: >=3.10
|
|
686
686
|
Description-Content-Type: text/markdown
|
|
687
|
-
Requires-Dist: matrix-nio
|
|
687
|
+
Requires-Dist: matrix-nio==0.25.2
|
|
688
688
|
Requires-Dist: logger
|
|
689
|
-
Requires-Dist: PyYAML
|
|
690
|
-
Requires-Dist: markdown
|
|
691
|
-
Requires-Dist: APScheduler
|
|
689
|
+
Requires-Dist: PyYAML==6.0.3
|
|
690
|
+
Requires-Dist: markdown==3.10.2
|
|
691
|
+
Requires-Dist: APScheduler==3.11.2
|
|
692
|
+
Requires-Dist: envyaml==1.10.211231
|
|
692
693
|
Provides-Extra: dev
|
|
693
|
-
Requires-Dist: pytest; extra == "dev"
|
|
694
|
-
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
695
|
-
Requires-Dist: black; extra == "dev"
|
|
696
|
-
Requires-Dist: mypy; extra == "dev"
|
|
697
|
-
Requires-Dist: types-PyYAML; extra == "dev"
|
|
698
|
-
Requires-Dist: types-Markdown; extra == "dev"
|
|
694
|
+
Requires-Dist: pytest==9.0.3; extra == "dev"
|
|
695
|
+
Requires-Dist: pytest-asyncio==1.3.0; extra == "dev"
|
|
696
|
+
Requires-Dist: black==26.3.1; extra == "dev"
|
|
697
|
+
Requires-Dist: mypy==1.20.0; extra == "dev"
|
|
698
|
+
Requires-Dist: types-PyYAML==6.0.12.20260408; extra == "dev"
|
|
699
|
+
Requires-Dist: types-Markdown==3.10.2.20260408; extra == "dev"
|
|
699
700
|
|
|
700
701
|
<div align="center">
|
|
701
702
|
<em>A simple, developer-friendly library to create powerful <a href="https://matrix.org">Matrix</a> bots.</em>
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
matrix/__init__.py,sha256=g8yEFjELnnwlvOKns-Ug6LgOezkjAFZ-Opt7esbBHKg,728
|
|
2
|
-
matrix/_version.py,sha256=
|
|
3
|
-
matrix/bot.py,sha256=
|
|
2
|
+
matrix/_version.py,sha256=rxov6PXTQVt5rKd2h-A8n5ETLEXZ52KLdqbL608ZU2s,528
|
|
3
|
+
matrix/bot.py,sha256=NpCZQMHr6rD4DDYDywQErE4fCMW1KZrU0lOF2ZIzuAc,11910
|
|
4
4
|
matrix/checks.py,sha256=F_7432_OcFO-im4fRAj62MUsyv1mXywT4OsGC_7xbBQ,486
|
|
5
5
|
matrix/command.py,sha256=GrP3WsT07sKehGX7PHfnT7gRX22d99877VPd0X2ViEw,10514
|
|
6
|
-
matrix/config.py,sha256=
|
|
6
|
+
matrix/config.py,sha256=JW_BBs-msIhtv1AGebZumLsx4td-Gp-NZaNYPJxRsEo,3680
|
|
7
7
|
matrix/content.py,sha256=z5_E2rTvHsODE52OiDkhDHNQAryx5NLhyHjBb65Xe-U,3853
|
|
8
8
|
matrix/context.py,sha256=-CbxY-LtK9-jgHERhvJH73B3SpO-Uk5ty0j1TMKfzuI,4032
|
|
9
9
|
matrix/errors.py,sha256=HKGb5NUeFuZvieXgpLlVSmUxK4jpA0ODuiPQqQlbQTE,1676
|
|
@@ -18,7 +18,7 @@ matrix/types.py,sha256=UFjC7p8RAf7piEPvp2X3NuWdqBwkM9Yc3He7KWb9icc,384
|
|
|
18
18
|
matrix/help/__init__.py,sha256=1u7V7T_-VgYDeQCTXsc4y8Fo-8gJhOqYJq2U3cUjMWg,168
|
|
19
19
|
matrix/help/help_command.py,sha256=xCLmKklw74LEMjbUfgQR9eaPMFvi3sPtDw2n2pnAnVQ,12800
|
|
20
20
|
matrix/help/pagination.py,sha256=sJk0wC46sFHf7xl7WsGRAUc4FC7b9hPqmwQDmvcjwgM,2717
|
|
21
|
-
matrix_python-1.4.
|
|
22
|
-
matrix_python-1.4.
|
|
23
|
-
matrix_python-1.4.
|
|
24
|
-
matrix_python-1.4.
|
|
21
|
+
matrix_python-1.4.6a0.dist-info/METADATA,sha256=_LnIZv4FZ76G_ncBzjfbwhb0B2ahf4vkMWrvXR1Jf4c,44672
|
|
22
|
+
matrix_python-1.4.6a0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
23
|
+
matrix_python-1.4.6a0.dist-info/top_level.txt,sha256=BvHVM9c7-5SLzg-1OCRpHKgqAubWhRN1e38e6coHs-g,7
|
|
24
|
+
matrix_python-1.4.6a0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|