matrix-python 1.1.0a0__tar.gz → 1.2.0a0__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.
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/PKG-INFO +1 -1
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/__init__.py +2 -1
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/_version.py +3 -3
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/bot.py +1 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/command.py +0 -1
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/group.py +46 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix_python.egg-info/PKG-INFO +1 -1
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_command.py +1 -26
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_group.py +34 -2
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/.github/workflows/codeql.yml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/.github/workflows/publish.yml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/.github/workflows/scorecard.yml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/.github/workflows/tests.yml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/.gitignore +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/CODE_OF_CONDUCT.md +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/CONTRIBUTING.md +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/LICENSE +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/README.md +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/README.md +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/checks.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/config.yaml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/cooldown.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/error_handling.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/ping.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/reaction.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/examples/scheduler.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/checks.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/config.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/content.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/context.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/errors.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/help/__init__.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/help/help_command.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/help/pagination.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/message.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/room.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/scheduler.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix/types.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix_python.egg-info/SOURCES.txt +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix_python.egg-info/dependency_links.txt +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix_python.egg-info/requires.txt +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/matrix_python.egg-info/top_level.txt +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/mypy.ini +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/pyproject.toml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/setup.cfg +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/config_fixture.yaml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/config_fixture_token.yaml +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/help/test_default_help_command.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/help/test_help_command.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/help/test_pagination.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_bot.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_config.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_context.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_message.py +0 -0
- {matrix_python-1.1.0a0 → matrix_python-1.2.0a0}/tests/test_room.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0a0
|
|
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>
|
|
@@ -8,7 +8,7 @@ except PackageNotFoundError:
|
|
|
8
8
|
from matrix._version import version as __version__
|
|
9
9
|
|
|
10
10
|
from .bot import Bot
|
|
11
|
-
from .group import Group
|
|
11
|
+
from .group import Group, group
|
|
12
12
|
from .config import Config
|
|
13
13
|
from .context import Context
|
|
14
14
|
from .command import Command
|
|
@@ -19,6 +19,7 @@ from .room import Room
|
|
|
19
19
|
__all__ = [
|
|
20
20
|
"Bot",
|
|
21
21
|
"Group",
|
|
22
|
+
"group",
|
|
22
23
|
"Config",
|
|
23
24
|
"Command",
|
|
24
25
|
"Context",
|
|
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
|
|
|
28
28
|
commit_id: COMMIT_ID
|
|
29
29
|
__commit_id__: COMMIT_ID
|
|
30
30
|
|
|
31
|
-
__version__ = version = '1.
|
|
32
|
-
__version_tuple__ = version_tuple = (1,
|
|
31
|
+
__version__ = version = '1.2.0a0'
|
|
32
|
+
__version_tuple__ = version_tuple = (1, 2, 0, 'a0')
|
|
33
33
|
|
|
34
|
-
__commit_id__ = commit_id = '
|
|
34
|
+
__commit_id__ = commit_id = 'gdd753b685'
|
|
@@ -82,3 +82,49 @@ class Group(Command):
|
|
|
82
82
|
await ctx.subcommand(ctx)
|
|
83
83
|
else:
|
|
84
84
|
await self.callback(ctx)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def group(
|
|
88
|
+
name: str,
|
|
89
|
+
*,
|
|
90
|
+
description: Optional[str] = None,
|
|
91
|
+
prefix: Optional[str] = None,
|
|
92
|
+
parent: Optional[str] = None,
|
|
93
|
+
usage: Optional[str] = None,
|
|
94
|
+
cooldown: Optional[tuple[int, float]] = None,
|
|
95
|
+
) -> Callable[[Callback], Group]:
|
|
96
|
+
"""
|
|
97
|
+
Decorator to create a group with a callback.
|
|
98
|
+
|
|
99
|
+
This is equivalent to @bot.group() but for creating groups
|
|
100
|
+
without immediately registering them to a bot.
|
|
101
|
+
|
|
102
|
+
## Example
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
@group("math", description="Math operations")
|
|
106
|
+
async def math(ctx):
|
|
107
|
+
await ctx.reply("Math help")
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@math.command()
|
|
111
|
+
async def add(ctx, a: int, b: int):
|
|
112
|
+
await ctx.reply(f"{a + b}")
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
bot.register_group(math)
|
|
116
|
+
```
|
|
117
|
+
"""
|
|
118
|
+
|
|
119
|
+
def decorator(func: Callback) -> Group:
|
|
120
|
+
return Group(
|
|
121
|
+
func,
|
|
122
|
+
name=name,
|
|
123
|
+
description=description,
|
|
124
|
+
prefix=prefix,
|
|
125
|
+
parent=parent,
|
|
126
|
+
usage=usage,
|
|
127
|
+
cooldown=cooldown,
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
return decorator
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.2.0a0
|
|
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>
|
|
@@ -130,10 +130,6 @@ async def test_error_handler():
|
|
|
130
130
|
ctx = DummyContext(args=[])
|
|
131
131
|
called = False
|
|
132
132
|
|
|
133
|
-
with pytest.raises(MissingArgumentError):
|
|
134
|
-
await cmd(ctx)
|
|
135
|
-
ctx.logger.exception.assert_called_once()
|
|
136
|
-
|
|
137
133
|
with pytest.raises(TypeError):
|
|
138
134
|
|
|
139
135
|
@cmd.error(TypeError)
|
|
@@ -145,8 +141,7 @@ async def test_error_handler():
|
|
|
145
141
|
nonlocal called
|
|
146
142
|
called = True
|
|
147
143
|
|
|
148
|
-
|
|
149
|
-
await cmd(ctx)
|
|
144
|
+
await cmd(ctx)
|
|
150
145
|
assert called
|
|
151
146
|
|
|
152
147
|
|
|
@@ -233,26 +228,6 @@ async def test_command_executes_when_all_checks_pass():
|
|
|
233
228
|
assert called is True
|
|
234
229
|
|
|
235
230
|
|
|
236
|
-
@pytest.mark.asyncio
|
|
237
|
-
async def test_command_does_not_execute_when_a_check_fails():
|
|
238
|
-
called = False
|
|
239
|
-
|
|
240
|
-
async def my_command(ctx):
|
|
241
|
-
nonlocal called
|
|
242
|
-
called = True
|
|
243
|
-
|
|
244
|
-
cmd = Command(my_command)
|
|
245
|
-
ctx = DummyContext(args=[])
|
|
246
|
-
|
|
247
|
-
@cmd.check
|
|
248
|
-
async def always_fails(ctx):
|
|
249
|
-
return False
|
|
250
|
-
|
|
251
|
-
with pytest.raises(Exception):
|
|
252
|
-
await cmd(ctx)
|
|
253
|
-
assert called is False
|
|
254
|
-
|
|
255
|
-
|
|
256
231
|
def test_parse_arguments_with_union_type__expect_successful_conversion():
|
|
257
232
|
async def my_command(ctx, value: str | int):
|
|
258
233
|
pass
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import pytest
|
|
2
2
|
|
|
3
|
-
from unittest.mock import MagicMock
|
|
4
3
|
from matrix.command import Command
|
|
5
|
-
from matrix.group import Group
|
|
4
|
+
from matrix.group import Group, group
|
|
6
5
|
from matrix.errors import AlreadyRegisteredError, CommandNotFoundError
|
|
7
6
|
|
|
8
7
|
|
|
@@ -125,3 +124,36 @@ async def test_invoke_with_subcommand__invokes_subcommand():
|
|
|
125
124
|
assert called == ["sub"]
|
|
126
125
|
assert ctx.subcommand.name == "foo"
|
|
127
126
|
assert ctx.args == []
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@pytest.mark.asyncio
|
|
130
|
+
async def test_group_factory__expect_group():
|
|
131
|
+
"""Test that @group decorator creates a Group with the decorated function as callback"""
|
|
132
|
+
called = []
|
|
133
|
+
|
|
134
|
+
@group("math", description="Math operations")
|
|
135
|
+
async def math_callback(ctx):
|
|
136
|
+
called.append("math_callback")
|
|
137
|
+
|
|
138
|
+
# Should return a Group instance
|
|
139
|
+
assert isinstance(math_callback, Group)
|
|
140
|
+
assert math_callback.name == "math"
|
|
141
|
+
assert math_callback.description == "Math operations"
|
|
142
|
+
|
|
143
|
+
# Test command registration
|
|
144
|
+
@math_callback.command()
|
|
145
|
+
async def add(ctx, a: int, b: int):
|
|
146
|
+
called.append("add_called")
|
|
147
|
+
|
|
148
|
+
assert "add" in math_callback.commands
|
|
149
|
+
assert math_callback.commands["add"].name == "add"
|
|
150
|
+
assert math_callback.commands["add"].parent == "math"
|
|
151
|
+
|
|
152
|
+
# Test the callback is set correctly
|
|
153
|
+
class DummyCtx:
|
|
154
|
+
def __init__(self):
|
|
155
|
+
self.args = []
|
|
156
|
+
|
|
157
|
+
ctx = DummyCtx()
|
|
158
|
+
await math_callback.invoke(ctx)
|
|
159
|
+
assert called == ["math_callback"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|