Changed release to 0.1.0
Some flake8 improvements
This commit is contained in:
parent
c698cafa02
commit
2c5d3607f3
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: lomion.tmdb
|
id: lomion.tmdb
|
||||||
version: 0.0.3
|
version: 0.1.0
|
||||||
license: AGPL 3.0
|
license: AGPL 3.0
|
||||||
modules:
|
modules:
|
||||||
- tmdb
|
- tmdb
|
||||||
|
|
24
tmdb/tmdb.py
24
tmdb/tmdb.py
|
@ -15,23 +15,24 @@ along with tmdb-bot. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
from html import escape
|
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 import Plugin, MessageEvent
|
||||||
from maubot.handlers import command
|
from maubot.handlers import command
|
||||||
|
|
||||||
from tmdb.tmdb_api import Movie
|
from tmdb.tmdb_api import Movie
|
||||||
|
|
||||||
from sqlalchemy import (Column, String, Integer, ForeignKey, Table, MetaData,
|
from sqlalchemy import (Column, String, Integer, Table, MetaData,
|
||||||
select, and_)
|
select)
|
||||||
from sqlalchemy.engine.base import Engine
|
from sqlalchemy.engine.base import Engine
|
||||||
|
|
||||||
|
|
||||||
class Database:
|
class Database:
|
||||||
db: Engine
|
db: Engine
|
||||||
|
|
||||||
def __init__(self, db: Engine) -> None:
|
def __init__(self, db: Engine) -> None:
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
||||||
meta = MetaData()
|
meta = MetaData()
|
||||||
meta.bind = db
|
meta.bind = db
|
||||||
|
|
||||||
|
@ -40,24 +41,25 @@ class Database:
|
||||||
Column("user_id", String(255), nullable=False),
|
Column("user_id", String(255), nullable=False),
|
||||||
Column("language", String(255), nullable=False),)
|
Column("language", String(255), nullable=False),)
|
||||||
meta.create_all(db)
|
meta.create_all(db)
|
||||||
|
|
||||||
def set_language(self, user_id, language):
|
def set_language(self, user_id, language):
|
||||||
with self.db.begin() as tx:
|
with self.db.begin() as tx:
|
||||||
tx.execute(self.language.delete().where(self.language.c.user_id == user_id))
|
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))
|
tx.execute(self.language.insert().values(user_id=user_id, language=language))
|
||||||
|
|
||||||
def get_language(self, user_id):
|
def get_language(self, user_id):
|
||||||
rows = self.db.execute(select([self.language.c.language])
|
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()
|
return rows.fetchone()
|
||||||
|
|
||||||
|
|
||||||
class TmdbBot(Plugin):
|
class TmdbBot(Plugin):
|
||||||
db: Database
|
db: Database
|
||||||
|
|
||||||
async def start(self) -> None:
|
async def start(self) -> None:
|
||||||
await super().start()
|
await super().start()
|
||||||
self.db = Database(self.database)
|
self.db = Database(self.database)
|
||||||
|
|
||||||
async def send_movie_info(self, evt: MessageEvent, movie) -> None:
|
async def send_movie_info(self, evt: MessageEvent, movie) -> None:
|
||||||
mxc_uri = await self.client.upload_media(data=movie.get_image_binary())
|
mxc_uri = await self.client.upload_media(data=movie.get_image_binary())
|
||||||
text_message = f'{movie.title}'
|
text_message = f'{movie.title}'
|
||||||
|
@ -67,7 +69,7 @@ class TmdbBot(Plugin):
|
||||||
three_dotts = ""
|
three_dotts = ""
|
||||||
cast = "Acting: "
|
cast = "Acting: "
|
||||||
for actor in movie.cast[:3]:
|
for actor in movie.cast[:3]:
|
||||||
cast+= f'{actor}, '
|
cast += f'{actor}, '
|
||||||
cast = cast[:-2]
|
cast = cast[:-2]
|
||||||
html_message = f"""<p><b>{escape(movie.title)}</b></p>
|
html_message = f"""<p><b>{escape(movie.title)}</b></p>
|
||||||
<p>{escape(movie.overview)[:200]}{three_dotts}</p>
|
<p>{escape(movie.overview)[:200]}{three_dotts}</p>
|
||||||
|
@ -84,7 +86,6 @@ class TmdbBot(Plugin):
|
||||||
url=f"{mxc_uri}")
|
url=f"{mxc_uri}")
|
||||||
await evt.respond(content)
|
await evt.respond(content)
|
||||||
|
|
||||||
|
|
||||||
@command.new("movie-id", help="Movie lookup by id")
|
@command.new("movie-id", help="Movie lookup by id")
|
||||||
@command.argument("message", pass_raw=True, required=True)
|
@command.argument("message", pass_raw=True, required=True)
|
||||||
async def movie_id(self, evt: MessageEvent, message: str = "") -> None:
|
async def movie_id(self, evt: MessageEvent, message: str = "") -> None:
|
||||||
|
@ -95,7 +96,6 @@ class TmdbBot(Plugin):
|
||||||
movie.query_details(message)
|
movie.query_details(message)
|
||||||
await self.send_movie_info(evt, movie)
|
await self.send_movie_info(evt, movie)
|
||||||
|
|
||||||
|
|
||||||
@command.new("movie-search", help="Movie lookup by Title")
|
@command.new("movie-search", help="Movie lookup by Title")
|
||||||
@command.argument("message", pass_raw=True, required=True)
|
@command.argument("message", pass_raw=True, required=True)
|
||||||
async def movie_search(self, evt: MessageEvent, message: str = "") -> None:
|
async def movie_search(self, evt: MessageEvent, message: str = "") -> None:
|
||||||
|
@ -119,4 +119,4 @@ class TmdbBot(Plugin):
|
||||||
content = TextMessageEventContent(
|
content = TextMessageEventContent(
|
||||||
msgtype=MessageType.NOTICE, format=Format.HTML,
|
msgtype=MessageType.NOTICE, format=Format.HTML,
|
||||||
body=f"Language set to {message}!")
|
body=f"Language set to {message}!")
|
||||||
await evt.respond(content)
|
await evt.respond(content)
|
||||||
|
|
Loading…
Reference in a new issue