From 2c5d3607f39a711e67f91222b6743993bdaee433 Mon Sep 17 00:00:00 2001 From: lomion Date: Tue, 23 Jun 2020 20:12:43 +0200 Subject: [PATCH] Changed release to 0.1.0 Some flake8 improvements --- maubot.yaml | 2 +- tmdb/tmdb.py | 24 ++++++++++++------------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/maubot.yaml b/maubot.yaml index 9784f72..5009c62 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -1,6 +1,6 @@ maubot: 0.1.0 id: lomion.tmdb -version: 0.0.3 +version: 0.1.0 license: AGPL 3.0 modules: - tmdb diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index 59613ba..f20af64 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -15,23 +15,24 @@ along with tmdb-bot. If not, see . ''' from html import escape -from mautrix.types import TextMessageEventContent, MediaMessageEventContent, MessageType, Format, RelatesTo, RelationType +from mautrix.types import TextMessageEventContent, MediaMessageEventContent, MessageType, Format from maubot import Plugin, MessageEvent from maubot.handlers import command from tmdb.tmdb_api import Movie -from sqlalchemy import (Column, String, Integer, ForeignKey, Table, MetaData, - select, and_) +from sqlalchemy import (Column, String, Integer, Table, MetaData, + select) from sqlalchemy.engine.base import Engine + class Database: db: Engine def __init__(self, db: Engine) -> None: self.db = db - + meta = MetaData() meta.bind = db @@ -40,24 +41,25 @@ class Database: Column("user_id", String(255), nullable=False), Column("language", String(255), nullable=False),) meta.create_all(db) - + def set_language(self, user_id, language): with self.db.begin() as tx: tx.execute(self.language.delete().where(self.language.c.user_id == user_id)) tx.execute(self.language.insert().values(user_id=user_id, language=language)) - + def get_language(self, user_id): rows = self.db.execute(select([self.language.c.language]) - .where(self.language.c.user_id == user_id)) + .where(self.language.c.user_id == user_id)) return rows.fetchone() + class TmdbBot(Plugin): db: Database async def start(self) -> None: await super().start() self.db = Database(self.database) - + async def send_movie_info(self, evt: MessageEvent, movie) -> None: mxc_uri = await self.client.upload_media(data=movie.get_image_binary()) text_message = f'{movie.title}' @@ -67,7 +69,7 @@ class TmdbBot(Plugin): three_dotts = "" cast = "Acting: " for actor in movie.cast[:3]: - cast+= f'{actor}, ' + cast += f'{actor}, ' cast = cast[:-2] html_message = f"""

{escape(movie.title)}

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

@@ -84,7 +86,6 @@ class TmdbBot(Plugin): url=f"{mxc_uri}") await evt.respond(content) - @command.new("movie-id", help="Movie lookup by id") @command.argument("message", pass_raw=True, required=True) async def movie_id(self, evt: MessageEvent, message: str = "") -> None: @@ -95,7 +96,6 @@ class TmdbBot(Plugin): movie.query_details(message) await self.send_movie_info(evt, movie) - @command.new("movie-search", help="Movie lookup by Title") @command.argument("message", pass_raw=True, required=True) async def movie_search(self, evt: MessageEvent, message: str = "") -> None: @@ -119,4 +119,4 @@ class TmdbBot(Plugin): content = TextMessageEventContent( msgtype=MessageType.NOTICE, format=Format.HTML, body=f"Language set to {message}!") - await evt.respond(content) + await evt.respond(content)