types.nim 5.6 KB

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