types.nim 5.0 KB

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