types.nim 5.1 KB

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