types.nim 5.9 KB

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