Compare commits

...

8 Commits

Author SHA1 Message Date
Ruby Marx
c6e7a302ae
Merge f63be9059b into 91f214819a 2024-04-09 00:56:04 +01:00
Tulir Asokan
91f214819a Update .gitignore 2024-03-30 23:37:07 +02:00
Tulir Asokan
299d8f68c3 Update changelog again 2024-03-30 23:36:54 +02:00
Tulir Asokan
a7f31f6175 Only include directories with __init__.py when building mbp file 2024-03-30 23:32:08 +02:00
Tulir Asokan
4f68e20ff7 Update changelog 2024-03-30 23:31:48 +02:00
Tulir Asokan
7759643e93 Assume main class is in last module instead of first 2024-03-30 23:31:40 +02:00
Tulir Asokan
2c60342cc6 Update plugin list link 2024-03-10 17:10:41 +02:00
MxMarx
f63be9059b automatically decrypt get_event_context() 2023-09-30 18:08:07 -07:00
7 changed files with 45 additions and 6 deletions

1
.gitignore vendored
View File

@ -13,6 +13,7 @@ __pycache__
!example-config.yaml !example-config.yaml
!.pre-commit-config.yaml !.pre-commit-config.yaml
/start
logs/ logs/
plugins/ plugins/
trash/ trash/

View File

@ -1,3 +1,21 @@
# v0.5.0 (unreleased)
* Fixed `main_class` to default to being loaded from the last module instead of
the first if a module name is not explicitly specified.
* This was already the [documented behavior](https://docs.mau.fi/maubot/dev/reference/plugin-metadata.html),
and loading from the first module doesn't make sense due to import order.
* Added simple scheduler utility for running background tasks periodically or
after a certain delay.
* Added testing framework for plugins (thanks to [@abompard] in [#225]).
* Changed `mbc build` to ignore directories declared in `modules` that are
missing an `__init__.py` file.
* Importing the modules at runtime would fail and break the plugin.
To include non-code resources outside modules in the mbp archive,
use `extra_files` instead.
[#225]: https://github.com/maubot/maubot/issues/225
[@abompard]: https://github.com/abompard
# v0.4.2 (2023-09-20) # v0.4.2 (2023-09-20)
* Updated Pillow to 10.0.1. * Updated Pillow to 10.0.1.

View File

@ -22,7 +22,7 @@ All setup and usage instructions are located on
Matrix room: [#maubot:maunium.net](https://matrix.to/#/#maubot:maunium.net) Matrix room: [#maubot:maunium.net](https://matrix.to/#/#maubot:maunium.net)
## Plugins ## Plugins
A list of plugins can be found at [plugins.maubot.xyz](https://plugins.maubot.xyz/). A list of plugins can be found at [plugins.mau.bot](https://plugins.mau.bot/).
To add your plugin to the list, send a pull request to <https://github.com/maubot/plugins.maubot.xyz>. To add your plugin to the list, send a pull request to <https://github.com/maubot/plugins.maubot.xyz>.

View File

@ -93,10 +93,16 @@ def write_plugin(meta: PluginMeta, output: str | IO) -> None:
if os.path.isfile(f"{module}.py"): if os.path.isfile(f"{module}.py"):
zip.write(f"{module}.py") zip.write(f"{module}.py")
elif module is not None and os.path.isdir(module): elif module is not None and os.path.isdir(module):
zipdir(zip, module) if os.path.isfile(f"{module}/__init__.py"):
zipdir(zip, module)
else:
print(
Fore.YELLOW
+ f"Module {module} is missing __init__.py, skipping"
+ Fore.RESET
)
else: else:
print(Fore.YELLOW + f"Module {module} not found, skipping" + Fore.RESET) print(Fore.YELLOW + f"Module {module} not found, skipping" + Fore.RESET)
for pattern in meta.extra_files: for pattern in meta.extra_files:
for file in glob.iglob(pattern): for file in glob.iglob(pattern):
zip.write(file) zip.write(file)

View File

@ -167,7 +167,7 @@ class ZippedPluginLoader(PluginLoader):
if "/" in meta.main_class: if "/" in meta.main_class:
self.main_module, self.main_class = meta.main_class.split("/")[:2] self.main_module, self.main_class = meta.main_class.split("/")[:2]
else: else:
self.main_module = meta.modules[0] self.main_module = meta.modules[-1]
self.main_class = meta.main_class self.main_class = meta.main_class
self._file = file self._file = file

View File

@ -36,6 +36,8 @@ from mautrix.types import (
RelatesTo, RelatesTo,
RoomID, RoomID,
TextMessageEventContent, TextMessageEventContent,
EventContext,
RoomEventFilter,
) )
from mautrix.util import markdown from mautrix.util import markdown
from mautrix.util.formatter import EntityType, MarkdownString, MatrixParser from mautrix.util.formatter import EntityType, MarkdownString, MatrixParser
@ -278,7 +280,19 @@ class MaubotMatrixClient(MatrixClient):
return super().dispatch_event(event, source) return super().dispatch_event(event, source)
async def get_event(self, room_id: RoomID, event_id: EventID) -> Event: async def get_event(self, room_id: RoomID, event_id: EventID) -> Event:
evt = await super().get_event(room_id, event_id) return await self._decrypt_event(await super().get_event(room_id, event_id))
async def get_event_context(self, room_id: RoomID, event_id: EventID, limit: int | None = 10,
filter: RoomEventFilter | None = None) -> EventContext:
event_context = await super().get_event_context(room_id=room_id,event_id=event_id,
limit=limit,filter=filter)
event_context.events_after = [await self._decrypt_event(evt)
for evt in event_context.events_after]
event_context.events_before = [await self._decrypt_event(evt)
for evt in event_context.events_before]
return event_context
async def _decrypt_event(self, evt: Event):
if isinstance(evt, EncryptedEvent) and self.crypto: if isinstance(evt, EncryptedEvent) and self.crypto:
try: try:
self.crypto_log.trace(f"get_event: Decrypting {evt.event_id} in {evt.room_id}...") self.crypto_log.trace(f"get_event: Decrypting {evt.event_id} in {evt.room_id}...")

View File

@ -115,7 +115,7 @@ with open(args.meta, "r") as meta_file:
if "/" in meta.main_class: if "/" in meta.main_class:
module, main_class = meta.main_class.split("/", 1) module, main_class = meta.main_class.split("/", 1)
else: else:
module = meta.modules[0] module = meta.modules[-1]
main_class = meta.main_class main_class = meta.main_class
if args.meta != "maubot.yaml" and os.path.dirname(args.meta) != "": if args.meta != "maubot.yaml" and os.path.dirname(args.meta) != "":