types.nim 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # SPDX-License-Identifier: AGPL-3.0-only
  2. import times, sequtils, options, tables
  3. import prefs_impl
  4. genPrefsType()
  5. type
  6. RateLimitError* = object of CatchableError
  7. InternalError* = object of CatchableError
  8. Api* {.pure.} = enum
  9. userShow
  10. photoRail
  11. timeline
  12. search
  13. tweet
  14. list
  15. listBySlug
  16. listMembers
  17. RateLimit* = object
  18. remaining*: int
  19. reset*: int
  20. Token* = ref object
  21. tok*: string
  22. init*: Time
  23. lastUse*: Time
  24. pending*: int
  25. apis*: Table[Api, RateLimit]
  26. Error* = enum
  27. null = 0
  28. noUserMatches = 17
  29. protectedUser = 22
  30. couldntAuth = 32
  31. doesntExist = 34
  32. userNotFound = 50
  33. suspended = 63
  34. rateLimited = 88
  35. invalidToken = 89
  36. listIdOrSlug = 112
  37. forbidden = 200
  38. badToken = 239
  39. noCsrf = 353
  40. Profile* = object
  41. id*: string
  42. username*: string
  43. fullname*: string
  44. lowername*: string
  45. location*: string
  46. website*: string
  47. bio*: string
  48. userPic*: string
  49. banner*: string
  50. following*: string
  51. followers*: string
  52. tweets*: string
  53. likes*: string
  54. media*: string
  55. verified*: bool
  56. protected*: bool
  57. suspended*: bool
  58. joinDate*: DateTime
  59. VideoType* = enum
  60. m3u8 = "application/x-mpegURL"
  61. mp4 = "video/mp4"
  62. vmap = "video/vmap"
  63. VideoVariant* = object
  64. contentType*: VideoType
  65. url*: string
  66. bitrate*: int
  67. Video* = object
  68. durationMs*: int
  69. url*: string
  70. thumb*: string
  71. views*: string
  72. available*: bool
  73. reason*: string
  74. title*: string
  75. description*: string
  76. playbackType*: VideoType
  77. variants*: seq[VideoVariant]
  78. QueryKind* = enum
  79. posts, replies, media, users, tweets, userList
  80. Query* = object
  81. kind*: QueryKind
  82. text*: string
  83. filters*: seq[string]
  84. includes*: seq[string]
  85. excludes*: seq[string]
  86. fromUser*: seq[string]
  87. since*: string
  88. until*: string
  89. near*: string
  90. sep*: string
  91. Gif* = object
  92. url*: string
  93. thumb*: string
  94. GalleryPhoto* = object
  95. url*: string
  96. tweetId*: string
  97. color*: string
  98. PhotoRail* = seq[GalleryPhoto]
  99. Poll* = object
  100. options*: seq[string]
  101. values*: seq[int]
  102. votes*: int
  103. leader*: int
  104. status*: string
  105. CardKind* = enum
  106. amplify = "amplify"
  107. app = "app"
  108. appPlayer = "appplayer"
  109. player = "player"
  110. summary = "summary"
  111. summaryLarge = "summary_large_image"
  112. promoWebsite = "promo_website"
  113. promoVideo = "promo_video_website"
  114. promoVideoConvo = "promo_video_convo"
  115. promoImageConvo = "promo_image_convo"
  116. promoImageApp = "promo_image_app"
  117. storeLink = "direct_store_link_app"
  118. liveEvent = "live_event"
  119. broadcast = "broadcast"
  120. periscope = "periscope_broadcast"
  121. unified = "unified_card"
  122. moment = "moment"
  123. messageMe = "message_me"
  124. videoDirectMessage = "video_direct_message"
  125. imageDirectMessage = "image_direct_message"
  126. audiospace = "audiospace"
  127. newsletterPublication = "newsletter_publication"
  128. unknown
  129. Card* = object
  130. kind*: CardKind
  131. url*: string
  132. title*: string
  133. dest*: string
  134. text*: string
  135. image*: string
  136. video*: Option[Video]
  137. TweetStats* = object
  138. replies*: int
  139. retweets*: int
  140. likes*: int
  141. quotes*: int
  142. Tweet* = ref object
  143. id*: int64
  144. threadId*: int64
  145. replyId*: int64
  146. profile*: Profile
  147. text*: string
  148. time*: DateTime
  149. reply*: seq[string]
  150. pinned*: bool
  151. hasThread*: bool
  152. available*: bool
  153. tombstone*: string
  154. location*: string
  155. stats*: TweetStats
  156. retweet*: Option[Tweet]
  157. attribution*: Option[Profile]
  158. mediaTags*: seq[Profile]
  159. quote*: Option[Tweet]
  160. card*: Option[Card]
  161. poll*: Option[Poll]
  162. gif*: Option[Gif]
  163. video*: Option[Video]
  164. photos*: seq[string]
  165. Result*[T] = object
  166. content*: seq[T]
  167. top*, bottom*: string
  168. beginning*: bool
  169. query*: Query
  170. Chain* = object
  171. content*: seq[Tweet]
  172. more*: int64
  173. cursor*: string
  174. Conversation* = ref object
  175. tweet*: Tweet
  176. before*: Chain
  177. after*: Chain
  178. replies*: Result[Chain]
  179. Timeline* = Result[Tweet]
  180. List* = object
  181. id*: string
  182. name*: string
  183. userId*: string
  184. username*: string
  185. description*: string
  186. members*: int
  187. banner*: string
  188. GlobalObjects* = ref object
  189. tweets*: Table[string, Tweet]
  190. users*: Table[string, Profile]
  191. Config* = ref object
  192. address*: string
  193. port*: int
  194. useHttps*: bool
  195. httpMaxConns*: int
  196. title*: string
  197. hostname*: string
  198. staticDir*: string
  199. hmacKey*: string
  200. base64Media*: bool
  201. minTokens*: int
  202. enableRss*: bool
  203. enableDebug*: bool
  204. proxy*: string
  205. proxyAuth*: string
  206. rssCacheTime*: int
  207. listCacheTime*: int
  208. redisHost*: string
  209. redisPort*: int
  210. redisConns*: int
  211. redisMaxConns*: int
  212. redisPassword*: string
  213. Rss* = object
  214. feed*, cursor*: string
  215. proc contains*(thread: Chain; tweet: Tweet): bool =
  216. thread.content.anyIt(it.id == tweet.id)