@glagan/rettiwt-api 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/.eslintrc.js +166 -0
  2. package/.gitattributes +3 -0
  3. package/.github/FUNDING.yml +4 -0
  4. package/.github/ISSUE_TEMPLATE/bug-report.yml +57 -0
  5. package/.github/ISSUE_TEMPLATE/feature-request.yml +20 -0
  6. package/.github/ISSUE_TEMPLATE/question.yml +15 -0
  7. package/.github/PULL_REQUEST_TEMPLATE.md +32 -0
  8. package/.github/workflows/ci.yml +32 -0
  9. package/.github/workflows/publish.yml +23 -0
  10. package/.nvmrc +1 -0
  11. package/.prettierignore +3 -0
  12. package/.prettierrc +13 -0
  13. package/LICENSE +21 -0
  14. package/README.md +566 -0
  15. package/dist/cli.js +43 -0
  16. package/eslint.config.mjs +17 -0
  17. package/package.json +50 -0
  18. package/src/Rettiwt.ts +97 -0
  19. package/src/cli.ts +48 -0
  20. package/src/collections/Extractors.ts +155 -0
  21. package/src/collections/Groups.ts +81 -0
  22. package/src/collections/Requests.ts +89 -0
  23. package/src/collections/Tweet.ts +17 -0
  24. package/src/commands/DirectMessage.ts +62 -0
  25. package/src/commands/List.ts +90 -0
  26. package/src/commands/Tweet.ts +437 -0
  27. package/src/commands/User.ts +367 -0
  28. package/src/enums/Api.ts +10 -0
  29. package/src/enums/Authentication.ts +10 -0
  30. package/src/enums/Data.ts +13 -0
  31. package/src/enums/Logging.ts +14 -0
  32. package/src/enums/Media.ts +10 -0
  33. package/src/enums/Notification.ts +12 -0
  34. package/src/enums/Resource.ts +69 -0
  35. package/src/enums/Tweet.ts +8 -0
  36. package/src/enums/raw/Analytics.ts +32 -0
  37. package/src/enums/raw/Media.ts +10 -0
  38. package/src/enums/raw/Notification.ts +11 -0
  39. package/src/enums/raw/Tweet.ts +20 -0
  40. package/src/helper/CliUtils.ts +17 -0
  41. package/src/helper/JsonUtils.ts +70 -0
  42. package/src/index.ts +128 -0
  43. package/src/models/RettiwtConfig.ts +101 -0
  44. package/src/models/args/FetchArgs.ts +169 -0
  45. package/src/models/args/PostArgs.ts +93 -0
  46. package/src/models/args/ProfileArgs.ts +68 -0
  47. package/src/models/auth/AuthCookie.ts +58 -0
  48. package/src/models/auth/AuthCredential.ts +83 -0
  49. package/src/models/data/Analytics.ts +97 -0
  50. package/src/models/data/BookmarkFolder.ts +73 -0
  51. package/src/models/data/Conversation.ts +344 -0
  52. package/src/models/data/CursoredData.ts +64 -0
  53. package/src/models/data/DirectMessage.ts +335 -0
  54. package/src/models/data/Inbox.ts +124 -0
  55. package/src/models/data/List.ts +113 -0
  56. package/src/models/data/Notification.ts +84 -0
  57. package/src/models/data/Tweet.ts +388 -0
  58. package/src/models/data/User.ts +187 -0
  59. package/src/models/errors/TwitterError.ts +65 -0
  60. package/src/models/params/Variables.ts +62 -0
  61. package/src/requests/DirectMessage.ts +229 -0
  62. package/src/requests/List.ts +203 -0
  63. package/src/requests/Media.ts +67 -0
  64. package/src/requests/Tweet.ts +607 -0
  65. package/src/requests/User.ts +1191 -0
  66. package/src/services/internal/AuthService.ts +115 -0
  67. package/src/services/internal/ErrorService.ts +41 -0
  68. package/src/services/internal/LogService.ts +34 -0
  69. package/src/services/public/DirectMessageService.ts +159 -0
  70. package/src/services/public/FetcherService.ts +366 -0
  71. package/src/services/public/ListService.ts +241 -0
  72. package/src/services/public/TweetService.ts +886 -0
  73. package/src/services/public/UserService.ts +1154 -0
  74. package/src/types/ErrorHandler.ts +13 -0
  75. package/src/types/Fetch.ts +3 -0
  76. package/src/types/RettiwtConfig.ts +48 -0
  77. package/src/types/args/FetchArgs.ts +233 -0
  78. package/src/types/args/PostArgs.ts +142 -0
  79. package/src/types/args/ProfileArgs.ts +33 -0
  80. package/src/types/auth/AuthCookie.ts +22 -0
  81. package/src/types/auth/AuthCredential.ts +28 -0
  82. package/src/types/auth/TransactionHeader.ts +8 -0
  83. package/src/types/data/Analytics.ts +58 -0
  84. package/src/types/data/BookmarkFolder.ts +12 -0
  85. package/src/types/data/Conversation.ts +44 -0
  86. package/src/types/data/CursoredData.ts +24 -0
  87. package/src/types/data/DirectMessage.ts +33 -0
  88. package/src/types/data/Inbox.ts +23 -0
  89. package/src/types/data/List.ts +33 -0
  90. package/src/types/data/Notification.ts +26 -0
  91. package/src/types/data/Tweet.ts +99 -0
  92. package/src/types/data/User.ts +54 -0
  93. package/src/types/errors/TwitterError.ts +37 -0
  94. package/src/types/params/Variables.ts +41 -0
  95. package/src/types/raw/base/Analytic.ts +32 -0
  96. package/src/types/raw/base/BookmarkFolder.ts +12 -0
  97. package/src/types/raw/base/Cursor.ts +13 -0
  98. package/src/types/raw/base/Error.ts +38 -0
  99. package/src/types/raw/base/LimitedVisibilityTweet.ts +40 -0
  100. package/src/types/raw/base/List.ts +50 -0
  101. package/src/types/raw/base/Media.ts +53 -0
  102. package/src/types/raw/base/Message.ts +22 -0
  103. package/src/types/raw/base/Notification.ts +66 -0
  104. package/src/types/raw/base/Space.ts +35 -0
  105. package/src/types/raw/base/Tweet.ts +139 -0
  106. package/src/types/raw/base/User.ts +182 -0
  107. package/src/types/raw/composite/DataResult.ts +8 -0
  108. package/src/types/raw/composite/TimelineList.ts +10 -0
  109. package/src/types/raw/composite/TimelineTweet.ts +14 -0
  110. package/src/types/raw/composite/TimelineUser.ts +13 -0
  111. package/src/types/raw/dm/Conversation.ts +59 -0
  112. package/src/types/raw/dm/InboxInitial.ts +155 -0
  113. package/src/types/raw/dm/InboxTimeline.ts +301 -0
  114. package/src/types/raw/dm/UserUpdates.ts +46 -0
  115. package/src/types/raw/generic/Response.ts +10 -0
  116. package/src/types/raw/list/AddMember.ts +175 -0
  117. package/src/types/raw/list/Details.ts +176 -0
  118. package/src/types/raw/list/Members.ts +154 -0
  119. package/src/types/raw/list/RemoveMember.ts +174 -0
  120. package/src/types/raw/list/Tweets.ts +2296 -0
  121. package/src/types/raw/media/FinalizeUpload.ts +20 -0
  122. package/src/types/raw/media/InitalizeUpload.ts +12 -0
  123. package/src/types/raw/media/LiveVideoStream.ts +21 -0
  124. package/src/types/raw/space/Details.ts +359 -0
  125. package/src/types/raw/tweet/Bookmark.ts +14 -0
  126. package/src/types/raw/tweet/Details.ts +210 -0
  127. package/src/types/raw/tweet/DetailsBulk.ts +338 -0
  128. package/src/types/raw/tweet/Like.ts +14 -0
  129. package/src/types/raw/tweet/Likers.ts +200 -0
  130. package/src/types/raw/tweet/Post.ts +150 -0
  131. package/src/types/raw/tweet/Replies.ts +539 -0
  132. package/src/types/raw/tweet/Retweet.ts +31 -0
  133. package/src/types/raw/tweet/Retweeters.ts +208 -0
  134. package/src/types/raw/tweet/Schedule.ts +18 -0
  135. package/src/types/raw/tweet/Search.ts +597 -0
  136. package/src/types/raw/tweet/Unbookmark.ts +14 -0
  137. package/src/types/raw/tweet/Unlike.ts +14 -0
  138. package/src/types/raw/tweet/Unpost.ts +20 -0
  139. package/src/types/raw/tweet/Unretweet.ts +31 -0
  140. package/src/types/raw/tweet/Unschedule.ts +14 -0
  141. package/src/types/raw/user/Affiliates.ts +179 -0
  142. package/src/types/raw/user/Analytics.ts +23 -0
  143. package/src/types/raw/user/BookmarkFolderTweets.ts +53 -0
  144. package/src/types/raw/user/BookmarkFolders.ts +41 -0
  145. package/src/types/raw/user/Bookmarks.ts +637 -0
  146. package/src/types/raw/user/Details.ts +185 -0
  147. package/src/types/raw/user/DetailsBulk.ts +104 -0
  148. package/src/types/raw/user/Follow.ts +280 -0
  149. package/src/types/raw/user/Followed.ts +1942 -0
  150. package/src/types/raw/user/Followers.ts +215 -0
  151. package/src/types/raw/user/Following.ts +215 -0
  152. package/src/types/raw/user/Highlights.ts +1287 -0
  153. package/src/types/raw/user/Likes.ts +1254 -0
  154. package/src/types/raw/user/Lists.ts +378 -0
  155. package/src/types/raw/user/Media.ts +1738 -0
  156. package/src/types/raw/user/Notifications.ts +499 -0
  157. package/src/types/raw/user/ProfileUpdate.ts +80 -0
  158. package/src/types/raw/user/Recommended.ts +2319 -0
  159. package/src/types/raw/user/Scheduled.ts +37 -0
  160. package/src/types/raw/user/Search.ts +230 -0
  161. package/src/types/raw/user/Subscriptions.ts +176 -0
  162. package/src/types/raw/user/Tweets.ts +1254 -0
  163. package/src/types/raw/user/TweetsAndReplies.ts +1254 -0
  164. package/src/types/raw/user/Unfollow.ts +280 -0
  165. package/tsconfig.json +97 -0
@@ -0,0 +1,90 @@
1
+ import { Command, createCommand } from 'commander';
2
+
3
+ import { output } from '../helper/CliUtils';
4
+ import { Rettiwt } from '../Rettiwt';
5
+
6
+ /**
7
+ * Creates a new 'list' command which uses the given Rettiwt instance.
8
+ *
9
+ * @param rettiwt - The Rettiwt instance to use.
10
+ * @returns The created 'list' command.
11
+ */
12
+ function createListCommand(rettiwt: Rettiwt): Command {
13
+ // Creating the 'list' command
14
+ const list = createCommand('list').description('Access resources related to lists');
15
+
16
+ // Add member
17
+ list.command('add-member')
18
+ .description('Add a new member to a list')
19
+ .argument('<list-id>', 'The ID of the tweet list')
20
+ .argument('<user-id>', 'The ID of the user to add')
21
+ .action(async (listId: string, userId: string) => {
22
+ try {
23
+ const memberCount = await rettiwt.list.addMember(listId, userId);
24
+ output(memberCount);
25
+ } catch (error) {
26
+ output(error);
27
+ }
28
+ });
29
+
30
+ // Details
31
+ list.command('details')
32
+ .description('Fetch the details of a list')
33
+ .argument('<id>', 'The ID of the tweet list')
34
+ .action(async (id: string) => {
35
+ try {
36
+ const details = await rettiwt.list.details(id);
37
+ output(details);
38
+ } catch (error) {
39
+ output(error);
40
+ }
41
+ });
42
+
43
+ // Members
44
+ list.command('members')
45
+ .description('Fetch the list of members of the given tweet list')
46
+ .argument('<id>', 'The ID of the tweet list')
47
+ .argument('[count]', 'The number of members to fetch')
48
+ .argument('[cursor]', 'The cursor to the batch of members to fetch')
49
+ .action(async (id: string, count?: string, cursor?: string) => {
50
+ try {
51
+ const members = await rettiwt.list.members(id, count ? parseInt(count) : undefined, cursor);
52
+ output(members);
53
+ } catch (error) {
54
+ output(error);
55
+ }
56
+ });
57
+
58
+ // Remove member
59
+ list.command('remove-member')
60
+ .description('Remove a new member from a list')
61
+ .argument('<list-id>', 'The ID of the tweet list')
62
+ .argument('<user-id>', 'The ID of the user to remove')
63
+ .action(async (listId: string, userId: string) => {
64
+ try {
65
+ const memberCount = await rettiwt.list.removeMember(listId, userId);
66
+ output(memberCount);
67
+ } catch (error) {
68
+ output(error);
69
+ }
70
+ });
71
+
72
+ // Tweets
73
+ list.command('tweets')
74
+ .description('Fetch the list of tweets in the tweet list with the given id')
75
+ .argument('<id>', 'The ID of the tweet list')
76
+ .argument('[count]', 'The number of tweets to fetch')
77
+ .argument('[cursor]', 'The cursor to the batch of tweets to fetch')
78
+ .action(async (id: string, count?: string, cursor?: string) => {
79
+ try {
80
+ const tweets = await rettiwt.list.tweets(id, count ? parseInt(count) : undefined, cursor);
81
+ output(tweets);
82
+ } catch (error) {
83
+ output(error);
84
+ }
85
+ });
86
+
87
+ return list;
88
+ }
89
+
90
+ export default createListCommand;
@@ -0,0 +1,437 @@
1
+ import { Command, createCommand } from 'commander';
2
+
3
+ import { TweetRepliesSortType } from '../enums/Tweet';
4
+ import { output } from '../helper/CliUtils';
5
+ import { TweetFilter } from '../models/args/FetchArgs';
6
+ import { Rettiwt } from '../Rettiwt';
7
+ import { ITweetFilter } from '../types/args/FetchArgs';
8
+
9
+ /**
10
+ * Creates a new 'tweet' command which uses the given Rettiwt instance.
11
+ *
12
+ * @param rettiwt - The Rettiwt instance to use.
13
+ * @returns The created 'tweet' command.
14
+ */
15
+ function createTweetCommand(rettiwt: Rettiwt): Command {
16
+ // Creating the 'tweet' command
17
+ const tweet = createCommand('tweet').description('Access resources related to tweets');
18
+
19
+ // Bookmark
20
+ tweet
21
+ .command('bookmark')
22
+ .description('Bookmark a tweet')
23
+ .argument('<id>', 'The tweet to bookmark')
24
+ .action(async (id: string) => {
25
+ try {
26
+ const result = await rettiwt.tweet.bookmark(id);
27
+ output(result);
28
+ } catch (error) {
29
+ output(error);
30
+ }
31
+ });
32
+
33
+ // Details
34
+ tweet
35
+ .command('details')
36
+ .description('Fetch the details of tweet/tweets with the given id/ids')
37
+ .argument('<id>', 'The comma-separated list of IDs of tweets whose details are to be fetched')
38
+ .action(async (id: string) => {
39
+ try {
40
+ // Getting the different IDs
41
+ const ids: string[] = id.split(',');
42
+
43
+ // If single ID given
44
+ if (ids.length <= 1) {
45
+ const details = await rettiwt.tweet.details(ids[0]);
46
+ output(details);
47
+ }
48
+ // If multiple IDs give
49
+ else {
50
+ const details = await rettiwt.tweet.details(ids);
51
+ output(details);
52
+ }
53
+ } catch (error) {
54
+ output(error);
55
+ }
56
+ });
57
+
58
+ // Like
59
+ tweet
60
+ .command('like')
61
+ .description('Like a tweet')
62
+ .argument('<id>', 'The tweet to like')
63
+ .action(async (id: string) => {
64
+ try {
65
+ const result = await rettiwt.tweet.like(id);
66
+ output(result);
67
+ } catch (error) {
68
+ output(error);
69
+ }
70
+ });
71
+
72
+ // Likers
73
+ tweet
74
+ .command('likers')
75
+ .description('Fetch the list of users who liked the given tweet. Only works for your own tweets')
76
+ .argument('<id>', 'The id of the tweet')
77
+ .argument('[count]', 'The number of likers to fetch')
78
+ .argument('[cursor]', 'The cursor to the batch of likers to fetch')
79
+ .action(async (id: string, count?: string, cursor?: string) => {
80
+ try {
81
+ const users = await rettiwt.tweet.likers(id, count ? parseInt(count) : undefined, cursor);
82
+ output(users);
83
+ } catch (error) {
84
+ output(error);
85
+ }
86
+ });
87
+
88
+ // Post
89
+ tweet
90
+ .command('post')
91
+ .description('Post a tweet (text only)')
92
+ .argument('<text>', 'The text to post as a tweet')
93
+ .option('-m, --media [string]', 'Comma-separated list of ids of the media item(s) to be posted')
94
+ .option('-q, --quote [string]', 'The id of the tweet to quote in the tweet to be posted')
95
+ .option(
96
+ '-r, --reply [string]',
97
+ 'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
98
+ )
99
+ .action(async (text: string, options?: { media?: string; quote?: string; reply?: string }) => {
100
+ try {
101
+ const result = await rettiwt.tweet.post({
102
+ text: text,
103
+ media: options?.media ? options?.media.split(',').map((item) => ({ id: item })) : undefined,
104
+ quote: options?.quote,
105
+ replyTo: options?.reply,
106
+ });
107
+ output(result);
108
+ } catch (error) {
109
+ output(error);
110
+ }
111
+ });
112
+
113
+ // Replies
114
+ tweet
115
+ .command('replies')
116
+ .description(
117
+ 'Fetch the list of replies to a tweet, with the first batch containing the whole thread, if the tweet is/part of a thread',
118
+ )
119
+ .argument('<id>', 'The id of the tweet')
120
+ .argument('[cursor]', 'The cursor to the batch of replies to fetch')
121
+ .option('-s, --sort-by <string>', 'Sort the tweets by likes, latest or relevance, default is latest')
122
+ .action(async (id: string, cursor?: string, options?: { sortBy: string }) => {
123
+ try {
124
+ // Determining the sort type
125
+ let sortType: TweetRepliesSortType | undefined = undefined;
126
+ if (options?.sortBy === 'likes') {
127
+ sortType = TweetRepliesSortType.LIKES;
128
+ } else if (options?.sortBy === 'latest') {
129
+ sortType = TweetRepliesSortType.LATEST;
130
+ } else if (options?.sortBy === 'relevance') {
131
+ sortType = TweetRepliesSortType.RELEVANCE;
132
+ }
133
+
134
+ const tweets = await rettiwt.tweet.replies(id, cursor, sortType);
135
+ output(tweets);
136
+ } catch (error) {
137
+ output(error);
138
+ }
139
+ });
140
+
141
+ // Retweet
142
+ tweet
143
+ .command('retweet')
144
+ .description('Retweet a tweet')
145
+ .argument('<id>', 'The tweet to retweet')
146
+ .action(async (id: string) => {
147
+ try {
148
+ const result = await rettiwt.tweet.retweet(id);
149
+ output(result);
150
+ } catch (error) {
151
+ output(error);
152
+ }
153
+ });
154
+
155
+ // Retweeters
156
+ tweet
157
+ .command('retweeters')
158
+ .description('Fetch the list of users who retweeted the given tweets')
159
+ .argument('<id>', 'The id of the tweet')
160
+ .argument('[count]', 'The number of retweeters to fetch')
161
+ .argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
162
+ .action(async (id: string, count?: string, cursor?: string) => {
163
+ try {
164
+ const users = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
165
+ output(users);
166
+ } catch (error) {
167
+ output(error);
168
+ }
169
+ });
170
+
171
+ // Schedule
172
+ tweet
173
+ .command('schedule')
174
+ .description('Schedule a tweet to be posted at a given date/time')
175
+ .argument('<text>', 'The text to post as a tweet')
176
+ .argument('<time>', 'The date/time at which the tweet is to be scheduled (valid date/time string)')
177
+ .option('-m, --media [string]', 'Comma-separated list of ids of the media item(s) to be posted')
178
+ .option('-q, --quote [string]', 'The id of the tweet to quote in the tweet to be posted')
179
+ .option(
180
+ '-r, --reply [string]',
181
+ 'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
182
+ )
183
+ .action(async (text: string, time: string, options?: { media?: string; quote?: string; reply?: string }) => {
184
+ try {
185
+ const result = await rettiwt.tweet.schedule({
186
+ text: text,
187
+ media: options?.media ? options?.media.split(',').map((item) => ({ id: item })) : undefined,
188
+ quote: options?.quote,
189
+ replyTo: options?.reply,
190
+ scheduleFor: new Date(time),
191
+ });
192
+ output(result);
193
+ } catch (error) {
194
+ output(error);
195
+ }
196
+ });
197
+
198
+ // Search
199
+ tweet
200
+ .command('search')
201
+ .description('Fetch the list of tweets that match the given filter options')
202
+ .argument('[count]', 'The number of tweets to fetch')
203
+ .argument('[cursor]', 'The cursor to the batch of tweets to fetch')
204
+ .option('-f, --from <string>', 'Matches the tweets made by the comma-separated list of given users')
205
+ .option('-t, --to <string>', 'Matches the tweets made to the comma-separated list of given users')
206
+ .option('-w, --words <string>', 'Matches the tweets containing the given comma-separated list of words')
207
+ .option('-p, --phrase <string>', 'Matches the tweets containing the exact phrase')
208
+ .option(
209
+ '--optional-words <string>',
210
+ 'Matches the tweets containing any of the given comma-separated list of words',
211
+ )
212
+ .option(
213
+ '--exclude-words <string>',
214
+ 'Matches the tweets that do not contain any of the give comma-separated list of words',
215
+ )
216
+ .option('-h, --hashtags <string>', 'Matches the tweets containing the given comma-separated list of hashtags')
217
+ .option('--list <string>', 'Matches the tweets from the list with the given id')
218
+ .option(
219
+ '-m, --mentions <string>',
220
+ 'Matches the tweets that mention the given comma-separated list of usernames',
221
+ )
222
+ .option('-r, --min-replies <number>', 'Matches the tweets that have a minimum of given number of replies')
223
+ .option('-l, --min-likes <number>', 'Matches the tweets that have a minimum of given number of likes')
224
+ .option('-x, --min-retweets <number>', 'Matches the tweets that have a minimum of given number of retweets')
225
+ .option('-q, --quoted <string>', 'Matches the tweets that quote the tweet with the given id')
226
+ .option('--only-original', 'Matches tweets are original posts')
227
+ .option('--only-replies', 'Matches tweets that are replies')
228
+ .option('--only-text', 'Matches tweets that are only text')
229
+ .option('--only-links', 'Matches tweets that only contain links like media, quotes, etc')
230
+ .option('-s, --start <string>', 'Matches the tweets made since the given date (valid date/time string)')
231
+ .option('-e, --end <string>', 'Matches the tweets made upto the given date (valid date/time string)')
232
+ .option('--top', 'Matches top tweets instead of latest')
233
+ .option('--stream', 'Stream the filtered tweets in pseudo-realtime')
234
+ .option('-i, --interval <number>', 'The polling interval (in ms) to use for streaming. Default is 60000')
235
+ .action(async (count?: string, cursor?: string, options?: TweetSearchOptions) => {
236
+ try {
237
+ // If search results are to be streamed
238
+ if (options?.stream) {
239
+ for await (const tweet of rettiwt.tweet.stream(
240
+ new TweetSearchOptions(options).toTweetFilter(),
241
+ options?.interval,
242
+ )) {
243
+ output(tweet);
244
+ }
245
+ }
246
+ // If a normal search is to be done
247
+ else {
248
+ const tweets = await rettiwt.tweet.search(
249
+ new TweetSearchOptions(options).toTweetFilter(),
250
+ count ? parseInt(count) : undefined,
251
+ cursor,
252
+ );
253
+ output(tweets);
254
+ }
255
+ } catch (error) {
256
+ output(error);
257
+ }
258
+ });
259
+
260
+ // Unbookmark
261
+ tweet
262
+ .command('unbookmark')
263
+ .description('Unbookmark a tweet')
264
+ .argument('<id>', 'The id of the tweet')
265
+ .action(async (id: string) => {
266
+ try {
267
+ const result = await rettiwt.tweet.unbookmark(id);
268
+ output(result);
269
+ } catch (error) {
270
+ output(error);
271
+ }
272
+ });
273
+
274
+ // Unlike
275
+ tweet
276
+ .command('unlike')
277
+ .description('Unlike a tweet')
278
+ .argument('<id>', 'The id of the tweet')
279
+ .action(async (id: string) => {
280
+ try {
281
+ const result = await rettiwt.tweet.unlike(id);
282
+ output(result);
283
+ } catch (error) {
284
+ output(error);
285
+ }
286
+ });
287
+
288
+ // Unpost
289
+ tweet
290
+ .command('unpost')
291
+ .description('Unpost a tweet')
292
+ .argument('<id>', 'The id of the tweet')
293
+ .action(async (id: string) => {
294
+ try {
295
+ const result = await rettiwt.tweet.unpost(id);
296
+ output(result);
297
+ } catch (error) {
298
+ output(error);
299
+ }
300
+ });
301
+
302
+ // Unretweet
303
+ tweet
304
+ .command('unretweet')
305
+ .description('Unretweet a tweet')
306
+ .argument('<id>', 'The id of the tweet')
307
+ .action(async (id: string) => {
308
+ try {
309
+ const result = await rettiwt.tweet.unretweet(id);
310
+ output(result);
311
+ } catch (error) {
312
+ output(error);
313
+ }
314
+ });
315
+
316
+ // Unschedule
317
+ tweet
318
+ .command('unschedule')
319
+ .description('Unschedule a tweet')
320
+ .argument('<id>', 'The id of the tweet')
321
+ .action(async (id: string) => {
322
+ try {
323
+ const result = await rettiwt.tweet.unschedule(id);
324
+ output(result);
325
+ } catch (error) {
326
+ output(error);
327
+ }
328
+ });
329
+
330
+ // Upload
331
+ tweet
332
+ .command('upload')
333
+ .description('Upload a media file and returns the alloted id (valid for 24 hrs)')
334
+ .argument('<path>', 'The path to the media to upload')
335
+ .action(async (path: string) => {
336
+ try {
337
+ const id = await rettiwt.tweet.upload(path);
338
+ output(id);
339
+ } catch (error) {
340
+ output(error);
341
+ }
342
+ });
343
+
344
+ return tweet;
345
+ }
346
+
347
+ /**
348
+ * The search options supplied while searching for tweets.
349
+ *
350
+ * @remarks The search options are implementations of the ones offered by {@link TweetFilter}
351
+ */
352
+ class TweetSearchOptions {
353
+ public end?: string;
354
+ public excludeWords?: string;
355
+ public from?: string;
356
+ public hashtags?: string;
357
+ public interval?: number;
358
+ public list?: string;
359
+ public mentions?: string;
360
+ public minLikes?: number;
361
+ public minReplies?: number;
362
+ public minRetweets?: number;
363
+ public onlyLinks?: boolean = false;
364
+ public onlyOriginal?: boolean = false;
365
+ public onlyReplies?: boolean = false;
366
+ public onlyText?: boolean = false;
367
+ public optionalWords?: string;
368
+ public phrase?: string;
369
+ public quoted?: string;
370
+ public start?: string;
371
+ public stream?: boolean;
372
+ public to?: string;
373
+ public top?: boolean;
374
+ public words?: string;
375
+
376
+ /**
377
+ * Initializes a new object from the given options.
378
+ *
379
+ * @param options - The search options.
380
+ */
381
+ public constructor(options?: TweetSearchOptions) {
382
+ this.from = options?.from;
383
+ this.to = options?.to;
384
+ this.words = options?.words;
385
+ this.phrase = options?.phrase;
386
+ this.optionalWords = options?.optionalWords;
387
+ this.excludeWords = options?.excludeWords;
388
+ this.hashtags = options?.hashtags;
389
+ this.list = options?.list;
390
+ this.mentions = options?.mentions;
391
+ this.minReplies = options?.minReplies;
392
+ this.minLikes = options?.minLikes;
393
+ this.minRetweets = options?.minRetweets;
394
+ this.onlyLinks = options?.onlyLinks;
395
+ this.onlyOriginal = options?.onlyOriginal;
396
+ this.onlyReplies = options?.onlyReplies;
397
+ this.onlyText = options?.onlyText;
398
+ this.quoted = options?.quoted;
399
+ this.start = options?.start;
400
+ this.end = options?.end;
401
+ this.stream = options?.stream;
402
+ this.interval = options?.interval;
403
+ this.top = options?.top;
404
+ }
405
+
406
+ /**
407
+ * Converts the filter options to a format recognizable by rettiwt-api.
408
+ *
409
+ * @returns The '{@link ITweetFilter}' representation of filter options.
410
+ */
411
+ public toTweetFilter(): ITweetFilter {
412
+ return new TweetFilter({
413
+ fromUsers: this.from ? this.from.split(',') : undefined,
414
+ toUsers: this.to ? this.to.split(',') : undefined,
415
+ includeWords: this.words ? this.words.split(',') : undefined,
416
+ includePhrase: this.phrase,
417
+ optionalWords: this.optionalWords ? this.optionalWords.split(',') : undefined,
418
+ excludeWords: this.excludeWords ? this.excludeWords.split(',') : undefined,
419
+ hashtags: this.hashtags ? this.hashtags.split(',') : undefined,
420
+ list: this.list,
421
+ mentions: this.mentions ? this.mentions.split(',') : undefined,
422
+ minReplies: this.minReplies,
423
+ minLikes: this.minLikes,
424
+ minRetweets: this.minRetweets,
425
+ onlyLinks: this.onlyLinks,
426
+ onlyOriginal: this.onlyOriginal,
427
+ onlyReplies: this.onlyReplies,
428
+ onlyText: this.onlyText,
429
+ quoted: this.quoted,
430
+ startDate: this.start ? new Date(this.start) : undefined,
431
+ top: this.top,
432
+ endDate: this.end ? new Date(this.end) : undefined,
433
+ });
434
+ }
435
+ }
436
+
437
+ export default createTweetCommand;