forked from fair/matrix-puppeteer-line
Andrew Ferrazzutti
6d646e082b
- Handle "decrypting" state of messages - Handle lazy loading of emoji - Better handle lazy loading of images/stickers - Improve reliability of message sending, especially when sending several messages quickly - Use m.sticker events for inbound stickers instead of m.image, and add a config to optionally use m.image if desired - Use proper sizing for emoji, and add config to scale them since they are somewhat small - Deduplicate stickers as best as possible (works until they get a different blob URL) - Add config to disable bridging stickers/emoji - Send m.notice for inbound messages of unknown type
54 lines
1.9 KiB
Python
54 lines
1.9 KiB
Python
# matrix-puppeteer-line - A very hacky Matrix-LINE bridge based on running LINE's Chrome extension in Puppeteer
|
|
# Copyright (C) 2020-2021 Tulir Asokan, Andrew Ferrazzutti
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
from typing import Optional, ClassVar, TYPE_CHECKING
|
|
|
|
from attr import dataclass
|
|
|
|
from mautrix.types import ContentURI
|
|
from mautrix.util.async_db import Database
|
|
|
|
fake_db = Database("") if TYPE_CHECKING else None
|
|
|
|
|
|
@dataclass
|
|
class Media:
|
|
db: ClassVar[Database] = fake_db
|
|
|
|
media_id: str
|
|
mxc: ContentURI
|
|
mime_type: str
|
|
file_name: str
|
|
size: int
|
|
|
|
async def insert(self) -> None:
|
|
q = ("INSERT INTO media (media_id, mxc, mime_type, file_name, size) "
|
|
"VALUES ($1, $2, $3, $4, $5)")
|
|
await self.db.execute(q, self.media_id, self.mxc, self.mime_type, self.file_name, self.size)
|
|
|
|
async def update(self) -> None:
|
|
q = ("UPDATE media SET mxc=$2 "
|
|
"WHERE media_id=$1")
|
|
await self.db.execute(q, self.media_id, self.mxc)
|
|
|
|
@classmethod
|
|
async def get_by_id(cls, media_id: str) -> Optional['DBMedia']:
|
|
q = ("SELECT media_id, mxc, mime_type, file_name, size "
|
|
"FROM media WHERE media_id=$1")
|
|
row = await cls.db.fetchrow(q, media_id)
|
|
if not row:
|
|
return None
|
|
return cls(**row)
|