matrix-python 1.0.3a0__tar.gz → 1.0.4a0__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.0.3a0 → matrix_python-1.0.4a0}/PKG-INFO +1 -1
- matrix_python-1.0.4a0/examples/README.md +27 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/examples/checks.py +9 -4
- matrix_python-1.0.4a0/examples/cooldown.py +30 -0
- matrix_python-1.0.4a0/examples/error_handling.py +33 -0
- matrix_python-1.0.4a0/examples/ping.py +11 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/examples/reaction.py +5 -4
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/examples/scheduler.py +8 -9
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/__init__.py +3 -1
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/bot.py +63 -13
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/checks.py +1 -1
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/errors.py +0 -1
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/group.py +20 -2
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/help/pagination.py +0 -1
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix_python.egg-info/PKG-INFO +1 -1
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix_python.egg-info/SOURCES.txt +2 -2
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/pyproject.toml +2 -2
- matrix_python-1.0.3a0/examples/cooldown.py +0 -31
- matrix_python-1.0.3a0/examples/error.py +0 -36
- matrix_python-1.0.3a0/examples/ping.py +0 -12
- matrix_python-1.0.3a0/tests/test_help.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/.github/workflows/codeql.yml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/.github/workflows/publish.yml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/.github/workflows/scorecard.yml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/.github/workflows/tests.yml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/.gitignore +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/CODE_OF_CONDUCT.md +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/CONTRIBUTING.md +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/LICENSE +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/README.md +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/examples/config.yaml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/command.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/config.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/context.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/help/__init__.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/help/help_command.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/message.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/room.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix/scheduler.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix_python.egg-info/dependency_links.txt +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix_python.egg-info/requires.txt +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/matrix_python.egg-info/top_level.txt +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/mypy.ini +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/setup.cfg +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/config_fixture.yaml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/config_fixture_token.yaml +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/help/test_default_help_command.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/help/test_help_command.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/help/test_pagination.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_bot.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_command.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_config.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_context.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_group.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_message.py +0 -0
- {matrix_python-1.0.3a0 → matrix_python-1.0.4a0}/tests/test_room.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4a0
|
|
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>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
## Functionality Examples
|
|
2
|
+
This directory contains multiple examples demonstrating how to use different
|
|
3
|
+
features of the **[matrix.py]** library. Each example is self-contained and can be
|
|
4
|
+
run independently.
|
|
5
|
+
|
|
6
|
+
### How to Run the Examples
|
|
7
|
+
- You will first need to update the environment variables in the [config.yaml](config.yaml)
|
|
8
|
+
file with your Matrix credentials and desired settings.
|
|
9
|
+
|
|
10
|
+
- To run any of the examples, navigate to the `examples` directory from your
|
|
11
|
+
command line and execute the desired Python file using the command line.
|
|
12
|
+
For instance:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
python3 error_handling.py
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Make sure you have all the necessary dependencies installed and configured
|
|
19
|
+
before running the examples as instructed in the root [README file](../README.md).
|
|
20
|
+
|
|
21
|
+
### Available Examples
|
|
22
|
+
- [error_handling.py](error_handling.py): Demonstrates how to handle errors in commands.
|
|
23
|
+
- [cooldown.py](cooldown.py): Shows how to implement cooldowns for commands.
|
|
24
|
+
- [ping.py](ping.py): A simple ping command example.
|
|
25
|
+
- [reaction.py](reaction.py): Example of handling reactions to messages.
|
|
26
|
+
- [checks.py](checks.py): Demonstrates how to use checks for command execution.
|
|
27
|
+
- [scheduler.py](scheduler.py): Shows how to schedule tasks.
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
from matrix import Bot, Context
|
|
2
|
+
from matrix.errors import CheckError
|
|
2
3
|
|
|
3
|
-
bot = Bot("
|
|
4
|
+
bot = Bot(config="config.yaml")
|
|
4
5
|
|
|
5
6
|
allowed_users = {"@alice:matrix.org", "@bob:matrix.org"}
|
|
6
7
|
|
|
7
8
|
|
|
8
|
-
@bot.command("secret")
|
|
9
|
-
async def secret_command(ctx: Context):
|
|
9
|
+
@bot.command(name="secret")
|
|
10
|
+
async def secret_command(ctx: Context) -> None:
|
|
10
11
|
await ctx.reply("🎉 Welcome to the secret club!")
|
|
11
12
|
|
|
12
13
|
|
|
@@ -14,8 +15,12 @@ async def secret_command(ctx: Context):
|
|
|
14
15
|
async def is_allowed_user(ctx: Context) -> bool:
|
|
15
16
|
if ctx.sender in allowed_users:
|
|
16
17
|
return True
|
|
17
|
-
await ctx.reply("You do not have permission to use this command.")
|
|
18
18
|
return False
|
|
19
19
|
|
|
20
20
|
|
|
21
|
+
@secret_command.error(CheckError)
|
|
22
|
+
async def permission_error_handler(ctx: Context, error: CheckError) -> None:
|
|
23
|
+
await ctx.reply(f"Access denied: {error}")
|
|
24
|
+
|
|
25
|
+
|
|
21
26
|
bot.start()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from matrix import Bot, Context, cooldown
|
|
2
|
+
from matrix.errors import CooldownError
|
|
3
|
+
|
|
4
|
+
bot = Bot(config="config.yaml")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# Invoke by using !hello
|
|
8
|
+
@cooldown(rate=2, period=10)
|
|
9
|
+
@bot.command("hello")
|
|
10
|
+
async def hello_command(ctx: Context) -> None:
|
|
11
|
+
await ctx.reply("Hello World.")
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@hello_command.error(CooldownError)
|
|
15
|
+
async def hello_command_error_handler(ctx: Context, error: CooldownError) -> None:
|
|
16
|
+
await ctx.reply(f"⏳ Try again in {error.retry:.1f}s")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Invoke by using !cooldown_command
|
|
20
|
+
@bot.command(cooldown=(1, 10))
|
|
21
|
+
async def cooldown_command(ctx: Context) -> None:
|
|
22
|
+
await ctx.reply("This is limited to 1 uses per 10s per user.")
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@cooldown_command.error(CooldownError)
|
|
26
|
+
async def cooldown_function(ctx: Context, error: CooldownError) -> None:
|
|
27
|
+
await ctx.reply(f"⏳ Try again in {error.retry:.1f}s")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
bot.start()
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from matrix import Bot, Context
|
|
2
|
+
from matrix.errors import CommandNotFoundError, MissingArgumentError
|
|
3
|
+
|
|
4
|
+
bot = Bot(config="config.yaml")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@bot.error(CommandNotFoundError)
|
|
8
|
+
async def global_error(error: CommandNotFoundError) -> None:
|
|
9
|
+
print(f"Global error handler {error}.")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@bot.command("div")
|
|
13
|
+
async def division(ctx: Context, a: int, b: int) -> None:
|
|
14
|
+
c = a / b
|
|
15
|
+
await ctx.reply(f"{a} / {b} = {c}")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@division.error(ZeroDivisionError)
|
|
19
|
+
async def div_error(ctx: Context, error: ZeroDivisionError) -> None:
|
|
20
|
+
await ctx.reply(f"Operation not allowed: {error}")
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@division.error(ValueError)
|
|
24
|
+
async def val_error(ctx: Context, error: ValueError) -> None:
|
|
25
|
+
await ctx.reply(f"ValueError: {error}")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@division.error(MissingArgumentError)
|
|
29
|
+
async def command_error(ctx: Context, error: MissingArgumentError) -> None:
|
|
30
|
+
await ctx.reply(f"{error}")
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
bot.start()
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
from
|
|
1
|
+
from asyncio import Event
|
|
2
|
+
from matrix import Bot, Room
|
|
2
3
|
|
|
3
|
-
bot = Bot("
|
|
4
|
+
bot = Bot(config="config.yaml")
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
@bot.event
|
|
7
|
-
async def on_message(room, event):
|
|
8
|
+
async def on_message(room: Room, event: Event) -> None:
|
|
8
9
|
"""
|
|
9
10
|
This function listens for new messages in a room and reacts based
|
|
10
11
|
on the message content.
|
|
@@ -22,7 +23,7 @@ async def on_message(room, event):
|
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
@bot.event
|
|
25
|
-
async def on_react(room, event):
|
|
26
|
+
async def on_react(room: Room, event: Event) -> None:
|
|
26
27
|
"""
|
|
27
28
|
This function listens for new member reaction to messages in a room,
|
|
28
29
|
and reacts based on the reaction emoji.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
from matrix import Bot, Context
|
|
2
2
|
|
|
3
|
-
bot = Bot("
|
|
3
|
+
bot = Bot(config="config.yaml")
|
|
4
4
|
|
|
5
5
|
room_id = "!your_room_id:matrix.org" # Replace with your room ID
|
|
6
6
|
|
|
@@ -8,26 +8,25 @@ room = bot.get_room(room_id)
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
@bot.command("ping")
|
|
11
|
-
async def ping(ctx: Context):
|
|
12
|
-
print(f"{ctx.sender} invoked {ctx.body} in room {ctx.room_name}.")
|
|
11
|
+
async def ping(ctx: Context) -> None:
|
|
13
12
|
await ctx.reply("Pong!")
|
|
14
13
|
|
|
15
14
|
|
|
16
15
|
@bot.schedule("* * * * *")
|
|
17
|
-
async def scheduled_task():
|
|
18
|
-
|
|
16
|
+
async def scheduled_task() -> None:
|
|
17
|
+
# This task runs every minute.
|
|
19
18
|
await room.send(message="Scheduled ping!")
|
|
20
19
|
|
|
21
20
|
|
|
22
21
|
@bot.schedule("0 * * * *")
|
|
23
|
-
async def hourly_task():
|
|
24
|
-
|
|
22
|
+
async def hourly_task() -> None:
|
|
23
|
+
# This task runs every hour.
|
|
25
24
|
await room.send(message="This is your hourly update!")
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
@bot.schedule("0 9 * * 1-5")
|
|
29
|
-
async def weekday_morning_task():
|
|
30
|
-
|
|
28
|
+
async def weekday_morning_task() -> None:
|
|
29
|
+
# This task runs every weekday at 9 AM.
|
|
31
30
|
await room.send(message="Good morning! Here's your weekday update!")
|
|
32
31
|
|
|
33
32
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""A simple, developer-friendly library to create powerful Matrix bots."""
|
|
2
2
|
|
|
3
|
-
__version__ = "1.0.
|
|
3
|
+
__version__ = "1.0.4-alpha"
|
|
4
4
|
|
|
5
5
|
from .bot import Bot
|
|
6
6
|
from .group import Group
|
|
@@ -9,6 +9,7 @@ from .context import Context
|
|
|
9
9
|
from .command import Command
|
|
10
10
|
from .help import HelpCommand
|
|
11
11
|
from .checks import cooldown
|
|
12
|
+
from .room import Room
|
|
12
13
|
|
|
13
14
|
__all__ = [
|
|
14
15
|
"Bot",
|
|
@@ -18,4 +19,5 @@ __all__ = [
|
|
|
18
19
|
"Context",
|
|
19
20
|
"HelpCommand",
|
|
20
21
|
"cooldown",
|
|
22
|
+
"Room",
|
|
21
23
|
]
|
|
@@ -33,12 +33,12 @@ from .help import HelpCommand, DefaultHelpCommand
|
|
|
33
33
|
from .scheduler import Scheduler
|
|
34
34
|
|
|
35
35
|
from .errors import (
|
|
36
|
+
GroupAlreadyRegisteredError,
|
|
36
37
|
AlreadyRegisteredError,
|
|
37
38
|
CommandNotFoundError,
|
|
38
39
|
CheckError,
|
|
39
40
|
)
|
|
40
41
|
|
|
41
|
-
|
|
42
42
|
Callback = Callable[..., Coroutine[Any, Any, Any]]
|
|
43
43
|
GroupCallable = Callable[[Callable[..., Coroutine[Any, Any, Any]]], Group]
|
|
44
44
|
ErrorCallback = Callable[[Exception], Coroutine]
|
|
@@ -192,7 +192,6 @@ class Bot:
|
|
|
192
192
|
name: Optional[str] = None,
|
|
193
193
|
*,
|
|
194
194
|
description: Optional[str] = None,
|
|
195
|
-
prefix: Optional[str] = None,
|
|
196
195
|
parent: Optional[str] = None,
|
|
197
196
|
usage: Optional[str] = None,
|
|
198
197
|
cooldown: Optional[tuple[int, float]] = None,
|
|
@@ -203,16 +202,13 @@ class Bot:
|
|
|
203
202
|
The command name defaults to the function name unless
|
|
204
203
|
explicitly provided.
|
|
205
204
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
:raises ValueError: If a command with the same name is registered.
|
|
214
|
-
:return: Decorator that registers the command handler.
|
|
215
|
-
:rtype: Callback
|
|
205
|
+
## Example
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
@bot.command(description="Returns pong!")
|
|
209
|
+
async def ping(ctx):
|
|
210
|
+
await ctx.reply("Pong!")
|
|
211
|
+
```
|
|
216
212
|
"""
|
|
217
213
|
|
|
218
214
|
def wrapper(func: Callback) -> Command:
|
|
@@ -220,7 +216,7 @@ class Bot:
|
|
|
220
216
|
func,
|
|
221
217
|
name=name,
|
|
222
218
|
description=description,
|
|
223
|
-
prefix=prefix,
|
|
219
|
+
prefix=self.prefix,
|
|
224
220
|
parent=parent,
|
|
225
221
|
usage=usage,
|
|
226
222
|
cooldown=cooldown,
|
|
@@ -229,6 +225,52 @@ class Bot:
|
|
|
229
225
|
|
|
230
226
|
return wrapper
|
|
231
227
|
|
|
228
|
+
def group(
|
|
229
|
+
self,
|
|
230
|
+
name: Optional[str] = None,
|
|
231
|
+
*,
|
|
232
|
+
description: Optional[str] = None,
|
|
233
|
+
parent: Optional[str] = None,
|
|
234
|
+
usage: Optional[str] = None,
|
|
235
|
+
cooldown: Optional[tuple[int, float]] = None,
|
|
236
|
+
) -> GroupCallable:
|
|
237
|
+
"""Decorator to register a coroutine function as a group handler.
|
|
238
|
+
|
|
239
|
+
The group name defaults to the function name unless
|
|
240
|
+
explicitly provided.
|
|
241
|
+
|
|
242
|
+
## Example
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
@bot.group(description="Group of mathematical commands")
|
|
246
|
+
async def math(ctx):
|
|
247
|
+
await ctx.reply("You called !math")
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@math.command()
|
|
251
|
+
async def add(ctx, a: int, b: int):
|
|
252
|
+
await ctx.reply(f"{a} + {b} = {a + b}")
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@math.command()
|
|
256
|
+
async def subtract(ctx, a: int, b: int):
|
|
257
|
+
await ctx.reply(f"{a} - {b} = {a - b}")
|
|
258
|
+
"""
|
|
259
|
+
|
|
260
|
+
def wrapper(func: Callback) -> Group:
|
|
261
|
+
group = Group(
|
|
262
|
+
func,
|
|
263
|
+
name=name,
|
|
264
|
+
description=description,
|
|
265
|
+
prefix=self.prefix,
|
|
266
|
+
parent=parent,
|
|
267
|
+
usage=usage,
|
|
268
|
+
cooldown=cooldown,
|
|
269
|
+
)
|
|
270
|
+
return self.register_group(group)
|
|
271
|
+
|
|
272
|
+
return wrapper
|
|
273
|
+
|
|
232
274
|
def schedule(self, cron: str) -> Callable[..., Callback]:
|
|
233
275
|
"""
|
|
234
276
|
Decorator to register a coroutine function as a scheduled task.
|
|
@@ -261,6 +303,14 @@ class Bot:
|
|
|
261
303
|
|
|
262
304
|
return cmd
|
|
263
305
|
|
|
306
|
+
def register_group(self, group: Group) -> Group:
|
|
307
|
+
if group in self.commands:
|
|
308
|
+
raise GroupAlreadyRegisteredError(group)
|
|
309
|
+
|
|
310
|
+
self.commands[group.name] = group
|
|
311
|
+
self.log.debug("group '%s' registered", group)
|
|
312
|
+
return group
|
|
313
|
+
|
|
264
314
|
def error(self, exception: Optional[type[Exception]] = None) -> Callable:
|
|
265
315
|
"""
|
|
266
316
|
Decorator to register a custom error handler for commands.
|
|
@@ -14,10 +14,28 @@ ErrorCallback = Callable[["Context", Exception], Coroutine[Any, Any, Any]]
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
class Group(Command):
|
|
17
|
-
def __init__(
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
callback: Callback,
|
|
20
|
+
*,
|
|
21
|
+
name: Optional[str] = None,
|
|
22
|
+
description: Optional[str] = None,
|
|
23
|
+
prefix: Optional[str] = None,
|
|
24
|
+
parent: Optional[str] = None,
|
|
25
|
+
usage: Optional[str] = None,
|
|
26
|
+
cooldown: Optional[tuple[int, float]] = None,
|
|
27
|
+
):
|
|
18
28
|
self.commands: Dict[str, Command] = {}
|
|
19
29
|
|
|
20
|
-
super().__init__(
|
|
30
|
+
super().__init__(
|
|
31
|
+
callback,
|
|
32
|
+
name=name,
|
|
33
|
+
description=description,
|
|
34
|
+
prefix=prefix,
|
|
35
|
+
parent=parent,
|
|
36
|
+
usage=usage,
|
|
37
|
+
cooldown=cooldown,
|
|
38
|
+
)
|
|
21
39
|
|
|
22
40
|
def _build_usage(self) -> str:
|
|
23
41
|
return f"{self.prefix}{self.name} [subcommand]"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: matrix-python
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.4a0
|
|
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>
|
|
@@ -9,10 +9,11 @@ pyproject.toml
|
|
|
9
9
|
.github/workflows/publish.yml
|
|
10
10
|
.github/workflows/scorecard.yml
|
|
11
11
|
.github/workflows/tests.yml
|
|
12
|
+
examples/README.md
|
|
12
13
|
examples/checks.py
|
|
13
14
|
examples/config.yaml
|
|
14
15
|
examples/cooldown.py
|
|
15
|
-
examples/
|
|
16
|
+
examples/error_handling.py
|
|
16
17
|
examples/ping.py
|
|
17
18
|
examples/reaction.py
|
|
18
19
|
examples/scheduler.py
|
|
@@ -42,7 +43,6 @@ tests/test_command.py
|
|
|
42
43
|
tests/test_config.py
|
|
43
44
|
tests/test_context.py
|
|
44
45
|
tests/test_group.py
|
|
45
|
-
tests/test_help.py
|
|
46
46
|
tests/test_message.py
|
|
47
47
|
tests/test_room.py
|
|
48
48
|
tests/help/test_default_help_command.py
|
|
@@ -3,7 +3,7 @@ requires = ["setuptools>=64", "setuptools_scm>=8"]
|
|
|
3
3
|
|
|
4
4
|
[project]
|
|
5
5
|
name = "matrix-python"
|
|
6
|
-
version = "1.0.
|
|
6
|
+
version = "1.0.4-alpha"
|
|
7
7
|
authors = [
|
|
8
8
|
{ name="Simon Roy" },
|
|
9
9
|
{ name=" Chris Dedman Rollet " }
|
|
@@ -41,4 +41,4 @@ dev = [
|
|
|
41
41
|
|
|
42
42
|
[tool.setuptools]
|
|
43
43
|
packages = ["matrix"]
|
|
44
|
-
license-files = []
|
|
44
|
+
license-files = []
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
from matrix import Bot, Context, cooldown
|
|
2
|
-
from matrix.errors import CooldownError
|
|
3
|
-
|
|
4
|
-
bot = Bot("examples/config.yaml")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@bot.command(cooldown=(2, 15))
|
|
8
|
-
async def cooldown_command(ctx):
|
|
9
|
-
await ctx.reply("This is limited to 2 uses per 15s per user.")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@cooldown_command.error(CooldownError)
|
|
13
|
-
async def cooldown_error(ctx, error):
|
|
14
|
-
print(f"CooldownError invoked: Try again in {error.retry:.1f} seconds.")
|
|
15
|
-
await ctx.reply(f"⏳ Try again in {error.retry:.1f}s")
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@cooldown(2, 10)
|
|
19
|
-
@bot.command("hi")
|
|
20
|
-
async def hello(ctx: Context):
|
|
21
|
-
print(f"{ctx.sender} invoked {ctx.body} in room {ctx.room_name}.")
|
|
22
|
-
await ctx.reply("Hello World.")
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@hello.error(CooldownError)
|
|
26
|
-
async def hello_error(ctx, error):
|
|
27
|
-
print(f"CooldownError invoked: Try again in {error.retry:.1f} seconds.")
|
|
28
|
-
await ctx.reply(f"⏳ Try again in {error.retry:.1f}s")
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
bot.start()
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
from matrix import Bot, Context
|
|
2
|
-
from matrix.errors import CommandNotFoundError, MissingArgumentError
|
|
3
|
-
|
|
4
|
-
bot = Bot("examples/config.yaml")
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
@bot.error(CommandNotFoundError)
|
|
8
|
-
async def global_error(error):
|
|
9
|
-
print(f"Glable error handler {error}.")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
@bot.command("div")
|
|
13
|
-
async def division(ctx: Context, a: int, b: int):
|
|
14
|
-
c = a / b
|
|
15
|
-
await ctx.reply(c)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@division.error(ZeroDivisionError)
|
|
19
|
-
async def div_error(ctx, error):
|
|
20
|
-
print(f"Operation Not Allowed: {error}")
|
|
21
|
-
await ctx.reply(f"Operation not allowed: {error}")
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
@division.error(ValueError)
|
|
25
|
-
async def val_error(ctx, error):
|
|
26
|
-
print(f"ValueError: {error}")
|
|
27
|
-
await ctx.reply(f"ValueError: {error}")
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
@division.error(MissingArgumentError)
|
|
31
|
-
async def command_error(ctx, error):
|
|
32
|
-
print(error)
|
|
33
|
-
await ctx.reply(error)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
bot.start()
|
|
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
|