types.nim 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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. Photo* = object
  123. url*: string
  124. altText*: string
  125. GalleryPhoto* = object
  126. url*: string
  127. tweetId*: string
  128. color*: string
  129. PhotoRail* = seq[GalleryPhoto]
  130. Poll* = object
  131. options*: seq[string]
  132. values*: seq[int]
  133. votes*: int
  134. leader*: int
  135. status*: string
  136. CardKind* = enum
  137. amplify = "amplify"
  138. app = "app"
  139. appPlayer = "appplayer"
  140. player = "player"
  141. summary = "summary"
  142. summaryLarge = "summary_large_image"
  143. promoWebsite = "promo_website"
  144. promoVideo = "promo_video_website"
  145. promoVideoConvo = "promo_video_convo"
  146. promoImageConvo = "promo_image_convo"
  147. promoImageApp = "promo_image_app"
  148. storeLink = "direct_store_link_app"
  149. liveEvent = "live_event"
  150. broadcast = "broadcast"
  151. periscope = "periscope_broadcast"
  152. unified = "unified_card"
  153. moment = "moment"
  154. messageMe = "message_me"
  155. videoDirectMessage = "video_direct_message"
  156. imageDirectMessage = "image_direct_message"
  157. audiospace = "audiospace"
  158. newsletterPublication = "newsletter_publication"
  159. jobDetails = "job_details"
  160. hidden
  161. unknown
  162. Card* = object
  163. kind*: CardKind
  164. url*: string
  165. title*: string
  166. dest*: string
  167. text*: string
  168. image*: string
  169. video*: Option[Video]
  170. TweetStats* = object
  171. replies*: int
  172. retweets*: int
  173. likes*: int
  174. views*: int
  175. Tweet* = ref object
  176. id*: int64
  177. threadId*: int64
  178. replyId*: int64
  179. user*: User
  180. text*: string
  181. time*: DateTime
  182. reply*: seq[string]
  183. pinned*: bool
  184. hasThread*: bool
  185. available*: bool
  186. tombstone*: string
  187. location*: string
  188. # Unused, needed for backwards compat
  189. source*: string
  190. stats*: TweetStats
  191. retweet*: Option[Tweet]
  192. attribution*: Option[User]
  193. mediaTags*: seq[User]
  194. quote*: Option[Tweet]
  195. card*: Option[Card]
  196. poll*: Option[Poll]
  197. gif*: Option[Gif]
  198. video*: Option[Video]
  199. photos*: seq[Photo]
  200. history*: seq[int64]
  201. note*: string
  202. Tweets* = seq[Tweet]
  203. Result*[T] = object
  204. content*: seq[T]
  205. top*, bottom*: string
  206. beginning*: bool
  207. query*: Query
  208. Chain* = object
  209. content*: Tweets
  210. hasMore*: bool
  211. cursor*: string
  212. Conversation* = ref object
  213. tweet*: Tweet
  214. before*: Chain
  215. after*: Chain
  216. replies*: Result[Chain]
  217. EditHistory* = object
  218. latest*: Tweet
  219. history*: Tweets
  220. Timeline* = Result[Tweets]
  221. Profile* = object
  222. user*: User
  223. photoRail*: PhotoRail
  224. pinned*: Option[Tweet]
  225. tweets*: Timeline
  226. List* = object
  227. id*: string
  228. name*: string
  229. userId*: string
  230. username*: string
  231. description*: string
  232. members*: int
  233. banner*: string
  234. GlobalObjects* = ref object
  235. tweets*: Table[string, Tweet]
  236. users*: Table[string, User]
  237. Config* = ref object
  238. address*: string
  239. port*: int
  240. useHttps*: bool
  241. httpMaxConns*: int
  242. title*: string
  243. hostname*: string
  244. staticDir*: string
  245. hmacKey*: string
  246. base64Media*: bool
  247. minTokens*: int
  248. enableRSSUserTweets*: bool
  249. enableRSSUserReplies*: bool
  250. enableRSSUserMedia*: bool
  251. enableRSSSearch*: bool
  252. enableRSSList*: bool
  253. enableDebug*: bool
  254. proxy*: string
  255. proxyAuth*: string
  256. apiProxy*: string
  257. disableTid*: bool
  258. maxConcurrentReqs*: int
  259. rssCacheTime*: int
  260. listCacheTime*: int
  261. redisHost*: string
  262. redisPort*: int
  263. redisConns*: int
  264. redisMaxConns*: int
  265. redisPassword*: string
  266. Rss* = object
  267. feed*, cursor*: string
  268. proc contains*(thread: Chain; tweet: Tweet): bool =
  269. thread.content.anyIt(it.id == tweet.id)
  270. proc add*(timeline: var seq[Tweets]; tweet: Tweet) =
  271. timeline.add @[tweet]