types.nim 5.9 KB

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