@devvit/reddit 0.11.17-next-2025-05-28-417d95f5a.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.
- package/LICENSE +26 -0
- package/README.md +5 -0
- package/RedditClient.d.ts +1155 -0
- package/RedditClient.d.ts.map +1 -0
- package/RedditClient.js +1417 -0
- package/common.d.ts +10 -0
- package/common.d.ts.map +1 -0
- package/common.js +5 -0
- package/getReddit.d.ts +3 -0
- package/getReddit.d.ts.map +1 -0
- package/getReddit.js +8 -0
- package/getRedditApiPlugins.d.ts +23 -0
- package/getRedditApiPlugins.d.ts.map +1 -0
- package/getRedditApiPlugins.js +25 -0
- package/getUserActionsPlugin.d.ts +6 -0
- package/getUserActionsPlugin.d.ts.map +1 -0
- package/getUserActionsPlugin.js +12 -0
- package/graphql/GraphQL.d.ts +10 -0
- package/graphql/GraphQL.d.ts.map +1 -0
- package/graphql/GraphQL.js +27 -0
- package/helpers/makeGettersEnumerable.d.ts +2 -0
- package/helpers/makeGettersEnumerable.d.ts.map +1 -0
- package/helpers/makeGettersEnumerable.js +19 -0
- package/helpers/permissions.d.ts +6 -0
- package/helpers/permissions.d.ts.map +1 -0
- package/helpers/permissions.js +24 -0
- package/helpers/richtextToString.d.ts +3 -0
- package/helpers/richtextToString.d.ts.map +1 -0
- package/helpers/richtextToString.js +14 -0
- package/helpers/textFallbackToRichtext.d.ts +4 -0
- package/helpers/textFallbackToRichtext.d.ts.map +1 -0
- package/helpers/textFallbackToRichtext.js +14 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/models/Comment.d.ts +138 -0
- package/models/Comment.d.ts.map +1 -0
- package/models/Comment.js +597 -0
- package/models/Flair.d.ts +171 -0
- package/models/Flair.d.ts.map +1 -0
- package/models/Flair.js +293 -0
- package/models/Listing.d.ts +53 -0
- package/models/Listing.d.ts.map +1 -0
- package/models/Listing.js +101 -0
- package/models/ModAction.d.ts +32 -0
- package/models/ModAction.d.ts.map +1 -0
- package/models/ModAction.js +70 -0
- package/models/ModMail.d.ts +655 -0
- package/models/ModMail.d.ts.map +1 -0
- package/models/ModMail.js +723 -0
- package/models/ModNote.d.ts +57 -0
- package/models/ModNote.d.ts.map +1 -0
- package/models/ModNote.js +103 -0
- package/models/Post.d.ts +491 -0
- package/models/Post.d.ts.map +1 -0
- package/models/Post.js +1022 -0
- package/models/PrivateMessage.d.ts +52 -0
- package/models/PrivateMessage.d.ts.map +1 -0
- package/models/PrivateMessage.js +126 -0
- package/models/Subreddit.d.ts +606 -0
- package/models/Subreddit.d.ts.map +1 -0
- package/models/Subreddit.js +750 -0
- package/models/User.d.ts +238 -0
- package/models/User.d.ts.map +1 -0
- package/models/User.js +458 -0
- package/models/Vault.d.ts +32 -0
- package/models/Vault.d.ts.map +1 -0
- package/models/Vault.js +25 -0
- package/models/Widget.d.ts +133 -0
- package/models/Widget.d.ts.map +1 -0
- package/models/Widget.js +467 -0
- package/models/WikiPage.d.ts +137 -0
- package/models/WikiPage.d.ts.map +1 -0
- package/models/WikiPage.js +329 -0
- package/models/index.d.ts +14 -0
- package/models/index.d.ts.map +1 -0
- package/models/index.js +13 -0
- package/package.json +46 -0
- package/tests/comment.api.test.d.ts.map +1 -0
- package/tests/flair.api.test.d.ts.map +1 -0
- package/tests/modmail.api.test.d.ts.map +1 -0
- package/tests/modnote.api.test.d.ts.map +1 -0
- package/tests/post.api.test.d.ts.map +1 -0
- package/tests/subreddit.api.test.d.ts.map +1 -0
- package/tests/user.api.test.d.ts.map +1 -0
- package/tests/utils/createTestPreview.d.ts +2 -0
- package/tests/utils/createTestPreview.d.ts.map +1 -0
- package/tests/utils/createTestPreview.js +5 -0
- package/tests/utils/redditApiPluginsMock.d.ts +203 -0
- package/tests/utils/redditApiPluginsMock.d.ts.map +1 -0
- package/tests/utils/redditApiPluginsMock.js +202 -0
- package/tests/utils/runWithTestContext.d.ts +4 -0
- package/tests/utils/runWithTestContext.d.ts.map +1 -0
- package/tests/utils/runWithTestContext.js +12 -0
- package/tests/utils/userActionsPluginMock.d.ts +6 -0
- package/tests/utils/userActionsPluginMock.d.ts.map +1 -0
- package/tests/utils/userActionsPluginMock.js +5 -0
package/RedditClient.js
ADDED
|
@@ -0,0 +1,1417 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _RedditClient_instances, _RedditClient_modMailService, _RedditClient_currentUser, _RedditClient_currentUsername, _RedditClient_metadata_get;
|
|
13
|
+
import {} from '@devvit/protos';
|
|
14
|
+
import { getContext } from '@devvit/server';
|
|
15
|
+
import { Header } from '@devvit/shared-types/Header.js';
|
|
16
|
+
import { asT2ID } from '@devvit/shared-types/tid.js';
|
|
17
|
+
import { asT3ID, asTID, isT1ID, isT3ID } from '@devvit/shared-types/tid.js';
|
|
18
|
+
import { getRedditApiPlugins } from './getRedditApiPlugins.js';
|
|
19
|
+
import { AboutLocations, Comment, Flair, FlairTemplate, getModerationLog, getSubredditInfoById, getSubredditInfoByName, getSubredditLeaderboard, getSubredditStyles, getVaultByAddress, getVaultByUserId, ModMailService, ModNote, Post, PrivateMessage, Subreddit, User, Widget, WikiPage, } from './models/index.js';
|
|
20
|
+
/**
|
|
21
|
+
* The Reddit API Client
|
|
22
|
+
*
|
|
23
|
+
* To use the Reddit API Client, add it to the plugin configuration at the top of the file.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
*
|
|
28
|
+
* Devvit.configure({
|
|
29
|
+
* redditAPI: true,
|
|
30
|
+
* // other plugins
|
|
31
|
+
* })
|
|
32
|
+
|
|
33
|
+
* // use within one of our capability handlers e.g. Menu Actions, Triggers, Scheduled Job Type, etc
|
|
34
|
+
* async (event, context) => {
|
|
35
|
+
* const subreddit = await context.reddit.getSubredditById(context.subredditId);
|
|
36
|
+
* context.reddit.submitPost({
|
|
37
|
+
* subredditName: subreddit.name,
|
|
38
|
+
* title: 'test post',
|
|
39
|
+
* text: 'test body',
|
|
40
|
+
* })
|
|
41
|
+
* // additional code
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export class RedditClient {
|
|
46
|
+
constructor() {
|
|
47
|
+
_RedditClient_instances.add(this);
|
|
48
|
+
_RedditClient_modMailService.set(this, void 0);
|
|
49
|
+
_RedditClient_currentUser.set(this, void 0);
|
|
50
|
+
_RedditClient_currentUsername.set(this, void 0);
|
|
51
|
+
__classPrivateFieldSet(this, _RedditClient_modMailService, new ModMailService(), "f");
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get ModMail API object
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```ts
|
|
58
|
+
* await reddit.modMail.reply({
|
|
59
|
+
* body: "Here is my message",
|
|
60
|
+
* conversationId: "abcd42";
|
|
61
|
+
* })
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
get modMail() {
|
|
65
|
+
return __classPrivateFieldGet(this, _RedditClient_modMailService, "f");
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Gets a {@link Subreddit} object by ID
|
|
69
|
+
*
|
|
70
|
+
* @deprecated Use {@link getSubredditInfoById} instead.
|
|
71
|
+
* @param {string} id - The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
|
|
72
|
+
* @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const memes = await reddit.getSubredditById('t5_2qjpg');
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
getSubredditById(id) {
|
|
79
|
+
return Subreddit.getById(asTID(id));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets a {@link SubredditInfo} object by ID
|
|
83
|
+
*
|
|
84
|
+
* @param {string} id - The ID (starting with t5_) of the subreddit to retrieve. e.g. t5_2qjpg
|
|
85
|
+
* @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const memes = await reddit.getSubredditInfoById('t5_2qjpg');
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
getSubredditInfoById(id) {
|
|
92
|
+
return getSubredditInfoById(id);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Gets a {@link Subreddit} object by name
|
|
96
|
+
*
|
|
97
|
+
* @deprecated Use {@link getSubredditInfoByName} instead.
|
|
98
|
+
* @param {string} name The name of a subreddit omitting the r/. This is case insensitive.
|
|
99
|
+
* @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
|
|
100
|
+
* @example
|
|
101
|
+
* ```ts
|
|
102
|
+
* const askReddit = await reddit.getSubredditByName('askReddit');
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
getSubredditByName(name) {
|
|
106
|
+
return Subreddit.getByName(name);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets a {@link SubredditInfo} object by name
|
|
110
|
+
*
|
|
111
|
+
* @param {string} name The name of a subreddit omitting the r/. This is case insensitive.
|
|
112
|
+
* @returns {Promise<SubredditInfo>} A Promise that resolves a SubredditInfo object.
|
|
113
|
+
* @example
|
|
114
|
+
* ```ts
|
|
115
|
+
* const askReddit = await reddit.getSubredditInfoByName('askReddit');
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
getSubredditInfoByName(name) {
|
|
119
|
+
return getSubredditInfoByName(name);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Add a removal reason to a subreddit
|
|
123
|
+
*
|
|
124
|
+
* @param subredditName Name of the subreddit being removed.
|
|
125
|
+
* @param options Options.
|
|
126
|
+
* @param options.title The title of the removal reason.
|
|
127
|
+
* @param options.message The message associated with the removal reason.
|
|
128
|
+
* @example
|
|
129
|
+
* ```ts
|
|
130
|
+
* const newReason = await reddit.addSubredditRemovalReasons(
|
|
131
|
+
* 'askReddit',
|
|
132
|
+
* {
|
|
133
|
+
* title: 'Spam',
|
|
134
|
+
* message: 'This is spam!'
|
|
135
|
+
* }
|
|
136
|
+
* );
|
|
137
|
+
* console.log(newReason.id)
|
|
138
|
+
* ```
|
|
139
|
+
*
|
|
140
|
+
* @returns {string} Removal Reason ID
|
|
141
|
+
*/
|
|
142
|
+
addSubredditRemovalReason(subredditName, options) {
|
|
143
|
+
return Subreddit.addRemovalReason(subredditName, options.title, options.message);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Get the list of subreddit's removal reasons (ordered)
|
|
147
|
+
*
|
|
148
|
+
* @param subredditName
|
|
149
|
+
* @example
|
|
150
|
+
* ```ts
|
|
151
|
+
* const reasons = await reddit.getSubredditRemovalReasons('askReddit');
|
|
152
|
+
*
|
|
153
|
+
* for (let reason of reasons) {
|
|
154
|
+
* console.log(reason.id, reason.message, reason.title)
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
157
|
+
*
|
|
158
|
+
* @returns Ordered array of Removal Reasons
|
|
159
|
+
*/
|
|
160
|
+
getSubredditRemovalReasons(subredditName) {
|
|
161
|
+
return Subreddit.getRemovalReasons(subredditName);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Retrieves the current subreddit.
|
|
165
|
+
*
|
|
166
|
+
* @returns {Promise<Subreddit>} A Promise that resolves a Subreddit object.
|
|
167
|
+
* @example
|
|
168
|
+
* ```ts
|
|
169
|
+
* const currentSubreddit = await reddit.getCurrentSubreddit();
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
async getCurrentSubreddit() {
|
|
173
|
+
const currentSubreddit = await Subreddit.getFromMetadata();
|
|
174
|
+
if (!currentSubreddit) {
|
|
175
|
+
throw new Error("Couldn't get current subreddit");
|
|
176
|
+
}
|
|
177
|
+
return currentSubreddit;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Gets a {@link Post} object by ID
|
|
181
|
+
*
|
|
182
|
+
* @param id
|
|
183
|
+
* @returns A Promise that resolves to a Post object.
|
|
184
|
+
*/
|
|
185
|
+
getPostById(id) {
|
|
186
|
+
return Post.getById(asTID(id));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Submits a new post to a subreddit.
|
|
190
|
+
*
|
|
191
|
+
* @param options - Either a self post or a link post.
|
|
192
|
+
* @returns A Promise that resolves to a Post object.
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* const post = await reddit.submitPost({
|
|
196
|
+
* subredditName: 'devvit',
|
|
197
|
+
* title: 'Hello World',
|
|
198
|
+
* richtext: new RichTextBuilder()
|
|
199
|
+
* .heading({ level: 1 }, (h) => {
|
|
200
|
+
* h.rawText('Hello world');
|
|
201
|
+
* })
|
|
202
|
+
* .codeBlock({}, (cb) => cb.rawText('This post was created via the Devvit API'))
|
|
203
|
+
* .build()
|
|
204
|
+
* });
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* By default, `submitPost()` creates a Post on behalf of the App account, but it may be called on behalf of the User making the request by setting the option `runAs: RunAs.USER`.
|
|
208
|
+
* When using `runAs: RunAs.USER` to create an experience Post, you must specify the `userGeneratedContent` option. For example:
|
|
209
|
+
* @example
|
|
210
|
+
* ```ts
|
|
211
|
+
* import { RunAs } from '@devvit/public-api';
|
|
212
|
+
*
|
|
213
|
+
* const post = await reddit.submitPost({
|
|
214
|
+
* title: 'My Devvit Post',
|
|
215
|
+
* runAs: RunAs.USER,
|
|
216
|
+
* userGeneratedContent: {
|
|
217
|
+
* text: "hello there",
|
|
218
|
+
* imageUrls: ["https://styles.redditmedia.com/t5_5wa5ww/styles/communityIcon_wyopomb2xb0a1.png", "https://styles.redditmedia.com/t5_49fkib/styles/bannerBackgroundImage_5a4axis7cku61.png"]
|
|
219
|
+
},
|
|
220
|
+
* subredditName: await reddit.getCurrentSubredditName(),
|
|
221
|
+
* textFallback: {
|
|
222
|
+
* text: 'This is a Devvit post!',
|
|
223
|
+
* },
|
|
224
|
+
* preview: (
|
|
225
|
+
* <vstack height="100%" width="100%" alignment="middle center">
|
|
226
|
+
* <text size="large">Loading...</text>
|
|
227
|
+
* </vstack>
|
|
228
|
+
* ),
|
|
229
|
+
* });
|
|
230
|
+
* ```
|
|
231
|
+
*/
|
|
232
|
+
submitPost(options) {
|
|
233
|
+
return Post.submit(options);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Crossposts a post to a subreddit.
|
|
237
|
+
*
|
|
238
|
+
* @param options - Options for crossposting a post
|
|
239
|
+
* @param options.subredditName - The name of the subreddit to crosspost to
|
|
240
|
+
* @param options.postId - The ID of the post to crosspost
|
|
241
|
+
* @param options.title - The title of the crosspost
|
|
242
|
+
* @returns - A Promise that resolves to a Post object.
|
|
243
|
+
*/
|
|
244
|
+
crosspost(options) {
|
|
245
|
+
return Post.crosspost(options);
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Gets a {@link User} object by ID
|
|
249
|
+
*
|
|
250
|
+
* @param id - The ID (starting with t2_) of the user to retrieve. e.g. t2_1qjpg
|
|
251
|
+
* @returns A Promise that resolves to a User object.
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* const user = await reddit.getUserById('t2_1qjpg');
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
getUserById(id) {
|
|
258
|
+
return User.getById(asTID(id));
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Gets a {@link User} object by username
|
|
262
|
+
*
|
|
263
|
+
* @param username - The username of the user omitting the u/. e.g. 'devvit'
|
|
264
|
+
* @returns A Promise that resolves to a User object or undefined if user is
|
|
265
|
+
* not found (user doesn't exist, account suspended, etc).
|
|
266
|
+
* @example
|
|
267
|
+
* ```ts
|
|
268
|
+
* const user = await reddit.getUserByUsername('devvit');
|
|
269
|
+
* if (user) {
|
|
270
|
+
* console.log(user)
|
|
271
|
+
* }
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
274
|
+
getUserByUsername(username) {
|
|
275
|
+
return User.getByUsername(username);
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Get the current calling user's username.
|
|
279
|
+
* Resolves to undefined for logged-out custom post renders.
|
|
280
|
+
*
|
|
281
|
+
* @returns A Promise that resolves to a string representing the username or undefined
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* const username = await reddit.getCurrentUsername();
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
async getCurrentUsername() {
|
|
288
|
+
const curUser = await this.getCurrentUser();
|
|
289
|
+
if (!curUser) {
|
|
290
|
+
return undefined;
|
|
291
|
+
}
|
|
292
|
+
__classPrivateFieldSet(this, _RedditClient_currentUsername, __classPrivateFieldGet(this, _RedditClient_currentUsername, "f") ?? curUser.username, "f");
|
|
293
|
+
return __classPrivateFieldGet(this, _RedditClient_currentUsername, "f");
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Get the current calling user.
|
|
297
|
+
* Resolves to undefined for logged-out custom post renders.
|
|
298
|
+
*
|
|
299
|
+
* @returns A Promise that resolves to a User object or undefined
|
|
300
|
+
* @example
|
|
301
|
+
* ```ts
|
|
302
|
+
* const user = await reddit.getCurrentUser();
|
|
303
|
+
* ```
|
|
304
|
+
*/
|
|
305
|
+
async getCurrentUser() {
|
|
306
|
+
const userId = getContext().userId;
|
|
307
|
+
if (!userId) {
|
|
308
|
+
return undefined;
|
|
309
|
+
}
|
|
310
|
+
__classPrivateFieldSet(this, _RedditClient_currentUser, __classPrivateFieldGet(this, _RedditClient_currentUser, "f") ?? User.getById(asT2ID(userId)), "f");
|
|
311
|
+
return __classPrivateFieldGet(this, _RedditClient_currentUser, "f");
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Get the user that the app runs as on the provided metadata.
|
|
315
|
+
*
|
|
316
|
+
* @returns A Promise that resolves to a User object.
|
|
317
|
+
* @example
|
|
318
|
+
* ```ts
|
|
319
|
+
* const user = await reddit.getAppUser(metadata);
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
getAppUser() {
|
|
323
|
+
const appUsername = getContext().appName;
|
|
324
|
+
return User.getByUsername(appUsername);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get the snoovatar URL for a given username.
|
|
328
|
+
*
|
|
329
|
+
* @param username - The username of the snoovatar to retrieve
|
|
330
|
+
* @returns A Promise that resolves to a URL of the snoovatar image if it exists.
|
|
331
|
+
*/
|
|
332
|
+
async getSnoovatarUrl(username) {
|
|
333
|
+
const currentUsername = await this.getCurrentUsername();
|
|
334
|
+
if (currentUsername && username === currentUsername) {
|
|
335
|
+
const snoovatarUrl = __classPrivateFieldGet(this, _RedditClient_instances, "a", _RedditClient_metadata_get)?.[Header.UserSnoovatarUrl]?.values[0];
|
|
336
|
+
if (snoovatarUrl) {
|
|
337
|
+
return snoovatarUrl;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
return User.getSnoovatarUrl(username);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Get a {@link Comment} object by ID
|
|
344
|
+
*
|
|
345
|
+
* @param id - The ID (starting with t1_) of the comment to retrieve. e.g. t1_1qjpg
|
|
346
|
+
* @returns A Promise that resolves to a Comment object.
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* const comment = await reddit.getCommentById('t1_1qjpg');
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
getCommentById(id) {
|
|
353
|
+
return Comment.getById(asTID(id));
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Get a list of comments from a specific post or comment.
|
|
357
|
+
*
|
|
358
|
+
* @param options - Options for the request
|
|
359
|
+
* @param options.postId - The ID of the post e.g. 't3_1qjpg'
|
|
360
|
+
* @param options.commentId - The ID of the comment e.g. 't1_1qjpg'
|
|
361
|
+
* @param options.limit - The maximum number of comments to return. e.g. 1000
|
|
362
|
+
* @param options.pageSize - The number of comments to return per request. e.g. 100
|
|
363
|
+
* @param options.sort - The sort order of the comments. e.g. 'new'
|
|
364
|
+
* @returns A Listing of Comment objects.
|
|
365
|
+
* @example
|
|
366
|
+
* ```ts
|
|
367
|
+
* const comments = await reddit.getComments({
|
|
368
|
+
* postId: 't3_1qjpg',
|
|
369
|
+
* limit: 1000,
|
|
370
|
+
* pageSize: 100
|
|
371
|
+
* }).all();
|
|
372
|
+
* ```
|
|
373
|
+
*/
|
|
374
|
+
getComments(options) {
|
|
375
|
+
return Comment.getComments(options);
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Get a list of comments by a specific user.
|
|
379
|
+
*
|
|
380
|
+
* @param options - Options for the request
|
|
381
|
+
* @param options.username - The username of the user omitting the u/. e.g. 'spez'
|
|
382
|
+
* @param options.sort - The sort order of the comments. e.g. 'new'
|
|
383
|
+
* @param options.timeframe - The timeframe of the comments. e.g. 'all'
|
|
384
|
+
* @param options.limit - The maximum number of comments to return. e.g. 1000
|
|
385
|
+
* @param options.pageSize - The number of comments to return per request. e.g. 100
|
|
386
|
+
* @returns A Listing of Comment objects.
|
|
387
|
+
*/
|
|
388
|
+
getCommentsByUser(options) {
|
|
389
|
+
return Comment.getCommentsByUser(options);
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Submit a new comment to a post or comment.
|
|
393
|
+
*
|
|
394
|
+
* @param options - You must provide either `options.text` or `options.richtext` but not both.
|
|
395
|
+
* @param options.id - The ID of the post or comment to comment on. e.g. 't3_1qjpg' for post and 't1_1qgif' for comment
|
|
396
|
+
* @param options.text - The text of the comment
|
|
397
|
+
* @param options.richtext - The rich text of the comment
|
|
398
|
+
* @param options.runAs - The user type to submit the comment as, eg 'APP' or 'USER'
|
|
399
|
+
* @returns A Promise that resolves to a Comment object.
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* import { RunAs } from '@devvit/public-api';
|
|
403
|
+
*
|
|
404
|
+
* const comment = await reddit.submitComment({
|
|
405
|
+
* id: 't1_1qgif',
|
|
406
|
+
* text: 'Hello world!',
|
|
407
|
+
* runAs: RunAs.APP,
|
|
408
|
+
* })
|
|
409
|
+
* ```
|
|
410
|
+
*/
|
|
411
|
+
submitComment(options) {
|
|
412
|
+
return Comment.submit({
|
|
413
|
+
...options,
|
|
414
|
+
id: asTID(options.id),
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Get a list of controversial posts from a specific subreddit.
|
|
419
|
+
*
|
|
420
|
+
* @param options - Options for the request
|
|
421
|
+
* @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
|
|
422
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
423
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
424
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
425
|
+
* @returns A Listing of Post objects.
|
|
426
|
+
* @example
|
|
427
|
+
* ```ts
|
|
428
|
+
* const posts = await reddit.getControversialPosts({
|
|
429
|
+
* subredditName: 'memes',
|
|
430
|
+
* timeframe: 'day',
|
|
431
|
+
* limit: 1000,
|
|
432
|
+
* pageSize: 100
|
|
433
|
+
* }).all();
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
getControversialPosts(options) {
|
|
437
|
+
return Post.getControversialPosts(options);
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Get a list of controversial posts from a specific subreddit.
|
|
441
|
+
*
|
|
442
|
+
* @param options - Options for the request
|
|
443
|
+
* @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
|
|
444
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
445
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
446
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
447
|
+
* @returns A Listing of Post objects.
|
|
448
|
+
* @example
|
|
449
|
+
* ```ts
|
|
450
|
+
* const posts = await reddit.getControversialPosts({
|
|
451
|
+
* subredditName: 'memes',
|
|
452
|
+
* timeframe: 'day',
|
|
453
|
+
* limit: 1000,
|
|
454
|
+
* pageSize: 100
|
|
455
|
+
* }).all();
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
getTopPosts(options) {
|
|
459
|
+
return Post.getTopPosts(options);
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Get a list of hot posts from a specific subreddit.
|
|
463
|
+
*
|
|
464
|
+
* @param options - Options for the request
|
|
465
|
+
* @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
|
|
466
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
467
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
468
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
469
|
+
* @returns A Listing of Post objects.
|
|
470
|
+
* @example
|
|
471
|
+
* ```ts
|
|
472
|
+
* const posts = await reddit.getHotPosts({
|
|
473
|
+
* subredditName: 'memes',
|
|
474
|
+
* timeframe: 'day',
|
|
475
|
+
* limit: 1000,
|
|
476
|
+
* pageSize: 100
|
|
477
|
+
* }).all();
|
|
478
|
+
* ```
|
|
479
|
+
*/
|
|
480
|
+
getHotPosts(options) {
|
|
481
|
+
return Post.getHotPosts(options);
|
|
482
|
+
}
|
|
483
|
+
/**
|
|
484
|
+
* Get a list of new posts from a specific subreddit.
|
|
485
|
+
*
|
|
486
|
+
* @param options - Options for the request
|
|
487
|
+
* @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
|
|
488
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
489
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
490
|
+
* @returns A Listing of Post objects.
|
|
491
|
+
* @example
|
|
492
|
+
* ```ts
|
|
493
|
+
* const posts = await reddit.getNewPosts({
|
|
494
|
+
* subredditName: 'memes',
|
|
495
|
+
* limit: 1000,
|
|
496
|
+
* pageSize: 100
|
|
497
|
+
* }).all();
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
getNewPosts(options) {
|
|
501
|
+
return Post.getNewPosts(options);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Get a list of hot posts from a specific subreddit.
|
|
505
|
+
*
|
|
506
|
+
* @param options - Options for the request
|
|
507
|
+
* @param options.subredditName - The name of the subreddit to get posts from. e.g. 'memes'
|
|
508
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
509
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
510
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
511
|
+
* @returns A Listing of Post objects.
|
|
512
|
+
* @example
|
|
513
|
+
* ```ts
|
|
514
|
+
* const posts = await reddit.getRisingPosts({
|
|
515
|
+
* subredditName: 'memes',
|
|
516
|
+
* timeframe: 'day',
|
|
517
|
+
* limit: 1000,
|
|
518
|
+
* pageSize: 100
|
|
519
|
+
* }).all();
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
getRisingPosts(options) {
|
|
523
|
+
return Post.getRisingPosts(options);
|
|
524
|
+
}
|
|
525
|
+
/**
|
|
526
|
+
* Get a list of posts from a specific user.
|
|
527
|
+
*
|
|
528
|
+
* @param options - Options for the request
|
|
529
|
+
* @param options.username - The username of the user omitting the u/. e.g. 'spez'
|
|
530
|
+
* @param options.sort - The sort method to use. e.g. 'new'
|
|
531
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
532
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
533
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
534
|
+
* @returns A Listing of Post objects.
|
|
535
|
+
*/
|
|
536
|
+
getPostsByUser(options) {
|
|
537
|
+
return Post.getPostsByUser(options);
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* Get a list of posts and comments from a specific user.
|
|
541
|
+
*
|
|
542
|
+
* @param options - Options for the request
|
|
543
|
+
* @param options.username - The username of the user omitting the u/. e.g. 'spez'
|
|
544
|
+
* @param options.sort - The sort method to use. e.g. 'new'
|
|
545
|
+
* @param options.timeframe - The timeframe to get posts from. e.g. 'day'
|
|
546
|
+
* @param options.limit - The maximum number of posts to return. e.g. 1000
|
|
547
|
+
* @param options.pageSize - The number of posts to return per request. e.g. 100
|
|
548
|
+
* @returns A Listing of `Post` and `Comment` objects.
|
|
549
|
+
*/
|
|
550
|
+
getCommentsAndPostsByUser(options) {
|
|
551
|
+
return User.getOverview(options);
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Get the moderation log for a subreddit.
|
|
555
|
+
*
|
|
556
|
+
* @param options - Options for the request
|
|
557
|
+
* @param options.subredditName - The name of the subreddit to get the moderation log from. e.g. 'memes'
|
|
558
|
+
* @param options.moderatorUsernames (optional) A moderator filter. Accepts an array of usernames
|
|
559
|
+
* @param options.type (optional) Filter the entries by the type of the Moderator action
|
|
560
|
+
* @param options.limit - (optional) The maximum number of ModActions to return. e.g. 1000
|
|
561
|
+
* @param options.pageSize - (optional) The number of ModActions to return per request. e.g. 100
|
|
562
|
+
* @returns A Listing of ModAction objects.
|
|
563
|
+
* @example
|
|
564
|
+
* ```ts
|
|
565
|
+
* const modActions = await reddit.getModerationLog({
|
|
566
|
+
* subredditName: 'memes',
|
|
567
|
+
* moderatorUsernames: ['spez'],
|
|
568
|
+
* type: 'banuser',
|
|
569
|
+
* limit: 1000,
|
|
570
|
+
* pageSize: 100
|
|
571
|
+
* }).all();
|
|
572
|
+
* ```
|
|
573
|
+
*/
|
|
574
|
+
getModerationLog(options) {
|
|
575
|
+
return getModerationLog(options);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Get a list of users who have been approved to post in a subreddit.
|
|
579
|
+
*
|
|
580
|
+
* @param options - Options for the request
|
|
581
|
+
* @param options.subredditName - The name of the subreddit to get the approved users from. e.g. 'memes'
|
|
582
|
+
* @param options.username - Use this to see if a user is approved to post in the subreddit.
|
|
583
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
584
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
585
|
+
* @returns A Listing of User objects.
|
|
586
|
+
*/
|
|
587
|
+
getApprovedUsers(options) {
|
|
588
|
+
return User.getSubredditUsersByType({
|
|
589
|
+
type: 'contributors',
|
|
590
|
+
...options,
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Approve a user to post in a subreddit.
|
|
595
|
+
*
|
|
596
|
+
* @param username - The username of the user to approve. e.g. 'spez'
|
|
597
|
+
* @param subredditName - The name of the subreddit to approve the user in. e.g. 'memes'
|
|
598
|
+
*/
|
|
599
|
+
approveUser(username, subredditName) {
|
|
600
|
+
return User.createRelationship({
|
|
601
|
+
username,
|
|
602
|
+
subredditName,
|
|
603
|
+
type: 'contributor',
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Remove a user's approval to post in a subreddit.
|
|
608
|
+
*
|
|
609
|
+
* @param username - The username of the user to remove approval from. e.g. 'spez'
|
|
610
|
+
* @param subredditName - The name of the subreddit to remove the user's approval from. e.g. 'memes'
|
|
611
|
+
*/
|
|
612
|
+
removeUser(username, subredditName) {
|
|
613
|
+
return User.removeRelationship({
|
|
614
|
+
username,
|
|
615
|
+
subredditName,
|
|
616
|
+
type: 'contributor',
|
|
617
|
+
});
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Get a list of users who are wiki contributors of a subreddit.
|
|
621
|
+
*
|
|
622
|
+
* @param options - Options for the request
|
|
623
|
+
* @param options.subredditName - The name of the subreddit to get the wiki contributors from. e.g. 'memes'
|
|
624
|
+
* @param options.username - Use this to see if a user is a wiki contributor for the subreddit.
|
|
625
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
626
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
627
|
+
* @returns A Listing of User objects.
|
|
628
|
+
*/
|
|
629
|
+
getWikiContributors(options) {
|
|
630
|
+
return User.getSubredditUsersByType({
|
|
631
|
+
type: 'wikicontributors',
|
|
632
|
+
...options,
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* Add a user as a wiki contributor for a subreddit.
|
|
637
|
+
*
|
|
638
|
+
* @param username - The username of the user to add as a wiki contributor. e.g. 'spez'
|
|
639
|
+
* @param subredditName - The name of the subreddit to add the user as a wiki contributor. e.g. 'memes'
|
|
640
|
+
*/
|
|
641
|
+
addWikiContributor(username, subredditName) {
|
|
642
|
+
return User.createRelationship({
|
|
643
|
+
username,
|
|
644
|
+
subredditName,
|
|
645
|
+
type: 'wikicontributor',
|
|
646
|
+
});
|
|
647
|
+
}
|
|
648
|
+
/**
|
|
649
|
+
* Remove a user's wiki contributor status for a subreddit.
|
|
650
|
+
*
|
|
651
|
+
* @param username - The username of the user to remove wiki contributor status from. e.g. 'spez'
|
|
652
|
+
* @param subredditName - The name of the subreddit to remove the user's wiki contributor status from. e.g. 'memes'
|
|
653
|
+
*/
|
|
654
|
+
removeWikiContributor(username, subredditName) {
|
|
655
|
+
return User.removeRelationship({
|
|
656
|
+
username,
|
|
657
|
+
subredditName,
|
|
658
|
+
type: 'wikicontributor',
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Get a list of users who are banned from a subreddit.
|
|
663
|
+
*
|
|
664
|
+
* @param options - Options for the request
|
|
665
|
+
* @param options.subredditName - The name of the subreddit to get the banned users from. e.g. 'memes'
|
|
666
|
+
* @param options.username - Use this to see if a user is banned from the subreddit.
|
|
667
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
668
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
669
|
+
* @returns A Listing of User objects.
|
|
670
|
+
*/
|
|
671
|
+
getBannedUsers(options) {
|
|
672
|
+
return User.getSubredditUsersByType({
|
|
673
|
+
type: 'banned',
|
|
674
|
+
...options,
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
/**
|
|
678
|
+
* Ban a user from a subreddit.
|
|
679
|
+
*
|
|
680
|
+
* @param options - Options for the request
|
|
681
|
+
* @param options.username - The username of the user to ban. e.g. 'spez'
|
|
682
|
+
* @param options.subredditName - The name of the subreddit to ban the user from. e.g. 'memes'
|
|
683
|
+
* @param options.note - A mod note for the ban. (optional)
|
|
684
|
+
* @param options.duration - The number of days the user should be banned for. (optional)
|
|
685
|
+
* @param options.message - A message to send to the user when they are banned. (optional)
|
|
686
|
+
* @param options.context - The ID of the post or comment that caused the ban. (optional)
|
|
687
|
+
* @param options.reason - The reason for the ban. (optional)
|
|
688
|
+
*/
|
|
689
|
+
banUser(options) {
|
|
690
|
+
return User.createRelationship({
|
|
691
|
+
username: options.username,
|
|
692
|
+
subredditName: options.subredditName,
|
|
693
|
+
type: 'banned',
|
|
694
|
+
banReason: options.reason,
|
|
695
|
+
banMessage: options.message,
|
|
696
|
+
note: options.note,
|
|
697
|
+
duration: options.duration,
|
|
698
|
+
banContext: options.context,
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
/**
|
|
702
|
+
* Unban a user from a subreddit.
|
|
703
|
+
*
|
|
704
|
+
* @param username - The username of the user to unban. e.g. 'spez'
|
|
705
|
+
* @param subredditName - The name of the subreddit to unban the user from. e.g. 'memes'
|
|
706
|
+
*/
|
|
707
|
+
unbanUser(username, subredditName) {
|
|
708
|
+
return User.removeRelationship({
|
|
709
|
+
username,
|
|
710
|
+
subredditName,
|
|
711
|
+
type: 'banned',
|
|
712
|
+
});
|
|
713
|
+
}
|
|
714
|
+
/**
|
|
715
|
+
* Get a list of users who are banned from contributing to the wiki on a subreddit.
|
|
716
|
+
*
|
|
717
|
+
* @param options - Options for the request
|
|
718
|
+
* @param options.subredditName - The name of the subreddit to get the banned wiki contributors from. e.g. 'memes'
|
|
719
|
+
* @param options.username - Use this to see if a user is banned from contributing to the wiki on a subreddit.
|
|
720
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
721
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
722
|
+
* @returns A Listing of User objects.
|
|
723
|
+
*/
|
|
724
|
+
getBannedWikiContributors(options) {
|
|
725
|
+
return User.getSubredditUsersByType({
|
|
726
|
+
type: 'wikibanned',
|
|
727
|
+
...options,
|
|
728
|
+
});
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Ban a user from contributing to the wiki on a subreddit.
|
|
732
|
+
*
|
|
733
|
+
* @param options - Options for the request
|
|
734
|
+
* @param options.username - The username of the user to ban. e.g. 'spez'
|
|
735
|
+
* @param options.subredditName - The name of the subreddit to ban the user from contributing to the wiki on. e.g. 'memes'
|
|
736
|
+
* @param options.reason - The reason for the ban. (optional)
|
|
737
|
+
* @param options.duration - The number of days the user should be banned for. (optional)
|
|
738
|
+
* @param options.note - A mod note for the ban. (optional)
|
|
739
|
+
*/
|
|
740
|
+
banWikiContributor(options) {
|
|
741
|
+
return User.createRelationship({
|
|
742
|
+
...options,
|
|
743
|
+
type: 'wikibanned',
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
*
|
|
748
|
+
* @param username - The username of the user to unban. e.g. 'spez'
|
|
749
|
+
* @param subredditName - The name of the subreddit to unban the user from contributing to the wiki on. e.g. 'memes'
|
|
750
|
+
*/
|
|
751
|
+
unbanWikiContributor(username, subredditName) {
|
|
752
|
+
return User.removeRelationship({
|
|
753
|
+
username,
|
|
754
|
+
subredditName,
|
|
755
|
+
type: 'wikibanned',
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
/**
|
|
759
|
+
* Get a list of users who are moderators for a subreddit.
|
|
760
|
+
*
|
|
761
|
+
* @param options - Options for the request
|
|
762
|
+
* @param options.subredditName - The name of the subreddit to get the moderators from. e.g. 'memes'
|
|
763
|
+
* @param options.username - Use this to see if a user is a moderator of the subreddit.
|
|
764
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
765
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
766
|
+
* @returns A Listing of User objects.
|
|
767
|
+
*/
|
|
768
|
+
getModerators(options) {
|
|
769
|
+
return User.getSubredditUsersByType({
|
|
770
|
+
type: 'moderators',
|
|
771
|
+
...options,
|
|
772
|
+
});
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Invite a user to become a moderator of a subreddit.
|
|
776
|
+
*
|
|
777
|
+
* @param options - Options for the request
|
|
778
|
+
* @param options.username - The username of the user to invite. e.g. 'spez'
|
|
779
|
+
* @param options.subredditName - The name of the subreddit to invite the user to moderate. e.g. 'memes'
|
|
780
|
+
* @param options.permissions - The permissions to give the user. (optional) Defaults to 'all'.
|
|
781
|
+
*/
|
|
782
|
+
inviteModerator(options) {
|
|
783
|
+
return User.createRelationship({
|
|
784
|
+
type: 'moderator_invite',
|
|
785
|
+
subredditName: options.subredditName,
|
|
786
|
+
username: options.username,
|
|
787
|
+
permissions: options.permissions ?? [],
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
/**
|
|
791
|
+
* Revoke a moderator invite for a user to a subreddit.
|
|
792
|
+
*
|
|
793
|
+
* @param username - The username of the user to revoke the invite for. e.g. 'spez'
|
|
794
|
+
* @param subredditName - The name of the subreddit to revoke the invite for. e.g. 'memes'
|
|
795
|
+
*/
|
|
796
|
+
revokeModeratorInvite(username, subredditName) {
|
|
797
|
+
return User.removeRelationship({
|
|
798
|
+
username,
|
|
799
|
+
subredditName,
|
|
800
|
+
type: 'moderator_invite',
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Remove a user as a moderator of a subreddit.
|
|
805
|
+
*
|
|
806
|
+
* @param username - The username of the user to remove as a moderator. e.g. 'spez'
|
|
807
|
+
* @param subredditName - The name of the subreddit to remove the user as a moderator from. e.g. 'memes'
|
|
808
|
+
*/
|
|
809
|
+
removeModerator(username, subredditName) {
|
|
810
|
+
return User.removeRelationship({
|
|
811
|
+
type: 'moderator',
|
|
812
|
+
subredditName,
|
|
813
|
+
username,
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Update the permissions of a moderator of a subreddit.
|
|
818
|
+
*
|
|
819
|
+
* @param username - The username of the user to update the permissions for. e.g. 'spez'
|
|
820
|
+
* @param subredditName - The name of the subreddit. e.g. 'memes'
|
|
821
|
+
* @param permissions - The permissions to give the user. e.g ['posts', 'wiki']
|
|
822
|
+
*/
|
|
823
|
+
setModeratorPermissions(username, subredditName, permissions) {
|
|
824
|
+
return User.setModeratorPermissions(username, subredditName, permissions);
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Get a list of users who are muted in a subreddit.
|
|
828
|
+
*
|
|
829
|
+
* @param options - Options for the request
|
|
830
|
+
* @param options.subredditName - The name of the subreddit to get the muted users from. e.g. 'memes'
|
|
831
|
+
* @param options.username - Use this to see if a user is muted in the subreddit.
|
|
832
|
+
* @param options.limit - The maximum number of users to return. e.g. 1000
|
|
833
|
+
* @param options.pageSize - The number of users to return per request. e.g. 100
|
|
834
|
+
* @returns A listing of User objects.
|
|
835
|
+
*/
|
|
836
|
+
getMutedUsers(options) {
|
|
837
|
+
return User.getSubredditUsersByType({
|
|
838
|
+
type: 'muted',
|
|
839
|
+
...options,
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* Mute a user in a subreddit. Muting a user prevents them from sending modmail.
|
|
844
|
+
*
|
|
845
|
+
* @param options - Options for the request
|
|
846
|
+
* @param options.username - The username of the user to mute. e.g. 'spez'
|
|
847
|
+
* @param options.subredditName - The name of the subreddit to mute the user in. e.g. 'memes'
|
|
848
|
+
* @param options.note - A mod note on why the user was muted. (optional)
|
|
849
|
+
*/
|
|
850
|
+
muteUser(options) {
|
|
851
|
+
return User.createRelationship({
|
|
852
|
+
...options,
|
|
853
|
+
type: 'muted',
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Unmute a user in a subreddit. Unmuting a user allows them to send modmail.
|
|
858
|
+
*
|
|
859
|
+
* @param username - The username of the user to unmute. e.g. 'spez'
|
|
860
|
+
* @param subredditName - The name of the subreddit to unmute the user in. e.g. 'memes'
|
|
861
|
+
*/
|
|
862
|
+
unmuteUser(username, subredditName) {
|
|
863
|
+
return User.removeRelationship({
|
|
864
|
+
username,
|
|
865
|
+
subredditName,
|
|
866
|
+
type: 'muted',
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Get a list of mod notes related to a user in a subreddit.
|
|
871
|
+
*
|
|
872
|
+
* @param options - Options for the request
|
|
873
|
+
* @param options.subredditName - The name of the subreddit to get the mod notes from. e.g. 'memes'
|
|
874
|
+
* @param options.username - The username of the user to get the mod notes for. e.g. 'spez'
|
|
875
|
+
* @param options.filter - Filter the mod notes by type. e.g. 'NOTE', 'BAN', 'APPROVAL'
|
|
876
|
+
* @param options.limit - The maximum number of mod notes to return. e.g. 1000
|
|
877
|
+
* @param options.pageSize - The number of mod notes to return per request. e.g. 100
|
|
878
|
+
* @returns A listing of ModNote objects.
|
|
879
|
+
*/
|
|
880
|
+
getModNotes(options) {
|
|
881
|
+
return ModNote.get(options);
|
|
882
|
+
}
|
|
883
|
+
/**
|
|
884
|
+
* Delete a mod note.
|
|
885
|
+
*
|
|
886
|
+
* @param options - Options for the request
|
|
887
|
+
* @param options.subreddit - The name of the subreddit to delete the mod note from. e.g. 'memes'
|
|
888
|
+
* @param options.noteId - The ID of the mod note to delete (should have a ModNote_ prefix).
|
|
889
|
+
* @returns True if it was deleted successfully; false otherwise.
|
|
890
|
+
*/
|
|
891
|
+
deleteModNote(options) {
|
|
892
|
+
return ModNote.delete(options);
|
|
893
|
+
}
|
|
894
|
+
/**
|
|
895
|
+
* Add a mod note.
|
|
896
|
+
*
|
|
897
|
+
* @param options - Options for the request
|
|
898
|
+
* @param options.subreddit - The name of the subreddit to add the mod note to. e.g. 'memes'
|
|
899
|
+
* @param options.user - The username of the user to add the mod note to. e.g. 'spez'
|
|
900
|
+
* @param options.redditId - (optional) The ID of the comment or post to add the mod note to. e.g. 't3_1234'
|
|
901
|
+
* @param options.label - (optional) The label of the mod note. e.g. 'SPAM_WARNING'
|
|
902
|
+
* @param options.note - The text of the mod note.
|
|
903
|
+
* @returns A Promise that resolves if the mod note was successfully added.
|
|
904
|
+
*/
|
|
905
|
+
addModNote(options) {
|
|
906
|
+
const req = {
|
|
907
|
+
...options,
|
|
908
|
+
...(options.redditId ? { redditId: asTID(options.redditId) } : {}),
|
|
909
|
+
};
|
|
910
|
+
return ModNote.add(req);
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
* Add a mod note for why a post or comment was removed
|
|
914
|
+
*
|
|
915
|
+
* @param options.itemIds list of thing ids
|
|
916
|
+
* @param options.reasonId id of a Removal Reason - you can leave this as an empty string if you don't have one
|
|
917
|
+
* @param options.modNote the reason for removal (maximum 100 characters) (optional)
|
|
918
|
+
*/
|
|
919
|
+
addRemovalNote(options) {
|
|
920
|
+
return ModNote.addRemovalNote(options);
|
|
921
|
+
}
|
|
922
|
+
/**
|
|
923
|
+
* Sends a private message to a user.
|
|
924
|
+
*
|
|
925
|
+
* @param options - The options for sending the message.
|
|
926
|
+
* @returns A Promise that resolves if the private message was successfully sent.
|
|
927
|
+
*/
|
|
928
|
+
async sendPrivateMessage(options) {
|
|
929
|
+
return PrivateMessage.send(options);
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
* Sends a private message to a user on behalf of a subreddit.
|
|
933
|
+
*
|
|
934
|
+
* @param options - The options for sending the message as a subreddit.
|
|
935
|
+
* @returns A Promise that resolves if the private message was successfully sent.
|
|
936
|
+
*/
|
|
937
|
+
async sendPrivateMessageAsSubreddit(options) {
|
|
938
|
+
return PrivateMessage.sendAsSubreddit(options);
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Approve a post or comment.
|
|
942
|
+
*
|
|
943
|
+
* @param id - The id of the post (t3_) or comment (t1_) to approve.
|
|
944
|
+
* @example
|
|
945
|
+
* ```ts
|
|
946
|
+
* await reddit.approve('t3_123456');
|
|
947
|
+
* await reddit.approve('t1_123456');
|
|
948
|
+
* ```
|
|
949
|
+
*/
|
|
950
|
+
async approve(id) {
|
|
951
|
+
if (isT1ID(id)) {
|
|
952
|
+
return Comment.approve(id);
|
|
953
|
+
}
|
|
954
|
+
else if (isT3ID(id)) {
|
|
955
|
+
return Post.approve(id);
|
|
956
|
+
}
|
|
957
|
+
throw new Error('id must start with either t1_ or t3_');
|
|
958
|
+
}
|
|
959
|
+
/**
|
|
960
|
+
* Remove a post or comment.
|
|
961
|
+
*
|
|
962
|
+
* @param id - The id of the post (t3_) or comment (t1_) to remove.
|
|
963
|
+
* @param isSpam - Is the post or comment being removed because it's spam?
|
|
964
|
+
* @example
|
|
965
|
+
* ```ts
|
|
966
|
+
* await reddit.remove('t3_123456', false);
|
|
967
|
+
* await reddit.remove('t1_123456', true);
|
|
968
|
+
* ```
|
|
969
|
+
*/
|
|
970
|
+
async remove(id, isSpam) {
|
|
971
|
+
if (isT1ID(id)) {
|
|
972
|
+
return Comment.remove(id, isSpam);
|
|
973
|
+
}
|
|
974
|
+
else if (isT3ID(id)) {
|
|
975
|
+
return Post.remove(id, isSpam);
|
|
976
|
+
}
|
|
977
|
+
throw new Error('id must start with either t1_ or t3_');
|
|
978
|
+
}
|
|
979
|
+
/**
|
|
980
|
+
* Get the list of post flair templates for a subreddit.
|
|
981
|
+
*
|
|
982
|
+
* @param subredditName - The name of the subreddit to get the post flair templates for.
|
|
983
|
+
* @returns A Promise that resolves with an array of FlairTemplate objects.
|
|
984
|
+
*/
|
|
985
|
+
async getPostFlairTemplates(subredditName) {
|
|
986
|
+
return FlairTemplate.getPostFlairTemplates(subredditName);
|
|
987
|
+
}
|
|
988
|
+
/**
|
|
989
|
+
* Get the list of user flair templates for a subreddit.
|
|
990
|
+
*
|
|
991
|
+
* @param subredditName - The name of the subreddit to get the user flair templates for.
|
|
992
|
+
* @returns A Promise that resolves with an array of FlairTemplate objects.
|
|
993
|
+
*/
|
|
994
|
+
async getUserFlairTemplates(subredditName) {
|
|
995
|
+
return FlairTemplate.getUserFlairTemplates(subredditName);
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
* Create a post flair template for a subreddit.
|
|
999
|
+
*
|
|
1000
|
+
* @param options - Options for the request
|
|
1001
|
+
* @param options.subredditName - The name of the subreddit to create the flair template for.
|
|
1002
|
+
* @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
|
|
1003
|
+
* @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
|
|
1004
|
+
* @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
|
|
1005
|
+
* @param options.modOnly - Whether or not this flair template is only available to mods.
|
|
1006
|
+
* @param options.text - The text of the flair template.
|
|
1007
|
+
* @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
|
|
1008
|
+
* @param options.allowUserEdits - Whether or not users can edit the flair template when selecting a flair.
|
|
1009
|
+
* @returns The created FlairTemplate object.
|
|
1010
|
+
*/
|
|
1011
|
+
async createPostFlairTemplate(options) {
|
|
1012
|
+
return FlairTemplate.createPostFlairTemplate(options);
|
|
1013
|
+
}
|
|
1014
|
+
/**
|
|
1015
|
+
* Create a user flair template for a subreddit.
|
|
1016
|
+
*
|
|
1017
|
+
* @param options - Options for the request
|
|
1018
|
+
* @param options.subredditName - The name of the subreddit to create the flair template for.
|
|
1019
|
+
* @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
|
|
1020
|
+
* @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
|
|
1021
|
+
* @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
|
|
1022
|
+
* @param options.modOnly - Whether or not this flair template is only available to mods.
|
|
1023
|
+
* @param options.text - The text of the flair template.
|
|
1024
|
+
* @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
|
|
1025
|
+
* @param options.allowUserEdits - Whether or not users can edit the flair template when selecting a flair.
|
|
1026
|
+
* @returns The created FlairTemplate object.
|
|
1027
|
+
*/
|
|
1028
|
+
async createUserFlairTemplate(options) {
|
|
1029
|
+
return FlairTemplate.createUserFlairTemplate(options);
|
|
1030
|
+
}
|
|
1031
|
+
/**
|
|
1032
|
+
* Edit a flair template for a subreddit. This can be either a post or user flair template.
|
|
1033
|
+
* Note: If you leave any of the options fields as undefined, they will reset to their default values.
|
|
1034
|
+
*
|
|
1035
|
+
* @param options - Options for the request
|
|
1036
|
+
* @param options.id - The ID of the flair template to edit.
|
|
1037
|
+
* @param options.subredditName - The name of the subreddit to create the flair template for.
|
|
1038
|
+
* @param options.allowableContent - The content that is allowed to be used with this flair template. e.g. 'all' or 'text' or 'emoji'
|
|
1039
|
+
* @param options.backgroundColor - The background color of the flair template. e.g. '#ff0000' or 'transparent'
|
|
1040
|
+
* @param options.maxEmojis - The maximum number of emojis that can be used with this flair template.
|
|
1041
|
+
* @param options.modOnly - Is this flair template only available to mods?
|
|
1042
|
+
* @param options.text - The text of the flair template.
|
|
1043
|
+
* @param options.textColor - The text color of the flair template. Either 'dark' or 'light'.
|
|
1044
|
+
* @param options.allowUserEdits - Can users can edit the flair template when selecting a flair?
|
|
1045
|
+
* @returns The edited FlairTemplate object.
|
|
1046
|
+
*/
|
|
1047
|
+
async editFlairTemplate(options) {
|
|
1048
|
+
return FlairTemplate.editFlairTemplate(options);
|
|
1049
|
+
}
|
|
1050
|
+
/**
|
|
1051
|
+
* Delete a flair template from a subreddit.
|
|
1052
|
+
*
|
|
1053
|
+
* @param subredditName - The name of the subreddit to delete the flair template from.
|
|
1054
|
+
* @param flairTemplateId - The ID of the flair template to delete.
|
|
1055
|
+
*/
|
|
1056
|
+
async deleteFlairTemplate(subredditName, flairTemplateId) {
|
|
1057
|
+
return FlairTemplate.deleteFlairTemplate(subredditName, flairTemplateId);
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* Set the flair for a user in a subreddit.
|
|
1061
|
+
*
|
|
1062
|
+
* @param options - Options for the request
|
|
1063
|
+
* @param options.subredditName - The name of the subreddit to set the flair for.
|
|
1064
|
+
* @param options.username - The username of the user to set the flair for.
|
|
1065
|
+
* @param options.flairTemplateId - The ID of the flair template to use.
|
|
1066
|
+
* @param options.text - The text of the flair.
|
|
1067
|
+
* @param options.cssClass - The CSS class of the flair.
|
|
1068
|
+
* @param options.backgroundColor - The background color of the flair.
|
|
1069
|
+
* @param options.textColor - The text color of the flair.
|
|
1070
|
+
*/
|
|
1071
|
+
async setUserFlair(options) {
|
|
1072
|
+
return Flair.setUserFlair(options);
|
|
1073
|
+
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Set the flair of multiple users in the same subreddit with a single API call.
|
|
1076
|
+
* Can process up to 100 entries at once.
|
|
1077
|
+
*
|
|
1078
|
+
* @param subredditName - The name of the subreddit to edit flairs in.
|
|
1079
|
+
* @param {SetUserFlairBatchConfig[]} flairs - Array of user flair configuration objects. If both text and cssClass are empty for a given user the flair will be cleared.
|
|
1080
|
+
* @param flairs[].username - The username of the user to edit the flair for.
|
|
1081
|
+
* @param flairs[].text - The text of the flair.
|
|
1082
|
+
* @param flairs[].cssClass - The CSS class of the flair.
|
|
1083
|
+
* @returns {FlairCsvResult[]} - Array of statuses for each entry provided.
|
|
1084
|
+
*/
|
|
1085
|
+
async setUserFlairBatch(subredditName, flairs) {
|
|
1086
|
+
return Flair.setUserFlairBatch(subredditName, flairs);
|
|
1087
|
+
}
|
|
1088
|
+
/**
|
|
1089
|
+
* Remove the flair for a user in a subreddit.
|
|
1090
|
+
*
|
|
1091
|
+
* @param subredditName - The name of the subreddit to remove the flair from.
|
|
1092
|
+
* @param username - The username of the user to remove the flair from.
|
|
1093
|
+
*/
|
|
1094
|
+
async removeUserFlair(subredditName, username) {
|
|
1095
|
+
return Flair.removeUserFlair(subredditName, username);
|
|
1096
|
+
}
|
|
1097
|
+
/**
|
|
1098
|
+
* Set the flair for a post in a subreddit.
|
|
1099
|
+
*
|
|
1100
|
+
* @param options - Options for the request
|
|
1101
|
+
* @param options.subredditName - The name of the subreddit to set the flair for.
|
|
1102
|
+
* @param options.postId - The ID of the post to set the flair for.
|
|
1103
|
+
* @param options.flairTemplateId - The ID of the flair template to use.
|
|
1104
|
+
* @param options.text - The text of the flair.
|
|
1105
|
+
* @param options.cssClass - The CSS class of the flair.
|
|
1106
|
+
* @param options.backgroundColor - The background color of the flair.
|
|
1107
|
+
* @param options.textColor - The text color of the flair.
|
|
1108
|
+
*/
|
|
1109
|
+
async setPostFlair(options) {
|
|
1110
|
+
return Flair.setPostFlair(options);
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Remove the flair for a post in a subreddit.
|
|
1114
|
+
*
|
|
1115
|
+
* @param subredditName - The name of the subreddit to remove the flair from.
|
|
1116
|
+
* @param postId - The ID of the post to remove the flair from.
|
|
1117
|
+
*/
|
|
1118
|
+
async removePostFlair(subredditName, postId) {
|
|
1119
|
+
return Flair.removePostFlair(subredditName, asT3ID(postId));
|
|
1120
|
+
}
|
|
1121
|
+
/**
|
|
1122
|
+
* Get the widgets for a subreddit.
|
|
1123
|
+
*
|
|
1124
|
+
* @param subredditName - The name of the subreddit to get the widgets for.
|
|
1125
|
+
* @returns - An array of Widget objects.
|
|
1126
|
+
*/
|
|
1127
|
+
async getWidgets(subredditName) {
|
|
1128
|
+
return Widget.getWidgets(subredditName);
|
|
1129
|
+
}
|
|
1130
|
+
/**
|
|
1131
|
+
* Delete a widget from a subreddit.
|
|
1132
|
+
*
|
|
1133
|
+
* @param subredditName - The name of the subreddit to delete the widget from.
|
|
1134
|
+
* @param widgetId - The ID of the widget to delete.
|
|
1135
|
+
*/
|
|
1136
|
+
async deleteWidget(subredditName, widgetId) {
|
|
1137
|
+
return Widget.delete(subredditName, widgetId);
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Add a widget to a subreddit.
|
|
1141
|
+
*
|
|
1142
|
+
* @param widgetData - The data for the widget to add.
|
|
1143
|
+
* @returns - The added Widget object.
|
|
1144
|
+
*/
|
|
1145
|
+
async addWidget(widgetData) {
|
|
1146
|
+
return Widget.add(widgetData);
|
|
1147
|
+
}
|
|
1148
|
+
/**
|
|
1149
|
+
* Reorder the widgets for a subreddit.
|
|
1150
|
+
*
|
|
1151
|
+
* @param subredditName - The name of the subreddit to reorder the widgets for.
|
|
1152
|
+
* @param orderByIds - An array of widget IDs in the order that they should be displayed.
|
|
1153
|
+
*/
|
|
1154
|
+
async reorderWidgets(subredditName, orderByIds) {
|
|
1155
|
+
return Widget.reorder(subredditName, orderByIds);
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Get a wiki page from a subreddit.
|
|
1159
|
+
*
|
|
1160
|
+
* @param subredditName - The name of the subreddit to get the wiki page from.
|
|
1161
|
+
* @param page - The name of the wiki page to get.
|
|
1162
|
+
* @returns The requested WikiPage object.
|
|
1163
|
+
*/
|
|
1164
|
+
async getWikiPage(subredditName, page) {
|
|
1165
|
+
return WikiPage.getPage(subredditName, page);
|
|
1166
|
+
}
|
|
1167
|
+
/**
|
|
1168
|
+
* Get the wiki pages for a subreddit.
|
|
1169
|
+
*
|
|
1170
|
+
* @param subredditName - The name of the subreddit to get the wiki pages from.
|
|
1171
|
+
* @returns A list of the wiki page names for the subreddit.
|
|
1172
|
+
*/
|
|
1173
|
+
async getWikiPages(subredditName) {
|
|
1174
|
+
return WikiPage.getPages(subredditName);
|
|
1175
|
+
}
|
|
1176
|
+
/**
|
|
1177
|
+
* Create a new wiki page for a subreddit.
|
|
1178
|
+
*
|
|
1179
|
+
* @param options - Options for the request
|
|
1180
|
+
* @param options.subredditName - The name of the subreddit the wiki is in.
|
|
1181
|
+
* @param options.page - The name of the wiki page to create.
|
|
1182
|
+
* @param options.content - The Markdown content of the wiki page.
|
|
1183
|
+
* @param options.reason - The reason for creating the wiki page.
|
|
1184
|
+
* @returns - The created WikiPage object.
|
|
1185
|
+
*/
|
|
1186
|
+
async createWikiPage(options) {
|
|
1187
|
+
return WikiPage.createPage(options);
|
|
1188
|
+
}
|
|
1189
|
+
/**
|
|
1190
|
+
* Update a wiki page.
|
|
1191
|
+
*
|
|
1192
|
+
* @param options - Options for the request
|
|
1193
|
+
* @param options.subredditName - The name of the subreddit the wiki is in.
|
|
1194
|
+
* @param options.page - The name of the wiki page to update.
|
|
1195
|
+
* @param options.content - The Markdown content of the wiki page.
|
|
1196
|
+
* @param options.reason - The reason for updating the wiki page.
|
|
1197
|
+
* @returns The updated WikiPage object.
|
|
1198
|
+
*/
|
|
1199
|
+
async updateWikiPage(options) {
|
|
1200
|
+
return WikiPage.updatePage(options);
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Get the revisions for a wiki page.
|
|
1204
|
+
*
|
|
1205
|
+
* @param options - Options for the request
|
|
1206
|
+
* @param options.subredditName - The name of the subreddit the wiki is in.
|
|
1207
|
+
* @param options.page - The name of the wiki page to get the revisions for.
|
|
1208
|
+
* @param options.limit - The maximum number of revisions to return.
|
|
1209
|
+
* @param options.after - The ID of the revision to start after.
|
|
1210
|
+
* @returns A Listing of WikiPageRevision objects.
|
|
1211
|
+
*/
|
|
1212
|
+
getWikiPageRevisions(options) {
|
|
1213
|
+
return WikiPage.getPageRevisions(options);
|
|
1214
|
+
}
|
|
1215
|
+
/**
|
|
1216
|
+
* Revert a wiki page to a previous revision.
|
|
1217
|
+
*
|
|
1218
|
+
* @param subredditName - The name of the subreddit the wiki is in.
|
|
1219
|
+
* @param page - The name of the wiki page to revert.
|
|
1220
|
+
* @param revisionId - The ID of the revision to revert to.
|
|
1221
|
+
*/
|
|
1222
|
+
async revertWikiPage(subredditName, page, revisionId) {
|
|
1223
|
+
return WikiPage.revertPage(subredditName, page, revisionId);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Get the settings for a wiki page.
|
|
1227
|
+
*
|
|
1228
|
+
* @param subredditName - The name of the subreddit the wiki is in.
|
|
1229
|
+
* @param page - The name of the wiki page to get the settings for.
|
|
1230
|
+
* @returns A WikiPageSettings object.
|
|
1231
|
+
*/
|
|
1232
|
+
async getWikiPageSettings(subredditName, page) {
|
|
1233
|
+
return WikiPage.getPageSettings(subredditName, page);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* Update the settings for a wiki page.
|
|
1237
|
+
*
|
|
1238
|
+
* @param options - Options for the request
|
|
1239
|
+
* @param options.subredditName - The name of the subreddit the wiki is in.
|
|
1240
|
+
* @param options.page - The name of the wiki page to update the settings for.
|
|
1241
|
+
* @param options.listed - Whether the wiki page should be listed in the wiki index.
|
|
1242
|
+
* @param options.permLevel - The permission level required to edit the wiki page.
|
|
1243
|
+
* @returns A WikiPageSettings object.
|
|
1244
|
+
*/
|
|
1245
|
+
async updateWikiPageSettings(options) {
|
|
1246
|
+
return WikiPage.updatePageSettings(options);
|
|
1247
|
+
}
|
|
1248
|
+
/**
|
|
1249
|
+
* Add an editor to a wiki page.
|
|
1250
|
+
*
|
|
1251
|
+
* @param subredditName - The name of the subreddit the wiki is in.
|
|
1252
|
+
* @param page - The name of the wiki page to add the editor to.
|
|
1253
|
+
* @param username - The username of the user to add as an editor.
|
|
1254
|
+
*/
|
|
1255
|
+
async addEditorToWikiPage(subredditName, page, username) {
|
|
1256
|
+
return WikiPage.addEditor(subredditName, page, username);
|
|
1257
|
+
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Remove an editor from a wiki page.
|
|
1260
|
+
*
|
|
1261
|
+
* @param subredditName - The name of the subreddit the wiki is in.
|
|
1262
|
+
* @param page - The name of the wiki page to remove the editor from.
|
|
1263
|
+
* @param username - The username of the user to remove as an editor.
|
|
1264
|
+
*/
|
|
1265
|
+
async removeEditorFromWikiPage(subredditName, page, username) {
|
|
1266
|
+
return WikiPage.removeEditor(subredditName, page, username);
|
|
1267
|
+
}
|
|
1268
|
+
/**
|
|
1269
|
+
* Get private messages sent to the currently authenticated user.
|
|
1270
|
+
*
|
|
1271
|
+
* @param options - Options for the request
|
|
1272
|
+
* @param options.type - The type of messages to get.
|
|
1273
|
+
*/
|
|
1274
|
+
getMessages(options) {
|
|
1275
|
+
return PrivateMessage.getMessages(options);
|
|
1276
|
+
}
|
|
1277
|
+
/**
|
|
1278
|
+
* Mark all private messages as read.
|
|
1279
|
+
*/
|
|
1280
|
+
markAllMessagesAsRead() {
|
|
1281
|
+
return PrivateMessage.markAllAsRead();
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Report a Post or Comment
|
|
1285
|
+
*
|
|
1286
|
+
* The report is sent to the moderators of the subreddit for review.
|
|
1287
|
+
*
|
|
1288
|
+
* @param thing Post or Comment
|
|
1289
|
+
* @param options Options
|
|
1290
|
+
* @param options.reason Why the thing is reported
|
|
1291
|
+
*
|
|
1292
|
+
* @example
|
|
1293
|
+
* ```ts
|
|
1294
|
+
* await reddit.report(post, {
|
|
1295
|
+
* reason: 'This is spam!',
|
|
1296
|
+
* })
|
|
1297
|
+
* ```
|
|
1298
|
+
*/
|
|
1299
|
+
report(thing, options) {
|
|
1300
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
1301
|
+
return client.Report({
|
|
1302
|
+
reason: options.reason,
|
|
1303
|
+
thingId: thing.id,
|
|
1304
|
+
srName: thing.subredditName,
|
|
1305
|
+
usernames: thing.authorName,
|
|
1306
|
+
}, __classPrivateFieldGet(this, _RedditClient_instances, "a", _RedditClient_metadata_get));
|
|
1307
|
+
}
|
|
1308
|
+
getModQueue(options) {
|
|
1309
|
+
return Subreddit.aboutLocation({
|
|
1310
|
+
...options,
|
|
1311
|
+
location: AboutLocations.Modqueue,
|
|
1312
|
+
});
|
|
1313
|
+
}
|
|
1314
|
+
getReports(options) {
|
|
1315
|
+
return Subreddit.aboutLocation({
|
|
1316
|
+
...options,
|
|
1317
|
+
location: AboutLocations.Reports,
|
|
1318
|
+
});
|
|
1319
|
+
}
|
|
1320
|
+
getSpam(options) {
|
|
1321
|
+
return Subreddit.aboutLocation({
|
|
1322
|
+
...options,
|
|
1323
|
+
location: AboutLocations.Spam,
|
|
1324
|
+
});
|
|
1325
|
+
}
|
|
1326
|
+
getUnmoderated(options) {
|
|
1327
|
+
return Subreddit.aboutLocation({
|
|
1328
|
+
...options,
|
|
1329
|
+
location: AboutLocations.Unmoderated,
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
getEdited(options) {
|
|
1333
|
+
return Subreddit.aboutLocation({
|
|
1334
|
+
...options,
|
|
1335
|
+
location: AboutLocations.Edited,
|
|
1336
|
+
});
|
|
1337
|
+
}
|
|
1338
|
+
/**
|
|
1339
|
+
* Gets a {@link Vault} for the specified address.
|
|
1340
|
+
*
|
|
1341
|
+
* @param {string} address - The address (starting with 0x) of the Vault.
|
|
1342
|
+
* @example
|
|
1343
|
+
* ```ts
|
|
1344
|
+
* const vault = await reddit.getVaultByAddress('0x205ee28744456bDBf180A0Fa7De51e0F116d54Ed');
|
|
1345
|
+
* ```
|
|
1346
|
+
*/
|
|
1347
|
+
getVaultByAddress(address) {
|
|
1348
|
+
return getVaultByAddress(address);
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Gets a {@link Vault} for the specified user.
|
|
1352
|
+
*
|
|
1353
|
+
* @param {string} userId - The ID (starting with t2_) of the Vault owner.
|
|
1354
|
+
* @example
|
|
1355
|
+
* ```ts
|
|
1356
|
+
* const vault = await reddit.getVaultByUserId('t2_1w72');
|
|
1357
|
+
* ```
|
|
1358
|
+
*/
|
|
1359
|
+
getVaultByUserId(userId) {
|
|
1360
|
+
return getVaultByUserId(asTID(userId));
|
|
1361
|
+
}
|
|
1362
|
+
/**
|
|
1363
|
+
* Returns a leaderboard for a given subreddit ID.
|
|
1364
|
+
*
|
|
1365
|
+
* @param subredditId ID of the subreddit for which the leaderboard is being queried.
|
|
1366
|
+
*
|
|
1367
|
+
* @returns {SubredditLeaderboard} Leaderboard for the given subreddit.
|
|
1368
|
+
*/
|
|
1369
|
+
getSubredditLeaderboard(subredditId) {
|
|
1370
|
+
return getSubredditLeaderboard(subredditId);
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Returns the styles for a given subreddit ID.
|
|
1374
|
+
*
|
|
1375
|
+
* @param subredditId ID of the subreddit from which to retrieve the styles.
|
|
1376
|
+
*
|
|
1377
|
+
* @returns {SubredditStyles} Styles for the given subreddit.
|
|
1378
|
+
*/
|
|
1379
|
+
getSubredditStyles(subredditId) {
|
|
1380
|
+
return getSubredditStyles(subredditId);
|
|
1381
|
+
}
|
|
1382
|
+
/**
|
|
1383
|
+
* Subscribes to the subreddit in which the app is installed. No-op if the user is already subscribed.
|
|
1384
|
+
* This method will execute as the app account by default.
|
|
1385
|
+
* To subscribe on behalf of a user, please contact Reddit.
|
|
1386
|
+
*/
|
|
1387
|
+
async subscribeToCurrentSubreddit() {
|
|
1388
|
+
const currentSubreddit = await this.getCurrentSubreddit();
|
|
1389
|
+
const client = getRedditApiPlugins().Subreddits;
|
|
1390
|
+
await client.Subscribe({
|
|
1391
|
+
action: 'sub',
|
|
1392
|
+
actionSource: '',
|
|
1393
|
+
srName: currentSubreddit.name,
|
|
1394
|
+
sr: '',
|
|
1395
|
+
skipInitialDefaults: true,
|
|
1396
|
+
}, __classPrivateFieldGet(this, _RedditClient_instances, "a", _RedditClient_metadata_get));
|
|
1397
|
+
}
|
|
1398
|
+
/**
|
|
1399
|
+
* Unsubscribes from the subreddit in which the app is installed. No-op if the user isn't subscribed.
|
|
1400
|
+
* This method will execute as the app account by default.
|
|
1401
|
+
* To unsubscribe on behalf of a user, please contact Reddit.
|
|
1402
|
+
*/
|
|
1403
|
+
async unsubscribeFromCurrentSubreddit() {
|
|
1404
|
+
const currentSubreddit = await this.getCurrentSubreddit();
|
|
1405
|
+
const client = getRedditApiPlugins().Subreddits;
|
|
1406
|
+
await client.Subscribe({
|
|
1407
|
+
action: 'unsub',
|
|
1408
|
+
actionSource: '',
|
|
1409
|
+
srName: currentSubreddit.name,
|
|
1410
|
+
sr: '',
|
|
1411
|
+
skipInitialDefaults: false,
|
|
1412
|
+
}, __classPrivateFieldGet(this, _RedditClient_instances, "a", _RedditClient_metadata_get));
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
_RedditClient_modMailService = new WeakMap(), _RedditClient_currentUser = new WeakMap(), _RedditClient_currentUsername = new WeakMap(), _RedditClient_instances = new WeakSet(), _RedditClient_metadata_get = function _RedditClient_metadata_get() {
|
|
1416
|
+
return getContext().debug.metadata;
|
|
1417
|
+
};
|