types.nim 5.0 KB

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