AI ニジカ綜合
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.

101 lines
2.0 KiB

  1. from __future__ import annotations
  2. from datetime import datetime
  3. from eloquent import Model # type: ignore
  4. class AnsweredFlag (Model):
  5. id: int
  6. answer_id: int
  7. platform: int
  8. answered: bool
  9. __timestamps__ = False
  10. @property
  11. def answer (
  12. self,
  13. ) -> Answer:
  14. return self.belongs_to (Answer)
  15. class Answer (Model):
  16. id: int
  17. query_id: int
  18. character: int
  19. content: str
  20. answer_type: int
  21. sent_at: datetime
  22. __timestamps__ = False
  23. @property
  24. def query (
  25. self,
  26. ) -> Query:
  27. return self.belongs_to (Query)
  28. def answered (
  29. self,
  30. platform: int,
  31. ) -> bool | None:
  32. answered_flag = (AnsweredFlag.where ('answer_id', self.id)
  33. .where ('platform', platform)
  34. .first ())
  35. if answered_flag is None:
  36. return None
  37. return answered_flag.answered
  38. class Query (Model):
  39. id: int
  40. user_id: int | None
  41. target_character: int
  42. content: str
  43. image_url: str | None
  44. query_type: int
  45. model: int
  46. sent_at: datetime
  47. answered: bool
  48. __timestamps__ = False
  49. @property
  50. def user (
  51. self,
  52. ) -> User:
  53. return self.belongs_to (User)
  54. @property
  55. def answer_histories (
  56. self,
  57. ) -> list[Answer]:
  58. return [x.answer for x in self.has_many (QueryAnswerHistory).get ()]
  59. class QueryAnswerHistory (Model):
  60. id: int
  61. query_id: int
  62. answer_id: int
  63. @property
  64. def query (
  65. self,
  66. ) -> Query:
  67. return self.belongs_to (Query)
  68. @property
  69. def answer (
  70. self,
  71. ) -> Answer:
  72. return self.belongs_to (Answer)
  73. class User (Model):
  74. id: int
  75. platform: int
  76. code: str
  77. name: str
  78. icon: bytes