types.nim 5.5 KB

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