rettiwt-api 2.7.1 → 3.0.1

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 (139) hide show
  1. package/.eslintrc.js +73 -5
  2. package/.tool-versions +1 -0
  3. package/README.md +87 -20
  4. package/dist/Rettiwt.js +0 -1
  5. package/dist/Rettiwt.js.map +1 -1
  6. package/dist/cli.js +2 -4
  7. package/dist/cli.js.map +1 -1
  8. package/dist/collections/Extractors.d.ts +37 -0
  9. package/dist/collections/Extractors.js +67 -0
  10. package/dist/collections/Extractors.js.map +1 -0
  11. package/dist/collections/Groups.d.ts +19 -0
  12. package/dist/collections/Groups.js +55 -0
  13. package/dist/collections/Groups.js.map +1 -0
  14. package/dist/collections/Requests.d.ts +12 -0
  15. package/dist/collections/Requests.js +46 -0
  16. package/dist/collections/Requests.js.map +1 -0
  17. package/dist/commands/Auth.d.ts +6 -0
  18. package/dist/commands/Auth.js +26 -8
  19. package/dist/commands/Auth.js.map +1 -1
  20. package/dist/commands/Tweet.js +237 -82
  21. package/dist/commands/Tweet.js.map +1 -1
  22. package/dist/commands/User.js +197 -36
  23. package/dist/commands/User.js.map +1 -1
  24. package/dist/enums/Api.d.ts +30 -0
  25. package/dist/enums/Api.js +32 -1
  26. package/dist/enums/Api.js.map +1 -1
  27. package/dist/enums/Data.d.ts +9 -0
  28. package/dist/enums/Data.js +14 -0
  29. package/dist/enums/Data.js.map +1 -0
  30. package/dist/enums/Http.d.ts +1 -1
  31. package/dist/enums/Http.js +1 -1
  32. package/dist/enums/Logging.d.ts +6 -5
  33. package/dist/enums/Logging.js +6 -5
  34. package/dist/enums/Logging.js.map +1 -1
  35. package/dist/enums/Resource.d.ts +33 -0
  36. package/dist/enums/Resource.js +42 -0
  37. package/dist/enums/Resource.js.map +1 -0
  38. package/dist/helper/CliUtils.d.ts +1 -1
  39. package/dist/helper/CliUtils.js.map +1 -1
  40. package/dist/index.d.ts +11 -9
  41. package/dist/index.js +11 -14
  42. package/dist/index.js.map +1 -1
  43. package/dist/models/args/FetchArgs.d.ts +129 -0
  44. package/dist/models/args/FetchArgs.js +263 -0
  45. package/dist/models/args/FetchArgs.js.map +1 -0
  46. package/dist/models/args/PostArgs.d.ts +116 -0
  47. package/dist/models/args/PostArgs.js +232 -0
  48. package/dist/models/args/PostArgs.js.map +1 -0
  49. package/dist/models/data/CursoredData.d.ts +11 -11
  50. package/dist/models/data/CursoredData.js +21 -16
  51. package/dist/models/data/CursoredData.js.map +1 -1
  52. package/dist/models/data/List.d.ts +8 -10
  53. package/dist/models/data/List.js +2 -4
  54. package/dist/models/data/List.js.map +1 -1
  55. package/dist/models/data/Tweet.d.ts +44 -29
  56. package/dist/models/data/Tweet.js +74 -15
  57. package/dist/models/data/Tweet.js.map +1 -1
  58. package/dist/models/data/User.d.ts +38 -20
  59. package/dist/models/data/User.js +71 -7
  60. package/dist/models/data/User.js.map +1 -1
  61. package/dist/models/errors/ApiError.d.ts +1 -3
  62. package/dist/models/errors/ApiError.js +1 -4
  63. package/dist/models/errors/ApiError.js.map +1 -1
  64. package/dist/models/errors/DataValidationError.d.ts +30 -0
  65. package/dist/models/errors/DataValidationError.js +34 -0
  66. package/dist/models/errors/DataValidationError.js.map +1 -0
  67. package/dist/models/errors/HttpError.d.ts +1 -3
  68. package/dist/models/errors/HttpError.js +1 -4
  69. package/dist/models/errors/HttpError.js.map +1 -1
  70. package/dist/models/errors/TimeoutError.d.ts +2 -4
  71. package/dist/models/errors/TimeoutError.js +2 -5
  72. package/dist/models/errors/TimeoutError.js.map +1 -1
  73. package/dist/services/internal/ErrorService.d.ts +45 -35
  74. package/dist/services/internal/ErrorService.js +70 -68
  75. package/dist/services/internal/ErrorService.js.map +1 -1
  76. package/dist/services/internal/LogService.d.ts +7 -5
  77. package/dist/services/internal/LogService.js +28 -9
  78. package/dist/services/internal/LogService.js.map +1 -1
  79. package/dist/services/public/AuthService.d.ts +24 -20
  80. package/dist/services/public/AuthService.js +38 -36
  81. package/dist/services/public/AuthService.js.map +1 -1
  82. package/dist/services/public/FetcherService.d.ts +89 -0
  83. package/dist/services/public/FetcherService.js +240 -0
  84. package/dist/services/public/FetcherService.js.map +1 -0
  85. package/dist/services/public/TweetService.d.ts +213 -94
  86. package/dist/services/public/TweetService.js +409 -209
  87. package/dist/services/public/TweetService.js.map +1 -1
  88. package/dist/services/public/UserService.d.ts +185 -52
  89. package/dist/services/public/UserService.js +338 -103
  90. package/dist/services/public/UserService.js.map +1 -1
  91. package/dist/types/ReturnTypes.d.ts +21 -0
  92. package/dist/types/ReturnTypes.js +3 -0
  93. package/dist/types/ReturnTypes.js.map +1 -0
  94. package/package.json +4 -2
  95. package/src/Rettiwt.ts +0 -3
  96. package/src/cli.ts +2 -4
  97. package/src/collections/Extractors.ts +84 -0
  98. package/src/collections/Groups.ts +54 -0
  99. package/src/collections/Requests.ts +52 -0
  100. package/src/commands/Auth.ts +19 -7
  101. package/src/commands/Tweet.ts +179 -91
  102. package/src/commands/User.ts +118 -25
  103. package/src/enums/Api.ts +31 -0
  104. package/src/enums/Data.ts +9 -0
  105. package/src/enums/Http.ts +1 -1
  106. package/src/enums/Logging.ts +6 -5
  107. package/src/enums/Resource.ts +40 -0
  108. package/src/helper/CliUtils.ts +1 -1
  109. package/src/index.ts +41 -14
  110. package/src/models/args/FetchArgs.ts +296 -0
  111. package/src/models/args/PostArgs.ts +263 -0
  112. package/src/models/data/CursoredData.ts +23 -15
  113. package/src/models/data/List.ts +12 -15
  114. package/src/models/data/Tweet.ts +108 -39
  115. package/src/models/data/User.ts +99 -30
  116. package/src/models/errors/ApiError.ts +1 -4
  117. package/src/models/errors/DataValidationError.ts +44 -0
  118. package/src/models/errors/HttpError.ts +1 -4
  119. package/src/models/errors/TimeoutError.ts +2 -5
  120. package/src/services/internal/ErrorService.ts +76 -75
  121. package/src/services/internal/LogService.ts +20 -10
  122. package/src/services/public/AuthService.ts +39 -38
  123. package/src/services/public/FetcherService.ts +209 -0
  124. package/src/services/public/TweetService.ts +384 -179
  125. package/src/services/public/UserService.ts +319 -86
  126. package/src/types/RettiwtConfig.ts +0 -1
  127. package/src/types/ReturnTypes.ts +24 -0
  128. package/dist/models/args/TweetArgs.d.ts +0 -44
  129. package/dist/models/args/TweetArgs.js +0 -82
  130. package/dist/models/args/TweetArgs.js.map +0 -1
  131. package/dist/models/data/Media.d.ts +0 -14
  132. package/dist/models/data/Media.js +0 -19
  133. package/dist/models/data/Media.js.map +0 -1
  134. package/dist/services/internal/FetcherService.d.ts +0 -106
  135. package/dist/services/internal/FetcherService.js +0 -365
  136. package/dist/services/internal/FetcherService.js.map +0 -1
  137. package/src/models/args/TweetArgs.ts +0 -98
  138. package/src/models/data/Media.ts +0 -19
  139. package/src/services/internal/FetcherService.ts +0 -365
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rettiwt-api",
3
- "version": "2.7.1",
3
+ "version": "3.0.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "description": "An API for fetching data from TwitterAPI, without any rate limits!",
@@ -30,17 +30,19 @@
30
30
  "homepage": "https://rishikant181.github.io/Rettiwt-API/",
31
31
  "dependencies": {
32
32
  "axios": "1.6.3",
33
+ "chalk": "4.1.2",
33
34
  "class-validator": "0.14.1",
34
35
  "commander": "11.1.0",
35
36
  "https-proxy-agent": "7.0.2",
36
37
  "rettiwt-auth": "2.1.0",
37
- "rettiwt-core": "3.4.0"
38
+ "rettiwt-core": "4.0.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@types/node": "20.4.1",
41
42
  "@typescript-eslint/eslint-plugin": "6.0.0",
42
43
  "@typescript-eslint/parser": "6.0.0",
43
44
  "eslint": "8.44.0",
45
+ "eslint-plugin-import": "2.29.1",
44
46
  "eslint-plugin-tsdoc": "0.2.17",
45
47
  "nodemon": "2.0.20",
46
48
  "prettier": "3.0.0",
package/src/Rettiwt.ts CHANGED
@@ -1,9 +1,6 @@
1
- // SERVICES
2
1
  import { AuthService } from './services/public/AuthService';
3
2
  import { TweetService } from './services/public/TweetService';
4
3
  import { UserService } from './services/public/UserService';
5
-
6
- // TYPES
7
4
  import { IRettiwtConfig } from './types/RettiwtConfig';
8
5
 
9
6
  /**
package/src/cli.ts CHANGED
@@ -1,13 +1,11 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- // PACKAGES
4
3
  import { createCommand } from 'commander';
5
- import { Rettiwt } from './Rettiwt';
6
4
 
7
- // SUB-COMMANDS
5
+ import auth from './commands/Auth';
8
6
  import tweet from './commands/Tweet';
9
7
  import user from './commands/User';
10
- import auth from './commands/Auth';
8
+ import { Rettiwt } from './Rettiwt';
11
9
 
12
10
  // Creating a new commandline program
13
11
  const program = createCommand('rettiwt')
@@ -0,0 +1,84 @@
1
+ import {
2
+ IInitializeMediaUploadResponse,
3
+ IListTweetsResponse,
4
+ ITweetDetailsResponse,
5
+ ITweetLikeResponse,
6
+ ITweetLikersResponse,
7
+ ITweetPostResponse,
8
+ ITweetRetweetersResponse,
9
+ ITweetRetweetResponse,
10
+ ITweetSearchResponse,
11
+ ITweetUnlikeResponse,
12
+ ITweetUnpostResponse,
13
+ ITweetUnretweetResponse,
14
+ IUserDetailsResponse,
15
+ IUserFollowersResponse,
16
+ IUserFollowingResponse,
17
+ IUserFollowResponse,
18
+ IUserHighlightsResponse,
19
+ IUserLikesResponse,
20
+ IUserMediaResponse,
21
+ IUserSubscriptionsResponse,
22
+ IUserTweetsAndRepliesResponse,
23
+ IUserTweetsResponse,
24
+ IUserUnfollowResponse,
25
+ } from 'rettiwt-core';
26
+
27
+ import { EBaseType } from '../enums/Data';
28
+ import { CursoredData } from '../models/data/CursoredData';
29
+ import { Tweet } from '../models/data/Tweet';
30
+ import { User } from '../models/data/User';
31
+
32
+ /**
33
+ * Collection of data extractors for each resource.
34
+ *
35
+ * @internal
36
+ */
37
+ export const extractors = {
38
+ /* eslint-disable @typescript-eslint/naming-convention */
39
+ LIST_TWEETS: (response: IListTweetsResponse): CursoredData<Tweet> =>
40
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
41
+
42
+ MEDIA_UPLOAD_APPEND: (): void => undefined,
43
+ MEDIA_UPLOAD_FINALIZE: (): void => undefined,
44
+ MEDIA_UPLOAD_INITIALIZE: (response: IInitializeMediaUploadResponse): string =>
45
+ response.media_id_string ?? undefined,
46
+
47
+ TWEET_DETAILS: (response: ITweetDetailsResponse, id: string): Tweet | undefined => Tweet.single(response, id),
48
+ TWEET_LIKE: (response: ITweetLikeResponse): boolean => (response?.data?.favorite_tweet ? true : false),
49
+ TWEET_LIKERS: (response: ITweetLikersResponse): CursoredData<User> =>
50
+ new CursoredData<User>(response, EBaseType.USER),
51
+ TWEET_POST: (response: ITweetPostResponse): string =>
52
+ response?.data?.create_tweet?.tweet_results?.result?.rest_id ?? undefined,
53
+ TWEET_RETWEET: (response: ITweetRetweetResponse): boolean => (response?.data?.create_retweet ? true : false),
54
+ TWEET_RETWEETERS: (response: ITweetRetweetersResponse): CursoredData<User> =>
55
+ new CursoredData<User>(response, EBaseType.USER),
56
+ TWEET_SEARCH: (response: ITweetSearchResponse): CursoredData<Tweet> =>
57
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
58
+ TWEET_UNLIKE: (response: ITweetUnlikeResponse): boolean => (response?.data?.unfavorite_tweet ? true : false),
59
+ TWEET_UNPOST: (response: ITweetUnpostResponse): boolean => (response?.data?.delete_tweet ? true : false),
60
+ TWEET_UNRETWEET: (response: ITweetUnretweetResponse): boolean =>
61
+ response?.data?.unretweet?.source_tweet_results?.result ? true : false,
62
+
63
+ USER_DETAILS_BY_USERNAME: (response: IUserDetailsResponse): User | undefined => User.single(response),
64
+ USER_DETAILS_BY_ID: (response: IUserDetailsResponse): User | undefined => User.single(response),
65
+ USER_FOLLOW: (response: IUserFollowResponse): boolean => (response?.id ? true : false),
66
+ USER_FOLLOWING: (response: IUserFollowingResponse): CursoredData<User> =>
67
+ new CursoredData<User>(response, EBaseType.USER),
68
+ USER_FOLLOWERS: (response: IUserFollowersResponse): CursoredData<User> =>
69
+ new CursoredData<User>(response, EBaseType.USER),
70
+ USER_HIGHLIGHTS: (response: IUserHighlightsResponse): CursoredData<Tweet> =>
71
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
72
+ USER_LIKES: (response: IUserLikesResponse): CursoredData<Tweet> =>
73
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
74
+ USER_MEDIA: (response: IUserMediaResponse): CursoredData<Tweet> =>
75
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
76
+ USER_SUBSCRIPTIONS: (response: IUserSubscriptionsResponse): CursoredData<User> =>
77
+ new CursoredData<User>(response, EBaseType.USER),
78
+ USER_TIMELINE: (response: IUserTweetsResponse): CursoredData<Tweet> =>
79
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
80
+ USER_TIMELINE_AND_REPLIES: (response: IUserTweetsAndRepliesResponse): CursoredData<Tweet> =>
81
+ new CursoredData<Tweet>(response, EBaseType.TWEET),
82
+ USER_UNFOLLOW: (response: IUserUnfollowResponse): boolean => (response?.id ? true : false),
83
+ /* eslint-enable @typescript-eslint/naming-convention */
84
+ };
@@ -0,0 +1,54 @@
1
+ import { EResourceType } from '../enums/Resource';
2
+
3
+ /**
4
+ * Collection of resources that allow guest authentication.
5
+ *
6
+ * @internal
7
+ */
8
+ export const allowGuestAuthentication = [
9
+ EResourceType.TWEET_DETAILS,
10
+ EResourceType.USER_DETAILS_BY_USERNAME,
11
+ EResourceType.USER_TIMELINE,
12
+ ];
13
+
14
+ /**
15
+ * Collection of resources that can be fetched.
16
+ *
17
+ * @internal
18
+ */
19
+ export const fetchResources = [
20
+ EResourceType.LIST_TWEETS,
21
+ EResourceType.TWEET_DETAILS,
22
+ EResourceType.TWEET_LIKERS,
23
+ EResourceType.TWEET_RETWEETERS,
24
+ EResourceType.TWEET_SEARCH,
25
+ EResourceType.USER_DETAILS_BY_USERNAME,
26
+ EResourceType.USER_DETAILS_BY_ID,
27
+ EResourceType.USER_FOLLOWING,
28
+ EResourceType.USER_FOLLOWERS,
29
+ EResourceType.USER_HIGHLIGHTS,
30
+ EResourceType.USER_LIKES,
31
+ EResourceType.USER_MEDIA,
32
+ EResourceType.USER_SUBSCRIPTIONS,
33
+ EResourceType.USER_TIMELINE,
34
+ EResourceType.USER_TIMELINE_AND_REPLIES,
35
+ ];
36
+
37
+ /**
38
+ * Collection of resources that can be posted.
39
+ *
40
+ * @internal
41
+ */
42
+ export const postResources = [
43
+ EResourceType.MEDIA_UPLOAD_APPEND,
44
+ EResourceType.MEDIA_UPLOAD_FINALIZE,
45
+ EResourceType.MEDIA_UPLOAD_INITIALIZE,
46
+ EResourceType.TWEET_LIKE,
47
+ EResourceType.TWEET_POST,
48
+ EResourceType.TWEET_RETWEET,
49
+ EResourceType.TWEET_UNLIKE,
50
+ EResourceType.TWEET_UNPOST,
51
+ EResourceType.TWEET_UNRETWEET,
52
+ EResourceType.USER_FOLLOW,
53
+ EResourceType.USER_UNFOLLOW,
54
+ ];
@@ -0,0 +1,52 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { Request } from 'rettiwt-core';
3
+
4
+ import { EResourceType } from '../enums/Resource';
5
+ import { FetchArgs } from '../models/args/FetchArgs';
6
+ import { PostArgs } from '../models/args/PostArgs';
7
+
8
+ /**
9
+ * The request generator from rettiwt-core.
10
+ *
11
+ * @internal
12
+ */
13
+ const request = new Request();
14
+
15
+ /**
16
+ * The collection of requests to various resources.
17
+ *
18
+ * @internal
19
+ */
20
+ export const requests: { [key in keyof typeof EResourceType]: (args: FetchArgs | PostArgs) => AxiosRequestConfig } = {
21
+ /* eslint-disable @typescript-eslint/naming-convention */
22
+ LIST_TWEETS: (args: FetchArgs) => request.list.tweets(args.id!, args.count, args.cursor),
23
+
24
+ MEDIA_UPLOAD_APPEND: (args: PostArgs) => request.media.appendUpload(args.upload!.id!, args.upload!.media!),
25
+ MEDIA_UPLOAD_FINALIZE: (args: PostArgs) => request.media.finalizeUpload(args.upload!.id!),
26
+ MEDIA_UPLOAD_INITIALIZE: (args: PostArgs) => request.media.initializeUpload(args.upload!.size!),
27
+
28
+ TWEET_DETAILS: (args: FetchArgs) => request.tweet.details(args.id!),
29
+ TWEET_LIKE: (args: PostArgs) => request.tweet.like(args.id!),
30
+ TWEET_LIKERS: (args: FetchArgs) => request.tweet.likers(args.id!, args.count, args.cursor),
31
+ TWEET_POST: (args: PostArgs) => request.tweet.post(args.tweet!),
32
+ TWEET_RETWEET: (args: PostArgs) => request.tweet.retweet(args.id!),
33
+ TWEET_RETWEETERS: (args: FetchArgs) => request.tweet.retweeters(args.id!, args.count, args.cursor),
34
+ TWEET_SEARCH: (args: FetchArgs) => request.tweet.search(args.filter!, args.count, args.cursor),
35
+ TWEET_UNLIKE: (args: PostArgs) => request.tweet.unlike(args.id!),
36
+ TWEET_UNPOST: (args: PostArgs) => request.tweet.unpost(args.id!),
37
+ TWEET_UNRETWEET: (args: PostArgs) => request.tweet.unretweet(args.id!),
38
+
39
+ USER_DETAILS_BY_USERNAME: (args: FetchArgs) => request.user.detailsByUsername(args.id!),
40
+ USER_DETAILS_BY_ID: (args: FetchArgs) => request.user.detailsById(args.id!),
41
+ USER_FOLLOW: (args: PostArgs) => request.user.follow(args.id!),
42
+ USER_FOLLOWING: (args: FetchArgs) => request.user.following(args.id!, args.count, args.cursor),
43
+ USER_FOLLOWERS: (args: FetchArgs) => request.user.followers(args.id!, args.count, args.cursor),
44
+ USER_HIGHLIGHTS: (args: FetchArgs) => request.user.highlights(args.id!, args.count, args.cursor),
45
+ USER_LIKES: (args: FetchArgs) => request.user.likes(args.id!, args.count, args.cursor),
46
+ USER_MEDIA: (args: FetchArgs) => request.user.media(args.id!, args.count, args.cursor),
47
+ USER_SUBSCRIPTIONS: (args: FetchArgs) => request.user.subscriptions(args.id!, args.count, args.cursor),
48
+ USER_TIMELINE: (args: FetchArgs) => request.user.tweets(args.id!, args.count, args.cursor),
49
+ USER_TIMELINE_AND_REPLIES: (args: FetchArgs) => request.user.tweetsAndReplies(args.id!, args.count, args.cursor),
50
+ USER_UNFOLLOW: (args: PostArgs) => request.user.unfollow(args.id!),
51
+ /* eslint-enable @typescript-eslint/naming-convention */
52
+ };
@@ -1,10 +1,14 @@
1
- // PACKAGES
2
1
  import { Command, createCommand } from 'commander';
3
- import { Rettiwt } from '../Rettiwt';
4
2
 
5
- // UTILITY
6
3
  import { output } from '../helper/CliUtils';
4
+ import { Rettiwt } from '../Rettiwt';
7
5
 
6
+ /**
7
+ * Creates a new 'auth' command which uses the given Rettiwt instance.
8
+ *
9
+ * @param rettiwt - The Rettiwt instance to use.
10
+ * @returns The created 'auth' command.
11
+ */
8
12
  function createAuthCommand(rettiwt: Rettiwt): Command {
9
13
  // Creating the 'auth' command
10
14
  const auth = createCommand('auth').description('Manage authentication');
@@ -16,16 +20,24 @@ function createAuthCommand(rettiwt: Rettiwt): Command {
16
20
  .argument('<username>', 'The username associated with the Twitter account')
17
21
  .argument('<password>', 'The password to the Twitter account')
18
22
  .action(async (email: string, username: string, password: string) => {
19
- const apiKey: string = await rettiwt.auth.login(email, username, password);
20
- output(apiKey);
23
+ try {
24
+ const apiKey: string = await rettiwt.auth.login(email, username, password);
25
+ output(apiKey);
26
+ } catch (error) {
27
+ output(error);
28
+ }
21
29
  });
22
30
 
23
31
  // Guest
24
32
  auth.command('guest')
25
33
  .description('Generate a new guest key')
26
34
  .action(async () => {
27
- const guestKey: string = await rettiwt.auth.guest();
28
- output(guestKey);
35
+ try {
36
+ const guestKey: string = await rettiwt.auth.guest();
37
+ output(guestKey);
38
+ } catch (error) {
39
+ output(error);
40
+ }
29
41
  });
30
42
 
31
43
  return auth;
@@ -1,10 +1,8 @@
1
- // PACKAGES
2
1
  import { Command, createCommand } from 'commander';
3
- import { Rettiwt } from '../Rettiwt';
4
2
  import { TweetFilter } from 'rettiwt-core';
5
3
 
6
- // UTILITY
7
4
  import { output } from '../helper/CliUtils';
5
+ import { Rettiwt } from '../Rettiwt';
8
6
 
9
7
  /**
10
8
  * Creates a new 'tweet' command which uses the given Rettiwt instance.
@@ -22,8 +20,113 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
22
20
  .description('Fetch the details of tweet with the given id')
23
21
  .argument('<id>', 'The id of the tweet whose details are to be fetched')
24
22
  .action(async (id: string) => {
25
- const details = await rettiwt.tweet.details(id);
26
- output(details);
23
+ try {
24
+ const details = await rettiwt.tweet.details(id);
25
+ output(details);
26
+ } catch (error) {
27
+ output(error);
28
+ }
29
+ });
30
+
31
+ // Like
32
+ tweet
33
+ .command('like')
34
+ .description('Like a tweet')
35
+ .argument('<id>', 'The tweet to like')
36
+ .action(async (id: string) => {
37
+ try {
38
+ const result = await rettiwt.tweet.like(id);
39
+ output(result);
40
+ } catch (error) {
41
+ output(error);
42
+ }
43
+ });
44
+
45
+ // Likers
46
+ tweet
47
+ .command('likers')
48
+ .description('Fetch the list of users who liked the given tweets')
49
+ .argument('<id>', 'The id of the tweet')
50
+ .argument('[count]', 'The number of likers to fetch')
51
+ .argument('[cursor]', 'The cursor to the batch of likers to fetch')
52
+ .action(async (id: string, count?: string, cursor?: string) => {
53
+ try {
54
+ const tweets = await rettiwt.tweet.likers(id, count ? parseInt(count) : undefined, cursor);
55
+ output(tweets);
56
+ } catch (error) {
57
+ output(error);
58
+ }
59
+ });
60
+
61
+ // List
62
+ tweet
63
+ .command('list')
64
+ .description('Fetch the list of tweets in the tweet list with the given id')
65
+ .argument('<id>', 'The id of the tweet list')
66
+ .argument('[count]', 'The number of tweets to fetch')
67
+ .argument('[cursor]', 'The cursor to the batch of tweets to fetch')
68
+ .action(async (id: string, count?: string, cursor?: string) => {
69
+ try {
70
+ const tweets = await rettiwt.tweet.list(id, count ? parseInt(count) : undefined, cursor);
71
+ output(tweets);
72
+ } catch (error) {
73
+ output(error);
74
+ }
75
+ });
76
+
77
+ // Post
78
+ tweet
79
+ .command('post')
80
+ .description('Post a tweet (text only)')
81
+ .argument('<text>', 'The text to post as a tweet')
82
+ .option('-m, --media [string]', 'Comma-separated list of ids of the media item(s) to be posted')
83
+ .option('-q, --quote [string]', 'The id of the tweet to quote in the tweet to be posted')
84
+ .option(
85
+ '-r, --reply [string]',
86
+ 'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
87
+ )
88
+ .action(async (text: string, options?: { media?: string; quote?: string; reply?: string }) => {
89
+ try {
90
+ const result = await rettiwt.tweet.post({
91
+ text: text,
92
+ media: options?.media ? options?.media.split(',').map((item) => ({ id: item })) : undefined,
93
+ quote: options?.quote,
94
+ replyTo: options?.reply,
95
+ });
96
+ output(result);
97
+ } catch (error) {
98
+ output(error);
99
+ }
100
+ });
101
+
102
+ // Retweet
103
+ tweet
104
+ .command('retweet')
105
+ .description('Retweet a tweet')
106
+ .argument('<id>', 'The tweet to retweet')
107
+ .action(async (id: string) => {
108
+ try {
109
+ const result = await rettiwt.tweet.retweet(id);
110
+ output(result);
111
+ } catch (error) {
112
+ output(error);
113
+ }
114
+ });
115
+
116
+ // Retweeters
117
+ tweet
118
+ .command('retweeters')
119
+ .description('Fetch the list of users who retweeted the given tweets')
120
+ .argument('<id>', 'The id of the tweet')
121
+ .argument('[count]', 'The number of retweeters to fetch')
122
+ .argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
123
+ .action(async (id: string, count?: string, cursor?: string) => {
124
+ try {
125
+ const tweets = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
126
+ output(tweets);
127
+ } catch (error) {
128
+ output(error);
129
+ }
27
130
  });
28
131
 
29
132
  // Search
@@ -60,99 +163,84 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
60
163
  .option('--stream', 'Stream the filtered tweets in pseudo-realtime')
61
164
  .option('-i, --interval <number>', 'The polling interval (in ms) to use for streaming. Default is 60000')
62
165
  .action(async (count?: string, cursor?: string, options?: TweetSearchOptions) => {
63
- // If search results are to be streamed
64
- if (options?.stream) {
65
- for await (const tweet of rettiwt.tweet.stream(
66
- new TweetSearchOptions(options).toTweetFilter(),
67
- options?.interval,
68
- )) {
69
- output(tweet);
166
+ try {
167
+ // If search results are to be streamed
168
+ if (options?.stream) {
169
+ for await (const tweet of rettiwt.tweet.stream(
170
+ new TweetSearchOptions(options).toTweetFilter(),
171
+ options?.interval,
172
+ )) {
173
+ output(tweet);
174
+ }
70
175
  }
71
- }
72
- // If a normal search is to be done
73
- else {
74
- const tweets = await rettiwt.tweet.search(
75
- new TweetSearchOptions(options).toTweetFilter(),
76
- count ? parseInt(count) : undefined,
77
- cursor,
78
- );
79
- output(tweets);
176
+ // If a normal search is to be done
177
+ else {
178
+ const tweets = await rettiwt.tweet.search(
179
+ new TweetSearchOptions(options).toTweetFilter(),
180
+ count ? parseInt(count) : undefined,
181
+ cursor,
182
+ );
183
+ output(tweets);
184
+ }
185
+ } catch (error) {
186
+ output(error);
80
187
  }
81
188
  });
82
189
 
83
- // List
190
+ // Unlike
84
191
  tweet
85
- .command('list')
86
- .description('Fetch the list of tweets in the tweet list with the given id')
87
- .argument('<id>', 'The id of the tweet list')
88
- .argument('[count]', 'The number of tweets to fetch')
89
- .argument('[cursor]', 'The cursor to the batch of tweets to fetch')
90
- .action(async (id: string, count?: string, cursor?: string) => {
91
- const tweets = await rettiwt.tweet.list(id, count ? parseInt(count) : undefined, cursor);
92
- output(tweets);
93
- });
94
-
95
- // Likes
96
- tweet
97
- .command('likes')
98
- .description('Fetch the list of users who liked the given tweets')
192
+ .command('unlike')
193
+ .description('Unlike a tweet')
99
194
  .argument('<id>', 'The id of the tweet')
100
- .argument('[count]', 'The number of likers to fetch')
101
- .argument('[cursor]', 'The cursor to the batch of likers to fetch')
102
- .action(async (id: string, count?: string, cursor?: string) => {
103
- const tweets = await rettiwt.tweet.favoriters(id, count ? parseInt(count) : undefined, cursor);
104
- output(tweets);
195
+ .action(async (id: string) => {
196
+ try {
197
+ const result = await rettiwt.tweet.unlike(id);
198
+ output(result);
199
+ } catch (error) {
200
+ output(error);
201
+ }
105
202
  });
106
203
 
107
- // Retweets
204
+ // Unpost
108
205
  tweet
109
- .command('retweets')
110
- .description('Fetch the list of users who retweeted the given tweets')
206
+ .command('unpost')
207
+ .description('Unpost a tweet')
111
208
  .argument('<id>', 'The id of the tweet')
112
- .argument('[count]', 'The number of retweeters to fetch')
113
- .argument('[cursor]', 'The cursor to the batch of retweeters to fetch')
114
- .action(async (id: string, count?: string, cursor?: string) => {
115
- const tweets = await rettiwt.tweet.retweeters(id, count ? parseInt(count) : undefined, cursor);
116
- output(tweets);
117
- });
118
-
119
- // Post
120
- tweet
121
- .command('post')
122
- .description('Post a tweet (text only)')
123
- .argument('<text>', 'The text to post as a tweet')
124
- .option('-m, --media [string]', 'Comma-separated list of path(s) to the media item(s) to be posted')
125
- .option(
126
- '-r, --reply [string]',
127
- 'The id of the tweet to which the reply is to be made, if the tweet is to be a reply',
128
- )
129
- .action(async (text: string, options?: { media?: string; reply?: string }) => {
130
- const result = await rettiwt.tweet.tweet(
131
- text,
132
- options?.media ? options?.media.split(',').map((item) => ({ path: item })) : undefined,
133
- options?.reply,
134
- );
135
- output(result);
209
+ .action(async (id: string) => {
210
+ try {
211
+ const result = await rettiwt.tweet.unpost(id);
212
+ output(result);
213
+ } catch (error) {
214
+ output(error);
215
+ }
136
216
  });
137
217
 
138
- // Like
218
+ // Unretweet
139
219
  tweet
140
- .command('like')
141
- .description('Like a tweet')
142
- .argument('<id>', 'The tweet to like')
220
+ .command('unretweet')
221
+ .description('Unretweet a tweet')
222
+ .argument('<id>', 'The id of the tweet')
143
223
  .action(async (id: string) => {
144
- const result = await rettiwt.tweet.favorite(id);
145
- output(result);
224
+ try {
225
+ const result = await rettiwt.tweet.unretweet(id);
226
+ output(result);
227
+ } catch (error) {
228
+ output(error);
229
+ }
146
230
  });
147
231
 
148
- // Retweet
232
+ // Upload
149
233
  tweet
150
- .command('retweet')
151
- .description('Retweet a tweet')
152
- .argument('<id>', 'The tweet to retweet')
153
- .action(async (id: string) => {
154
- const result = await rettiwt.tweet.retweet(id);
155
- output(result);
234
+ .command('upload')
235
+ .description('Upload a media file and returns the alloted id (valid for 24 hrs)')
236
+ .argument('<path>', 'The path to the media to upload')
237
+ .action(async (path: string) => {
238
+ try {
239
+ const id = await rettiwt.tweet.upload(path);
240
+ output(id);
241
+ } catch (error) {
242
+ output(error);
243
+ }
156
244
  });
157
245
 
158
246
  return tweet;
@@ -164,24 +252,24 @@ function createTweetCommand(rettiwt: Rettiwt): Command {
164
252
  * @remarks The search options are implementations of the ones offered by {@link TweetFilter}
165
253
  */
166
254
  class TweetSearchOptions {
167
- public from?: string;
168
- public to?: string;
169
- public words?: string;
170
- public phrase?: string;
171
- public optionalWords?: string;
255
+ public end?: string;
256
+ public excludeLinks?: boolean = false;
257
+ public excludeReplies?: boolean = false;
172
258
  public excludeWords?: string;
259
+ public from?: string;
173
260
  public hashtags?: string;
261
+ public interval?: number;
174
262
  public mentions?: string;
175
- public minReplies?: number;
176
263
  public minLikes?: number;
264
+ public minReplies?: number;
177
265
  public minRetweets?: number;
266
+ public optionalWords?: string;
267
+ public phrase?: string;
178
268
  public quoted?: string;
179
- public excludeLinks?: boolean = false;
180
- public excludeReplies?: boolean = false;
181
269
  public start?: string;
182
- public end?: string;
183
270
  public stream?: boolean;
184
- public interval?: number;
271
+ public to?: string;
272
+ public words?: string;
185
273
 
186
274
  /**
187
275
  * Initializes a new object from the given options.