Skip to content

Commit

Permalink
Update to use new command handling system
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 24, 2018
1 parent a4d0b3b commit 3a981fb
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions media.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
from maubot import Plugin, CommandSpec, PassiveCommand, MessageEvent
from typing import Tuple

COMMAND_MEDIA = "xyz.maubot.media"
from mautrix.types import MessageType
from maubot import Plugin, MessageEvent
from maubot.handlers import command


class MediaBot(Plugin):
async def start(self) -> None:
self.set_command_spec(CommandSpec(
passive_commands=[PassiveCommand(
name=COMMAND_MEDIA,
matches="mxc://.+/.+",
match_against="url",
)],
))
self.client.add_command_handler(COMMAND_MEDIA, self.handler)

async def stop(self) -> None:
self.client.remove_command_handler(COMMAND_MEDIA, self.handler)

@staticmethod
async def handler(evt: MessageEvent) -> None:
await evt.respond(f"MXC URI: `{evt.content.url}`")
@command.passive("^mxc://.+/.+$", field=lambda evt: evt.content.url,
msgtypes=(MessageType.IMAGE, MessageType.FILE, MessageType.AUDIO,
MessageType.STICKER))
async def handler(self, evt: MessageEvent, url: Tuple[str]) -> None:
await evt.respond(f"MXC URI: `{url[0]}`")

0 comments on commit 3a981fb

Please sign in to comment.