Class: RedditUser

RedditUser

A class representing a reddit user


new RedditUser()

Example
// Get a user with the given username
r.getUser('spez')

Extends

Methods


giveGold(months)

Gives reddit gold to a user

Parameters:
Name Type Description
months number

The number of months of gold to give. This must be a number between 1 and 36.

Returns:

A Promise that fulfills when the request is complete

Type
Promise
Example
r.getUser('not_an_aardvark').giveGold(12)

assignFlair(options)

Assigns flair to this user on a given subreddit (as a moderator).

Parameters:
Name Type Description
options object
Properties
Name Type Argument Default Description
subredditName string

The subreddit that flair should be assigned on

text string <optional>
''

The text that the user's flair should have

cssClass string <optional>
''

The CSS class that the user's flair should have

Returns:

A Promise that fulfills with the current user after the request is complete

Type
Promise
Example
r.getUser('not_an_aardvark').assignFlair({subredditName: 'snoowrap', text: "Isn't an aardvark"})

friend(options)

Adds this user as a friend, or modifies their friend note.

Note: reddit.com only permits "notes" to be added on friends if the authenticated account has a subscription to reddit gold.

Parameters:
Name Type Description
options object
Properties
Name Type Argument Description
note string <optional>

An optional note to add on the user (300 characters max)

Returns:

A Promise that fulfills when this request is complete

Type
Promise
Example
r.getUser('actually_an_aardvark').friend({note: 'Is an aardvark'})

unfriend()

Removes this user from the requester's friend list.

Returns:

A Promise that fulfills with this user when the request is complete

Type
Promise
Example
r.getUser('actually_an_aardvark').unfriend()

getFriendInformation()

Gets information on this user related to their presence on the friend list.

Returns:

A Promise that fulfills with an object containing friend information

Type
Promise
Example
r.getUser('not_an_aardvark').getFriendInformation().then(console.log)
// => { date: 1460318190, note: 'Is an aardvark', name: 'actually_an_aardvark', id: 't2_q3519' }

getTrophies()

Gets a list of this user's trophies.

Returns:

A TrophyList containing this user's trophies

Type
Promise
Example
r.getUser('not_an_aardvark').getTrophies().then(console.log)
// => TrophyList { trophies: [
//  Trophy { ... },
//  Trophy { ... },
//  ...
// ] }

getOverview( [options])

Gets a Listing of the content this user has submitted.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions and Comments

Type
Promise
Example
r.getUser('spez').getOverview().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getSubmissions( [options])

Gets a Listing of this user's submissions.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions

Type
Promise
Example
r.getUser('spez').getSubmissions().then(console.log)
// => Listing [
//  Submission { ... },
//  Submission { ... },
//  Submission { ... },
//  ...
// ]

getComments( [options])

Gets a Listing of this user's comments.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Comments

Type
Promise
Example
r.getUser('spez').getComments().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Comment { ... },
//  ...
// ]

getUpvotedContent( [options])

Gets a Listing of the content that this user has upvoted.

Note: This can only be used to view one's own upvoted content, unless the user in question has chosen to make this information public in their preferences.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions and Comments

Type
Promise
Example
r.getMe().getUpvotedContent().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getDownvotedContent( [options])

Gets a Listing of the content that this user has downvoted.

Note: This can only be used to view one's own downvoted content, unless the user in question has chosen to make this information public in their preferences.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions and Comments

Type
Promise
Example
r.getMe().getDownvotedContent().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getHiddenContent( [options])

Gets a Listing of the submissions that this user has hidden.

Note: This can only be used to view one's own set of hidden posts, as reddit will return a 403 error when attempting to view another users' hidden posts.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions

Type
Promise
Example
r.getMe().getHiddenContent().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getSavedContent( [options])

Gets a Listing of the content that this user has saved.

Note: This can only be used to view one's own set of saved content, as reddit will return a 403 error when attempting to view other users' saved content.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions and Comments.

Type
Promise
Example
r.getMe().getSavedContent().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getGildedContent( [options])

Gets a Listing of this user's content which has been gilded.

Parameters:
Name Type Argument Description
options object <optional>

Options for the resulting Listing

Returns:

A Listing containing Submissions and Comments

Type
Promise
Example
r.getMe().getGildedContent().then(console.log)
// => Listing [
//  Comment { ... },
//  Comment { ... },
//  Submission { ... },
//  ...
// ]

getMultireddit(name)

Gets a multireddit belonging to this user.

Parameters:
Name Type Description
name string

The name of the multireddit

Returns:

An unfetched MultiReddit object

Type
MultiReddit
Example
r.getUser('multi-mod').getMultireddit('coding_languages')
// => MultiReddit {
//  name: 'coding_languages',
//  curator: RedditUser { name: 'multi-mod' },
//  path: '/user/multi-mod/m/coding_languages'
// }

getMultireddits()

Gets an Array of all of this user's MultiReddits.

Returns:

A Promise that fulfills with an Array containing MultiReddits.

Type
Promise
Example
r.getUser('multi-mod').getMultireddits().then(console.log)

// => [
  MultiReddit { ... },
  MultiReddit { ... },
  MultiReddit { ... },
  ...
]

remove(options)

Removes this Comment, Submission or PrivateMessage from public listings.

This requires the authenticated user to be a moderator of the subreddit with the posts permission.

Parameters:
Name Type Description
options object
Properties
Name Type Argument Default Description
spam boolean <optional>
false

Determines whether this should be marked as spam

Inherited From:
Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').remove({spam: true})

approve()

Approves this Comment, Submission, or PrivateMessage, re-adding it to public listings if it had been removed

Inherited From:
Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').approve()

report( [options])

Reports this content anonymously to subreddit moderators (for Comments and Submissions) or to the reddit admins (for PrivateMessages)

Parameters:
Name Type Argument Description
options object <optional>
Properties
Name Type Argument Description
reason string <optional>

The reason for the report

Inherited From:
Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').report({reason: 'Breaking the subreddit rules'})

ignoreReports()

Ignores reports on this Comment, Submission, or PrivateMessage

Inherited From:
Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').ignoreReports()

unignoreReports()

Unignores reports on this Comment, Submission, or PrivateMessages

Inherited From:
Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').unignoreReports()

reply(text)

Submits a new reply to this object. (This takes the form of a new Comment if this object is a Submission/Comment, or a new PrivateMessage if this object is a PrivateMessage.)

Parameters:
Name Type Description
text string

The content of the reply, in raw markdown text

Inherited From:
Returns:

A Promise that fulfills with the newly-created reply

Type
Promise
Example
r.getSubmission('4e60m3').reply('This was an interesting post. Thanks.');

blockAuthor()

Blocks the author of this content.

Note: In order for this function to have an effect, this item must be in the authenticated account's inbox or modmail somewhere. The reddit API gives no outward indication of whether this condition is satisfied, so the returned Promise will fulfill even if this is not the case.

Inherited From:
Returns:

A Promise that fulfills with this message after the request is complete

Type
Promise
Example
r.getInbox({limit: 1}).then(messages =>
  messages[0].blockAuthor();
);

fetch()

Fetches this content from reddit.

This will not mutate the original content object; all Promise properties will remain as Promises after the content has been fetched. However, the information on this object will be cached, so it may become out-of-date with the content on reddit. To clear the cache and fetch this object from reddit again, use refresh().

If snoowrap is running in an environment that supports ES2015 Proxies (e.g. Chrome 49+), then fetch() will get automatically called when an unknown property is accessed on an unfetched content object.

Inherited From:
Returns:

A version of this object with all of its fetched properties from reddit. This will not mutate the object. Once an object has been fetched once, its properties will be cached, so they might end up out-of-date if this function is called again. To refresh an object, use refresh().

Type
Promise
Example
r.getUser('not_an_aardvark').fetch().then(userInfo => {
  console.log(userInfo.name); // 'not_an_aardvark'
  console.log(userInfo.created_utc); // 1419104352
});

r.getComment('d1xchqn').fetch().then(comment => comment.body).then(console.log)
// => 'This is a little too interesting for my liking'

// In environments that support ES2015 Proxies, the above line is equivalent to:
r.getComment('d1xchqn').body.then(console.log);
// => 'This is a little too interesting for my liking'

refresh()

Refreshes this content.

Inherited From:
Returns:

A newly-fetched version of this content

Type
Promise
Example
var someComment = r.getComment('cmfkyus');
var initialCommentBody = some_comment.fetch().then(comment => comment.body);

setTimeout(() => {
  someComment.refresh().then(refreshedComment => {
    if (initialCommentBody.value() !== refreshedComment.body) {
      console.log('This comment has changed since 10 seconds ago.');
    }
  });
}, 10000);

toJSON()

Returns a stringifyable version of this object.

It is usually not necessary to call this method directly; simply running JSON.stringify(some_object) will strip the private properties anyway.

Inherited From:
Returns:

A version of this object with all the private properties stripped

Type
object
Example
var user = r.getUser('not_an_aardvark');
JSON.stringify(user) // => '{"name":"not_an_aardvark"}'