diff --git a/maubot.yaml b/maubot.yaml index 9784f72..92fe944 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: lomion.tmdb -version: 0.0.3 +version: 0.2.0 license: AGPL 3.0 modules: - tmdb diff --git a/test_tmdb.py b/test_tmdb.py index f037b8e..123c241 100644 --- a/test_tmdb.py +++ b/test_tmdb.py @@ -44,7 +44,7 @@ class TestTmdbMethods(unittest.TestCase): self.assertEqual(message, """

Fight Club

Ein Yuppie [...]

Acting: Edward Norton, Brad Pitt, Helena Bonham Carter

-

taken from www.themoviedb.org

""") +

Taken from www.themoviedb.org

""") def test_database_language(self): engine = create_engine('sqlite:///test.db', echo = True) diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index b07698c..4d9a8d1 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -20,7 +20,7 @@ from mautrix.types import TextMessageEventContent, MediaMessageEventContent, Mes from maubot import Plugin, MessageEvent from maubot.handlers import command -from tmdb.tmdb_api import Movie +from tmdb.tmdb_api import Movie, TvShow from tmdb.database import Database @@ -31,14 +31,14 @@ class TmdbBot(Plugin): await super().start() self.db = Database(self.database) - async def send_html_message(self, text_message, html_message) -> None: + async def send_html_message(self, evt: MessageEvent, text_message, html_message) -> None: content = TextMessageEventContent( msgtype=MessageType.TEXT, format=Format.HTML, body=f"{text_message}", formatted_body=f"{html_message}") await evt.respond(content) - async def send_image(self, title, image) -> None: + async def send_image(self, evt: MessageEvent, title, image) -> None: mxc_uri = await self.client.upload_media(image) content = MediaMessageEventContent( msgtype=MessageType.IMAGE, @@ -59,13 +59,13 @@ class TmdbBot(Plugin): html_message = f"""

{escape(movie.title)}

{escape(movie.overview)[:overview_length]}{three_dotts}

{cast}

-

taken from www.themoviedb.org

""" +

Taken from www.themoviedb.org

""" return html_message async def send_movie_info(self, evt: MessageEvent, movie) -> None: html_message = self.construct_html_message(movie) - await self.send_html_message(f'{movie.title}', html_message) - await self.send_image(movie.title, movie.get_image_binary()) + await self.send_html_message(evt, f'{movie.title}', html_message) + await self.send_image(evt, movie.title, movie.get_image_binary()) @command.new("movie-id", help="Movie lookup by id") @@ -103,3 +103,19 @@ class TmdbBot(Plugin): msgtype=MessageType.NOTICE, format=Format.HTML, body=f"Language set to {message}!") await evt.respond(content) + + @command.new("tvshow-search", help="TV Show lookup by Title") + @command.argument("message", pass_raw=True, required=True) + async def tvshow_search(self, evt: MessageEvent, message: str = "") -> None: + movie = TvShow() + language = self.db.get_language(evt.sender) + if language: + movie.set_language(language) + movie.search_title(message) + if movie.valid: + await self.send_movie_info(evt, movie) + else: + content = TextMessageEventContent( + msgtype=MessageType.NOTICE, format=Format.HTML, + body=f"No tv show found!") + await evt.respond(content) \ No newline at end of file