You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.7 KiB

  1. # maunium-stickerpicker - A fast and simple Matrix sticker picker widget.
  2. # Copyright (C) 2020 Tulir Asokan
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. from typing import Dict, Any
  17. from attr import dataclass
  18. import attr
  19. from mautrix.types import ContentURI
  20. from .base import Base
  21. @dataclass(kw_only=True)
  22. class Sticker(Base):
  23. pack_id: str
  24. order: int
  25. id: str
  26. url: ContentURI = attr.ib(order=False)
  27. body: str = attr.ib(order=False)
  28. meta: Dict[str, Any] = attr.ib(order=False)
  29. async def delete(self) -> None:
  30. await self.db.execute("DELETE FROM sticker WHERE id=$1", self.id)
  31. async def insert(self) -> None:
  32. await self.db.execute('INSERT INTO sticker (id, pack_id, url, body, meta, "order") '
  33. "VALUES ($1, $2, $3, $4, $5, $6)",
  34. self.id, self.pack_id, self.url, self.body, self.meta, self.order)
  35. def to_dict(self) -> Dict[str, Any]:
  36. return {
  37. **self.meta,
  38. "body": self.body,
  39. "url": self.url,
  40. "id": self.id,
  41. }