browser
Webbrowser abstraction for communicating with discourse
License: MIT
- browser
- ~trustLevels
- ~postActions
- ~setCore() ⇒
browser
- ~setPlugins() ⇒
browser
- ~prepare(events, callback)
- ~stop()
- ~start()
- ~pauseQueues(duration)
- ~throttleQueues(err, resp, waitTime)
- ~queueWorker(task, callback)
- ~getData(url, callback)
- ~postData(url, data, callback)
- ~createPost(topicId, [replyTo], content, callback)
- ~createPrivateMessage(to, title, content, callback)
- ~editPost(postId, content, [editReason], callback)
- ~readPosts(topicId, postIds, callback)
- ~getPost(postId, callback)
- ~getPosts(topicId, eachPost, complete)
- ~getLastPosts(topicId, eachPost, complete)
- ~getTopics(eachTopic, complete)
- ~postAction(action, postId, message, callback)
- ~getTopic(topicId, callback)
- ~getUser(username, callback)
- ~getCSRF(delay, queue, callback)
- ~doLogin(delay, queue, callback)
- ~login(callback)
- ~messageBus(channels, clientId, callback)
- ~getNotifications(callback)
- ~setPostUrl(post) ⇒
external.module_posts.CleanedPost
- ~setTrustLevel(post) ⇒
external.module_posts.CleanedPost
- ~cleanPostRaw(post) ⇒
external.module_posts.CleanedPost
- ~cleanPost(post) ⇒
external.posts.CleanedPost
- ~requestComplete
- ~postedCallback
- ~topicCallback
- ~completedCallback
- ~loginCallback
- ~messageBusCallback
- ~notificationsCallback
- ~eachTopicCallback
- ~eachPostCallback
browser~trustLevels
SockBot Virtual Trust Levels
Kind: inner constant of browser
Read only: true
Properties
Name | Default | Description |
---|---|---|
owner | 9 |
Bot Owner Trust Level |
admin | 8 |
Forum Admin Trust Level |
moderator | 7 |
Forum Moderator Trust Level |
staff | 6 |
Forum Staff Trust Level |
tl4 | 4 |
Discourst trust_level 4 Trust Level |
tl3 | 3 |
Discourst trust_level 3 Trust Level |
tl2 | 2 |
Discourst trust_level 2 Trust Level |
tl1 | 1 |
Discourst trust_level 1 Trust Level |
tl0 | 0 |
Discourst trust_level 0 Trust Level |
ignored | 0 |
Ignored User Trust Level |
browser~postActions
Discourse Post Actions
Kind: inner constant of browser
Read only: true
Properties
Name | Default |
---|---|
bookmark | 1 |
like | 2 |
off_topic | 3 |
inappropriate | 4 |
vote | 5 |
notify_user | 6 |
notify_moderators | 7 |
spam | 8 |
browser~setCore() ⇒ browser
Set module to core mode instance
Only available on core mode instance
Sets the currently active instance to the core mode instance which has no request delay
Kind: inner method of browser
Returns: browser
- Core browser instance
browser~setPlugins() ⇒ browser
Set module to core mode instance
Only available on core mode instance
Sets the currently active instance to the plugin mode instance which has a 5 second delay between requests
Kind: inner method of browser
Returns: browser
- Plugin browser instance
browser~prepare(events, callback)
Prepare the browser module prior to bot start
Kind: inner method of browser
Param | Type | Description |
---|---|---|
events | EventEmitter |
Central Events channel |
callback | function |
Completion callback |
browser~stop()
Stop the browser module
Kill the core mode and plugin mode request queues, preventing any further communication with discourse until restart
Kind: inner method of browser
browser~start()
Start the browser module
Set the request User-Agent based on configuration, set post signature, create core and plugin request queues
Kind: inner method of browser
browser~pauseQueues(duration)
Pause all discourse communication for a given period of time
Kind: inner method of browser
Param | Type | Description |
---|---|---|
duration | number |
length of time to pause in milliseconds |
browser~throttleQueues(err, resp, waitTime)
Calculate and apply throttling to the queues based on current discourse performance
Kind: inner method of browser
Param | Type | Description |
---|---|---|
err | Error |
Error encountered in request |
resp | request.Response |
response object |
waitTime | number |
Miliseconds elapsed between start and end of request |
browser~queueWorker(task, callback)
Process browser tasks with rate limiting
Kind: inner method of browser
Param | Type | Default | Description |
---|---|---|---|
task | object |
Task configuration | |
[task.method] | string |
"GET" |
HTTP method to request |
task.url | string |
Site relative URL to request | |
[task.form] | object |
HTTP form to use in HTTP request | |
[task.callback] | browser~requestComplete |
Callback toprovide request results to | |
[task.delay] | Number |
0 |
Seconds to delay callback after request for additional rate limiting |
callback | function |
Queue task complete callback |
browser~getData(url, callback)
Get data from a URL
Kind: inner method of browser
Param | Type | Description |
---|---|---|
url | string |
URL to issue GET request to |
callback | requestComplete |
Completion callback |
browser~postData(url, data, callback)
Post data to a URL
Kind: inner method of browser
Param | Type | Description |
---|---|---|
url | string |
URL to issue POST request to |
data | object |
Data to POST |
callback | requestComplete |
Completion callback |
browser~createPost(topicId, [replyTo], content, callback)
Post content to an existing topic
Kind: inner method of browser
Param | Type | Description |
---|---|---|
topicId | number |
Topic to post to |
[replyTo] | number |
Post Number in topic that this post is in reply to |
content | string |
Post Contents to post |
callback | postedCallback |
Completion callback |
browser~createPrivateMessage(to, title, content, callback)
Create a new private message.
Kind: inner method of browser
Param | Type | Description |
---|---|---|
to | string | Array.<string> |
Username or names to create PM to |
title | string |
Title of the Private Message |
content | string |
Private Message contents |
callback | postedCallback |
Completion callback |
browser~editPost(postId, content, [editReason], callback)
Edit an existing post.
Kind: inner method of browser
Param | Type | Description |
---|---|---|
postId | number |
Id number of the post to edit |
content | string |
New post content |
[editReason] | string |
Optional Edit Reason that no one ever uses |
callback | postedCallback |
Completion callback |
browser~readPosts(topicId, postIds, callback)
Read post
Kind: inner method of browser
Param | Type | Description |
---|---|---|
topicId | number |
Id of topic to read |
postIds | Array.<number> |
Ids of posts to read |
callback | postedCallback |
Completion callback |
browser~getPost(postId, callback)
Get post details
Kind: inner method of browser
Param | Type | Description |
---|---|---|
postId | number |
Id of post to retrieve |
callback | postedCallback |
Completion callback |
browser~getPosts(topicId, eachPost, complete)
Get all posts from a topic
Kind: inner method of browser
Param | Type | Description |
---|---|---|
topicId | number |
Topic to get posts from |
eachPost | eachPostCallback |
Callback to process individual posts |
complete | completionCallback |
Completion callback |
browser~getLastPosts(topicId, eachPost, complete)
Get latest posts from a topic
Kind: inner method of browser
Param | Type | Description |
---|---|---|
topicId | number |
Topic to get posts from |
eachPost | eachPostCallback |
Callback to process individual posts |
complete | completionCallback |
Completion callback |
browser~getTopics(eachTopic, complete)
Get all topics visible from /latest
Kind: inner method of browser
Param | Type | Description |
---|---|---|
eachTopic | eachTopicCallback |
Callback to process individual topics |
complete | completionCallback |
Completion callback |
browser~postAction(action, postId, message, callback)
Perform a post action
Kind: inner method of browser
Param | Type | Description |
---|---|---|
action | postActions |
Action to perform |
postId | number |
Id of post to act on |
message | string |
Message to leave as part of post action |
callback | completionCallback |
Completion callback |
browser~getTopic(topicId, callback)
Get topic details
Kind: inner method of browser
Param | Type | Description |
---|---|---|
topicId | number |
Id of topic to retrieve |
callback | topicCallback |
Completion callback |
browser~getUser(username, callback)
Get username details
Kind: inner method of browser
Param | Type | Description |
---|---|---|
username | number |
Username to get details of |
callback | topicCallback |
Completion callback |
browser~getCSRF(delay, queue, callback)
get a CSRF token from discourse
Kind: inner method of browser
Param | Type | Description |
---|---|---|
delay | number |
Delay completion by this many ms |
queue | async.queue |
Task Queue |
callback | completedCallback |
Completion callback |
browser~doLogin(delay, queue, callback)
Perform a login to discourse
Kind: inner method of browser
Param | Type | Description |
---|---|---|
delay | number |
Delay completion by this many ms |
queue | async.queue |
Task Queue |
callback | loginCallback |
Completion callback |
browser~login(callback)
Login to discourse
Kind: inner method of browser
Param | Type | Description |
---|---|---|
callback | loginCallback |
Completion callback |
browser~messageBus(channels, clientId, callback)
poll message-bus for messages
Kind: inner method of browser
Param | Type | Description |
---|---|---|
channels | Object.<string, number> |
Channels of interest |
clientId | string |
Id of the client for message-bus |
callback | messageBusCallback |
Completion callback |
browser~getNotifications(callback)
Poll for notifications
Kind: inner method of browser
Param | Type | Description |
---|---|---|
callback | notificationsCallback |
Completion callback |
browser~setPostUrl(post) ⇒ external.module_posts.CleanedPost
construct direct post link and direct in reply to link
Kind: inner method of browser
Returns: external.module_posts.CleanedPost
- input post with urls set
See
Param | Type | Description |
---|---|---|
post | external.module_posts.Post |
Post to generate links for |
post.topic_id | number |
Topic Id that the input post belongs to |
post.topic_slug | string |
URL slug of the topic |
post.post_number | number |
Ordinal of the input post in topic. |
post.reply_to_post_number | number |
The post_number the input post is a reply to |
browser~setTrustLevel(post) ⇒ external.module_posts.CleanedPost
Normalize discourse trust level to SockBot Virtual Trust Level
Kind: inner method of browser
Returns: external.module_posts.CleanedPost
- input post with normalized trust_level
See
Param | Type | Description |
---|---|---|
post | external.module_posts.Post |
Post to normalize trust levels on |
post.username | string |
Username of the post owner |
post.trust_level | Number |
Trust level of the post owner |
post.moderator | boolean |
Flags whether post owner has moderator powers |
post.admin | boolean |
Flags whether post owner has admin powers |
post.staff | boolean |
Flags whether post owner has staff powers |
browser~cleanPostRaw(post) ⇒ external.module_posts.CleanedPost
Clean post raw
Provided and commented by flabdablet
Kind: inner method of browser
Returns: external.module_posts.CleanedPost
- input post with cleaned raw
See: CleanedPost
Param | Type | Description |
---|---|---|
post | external.module_posts.Post |
Post to clean |
post.raw | string |
Raw text of the post to clean |
browser~cleanPost(post) ⇒ external.posts.CleanedPost
Clean discourse post for processing
Kind: inner method of browser
Returns: external.posts.CleanedPost
- Cleaned Post
See
Param | Type | Description |
---|---|---|
post | external.posts.Post |
Input Post |
browser~requestComplete
Browser Request Callback
Kind: inner typedef of browser
Param | Type | Default | Description |
---|---|---|---|
[err] | Exception |
|
Error encountered processing request |
body | Object |
JSON parsed response body. If invalid JSON will be undefined |
browser~postedCallback
Post Request Callback
Kind: inner typedef of browser
See: CleanedPost
Param | Type | Default | Description |
---|---|---|---|
[err] | Exception |
|
Error encountered processing request |
post | external.posts.CleanedPost |
Cleaned post |
browser~topicCallback
Topic Request Callback
Kind: inner typedef of browser
See: Topic
Param | Type | Default | Description |
---|---|---|---|
[err] | Exception |
|
Error encountered processing request |
topic | external.topics.Topic |
RetrievedTopic |
browser~completedCallback
Completion Callback
Kind: inner typedef of browser
Param | Type | Default | Description |
---|---|---|---|
[err] | Exception |
|
Error encountered |
browser~loginCallback
Login Completion Callback
Kind: inner typedef of browser
Param | Type | Default | Description |
---|---|---|---|
[err] | Exception |
|
Error encountered processing request |
user | extermal.users.User |
Logged in User information |
browser~messageBusCallback
MessageBus Completion Callback
Kind: inner typedef of browser
Param | Type | Default | Description |
---|---|---|---|
[err] | Excption |
|
Error encountered processing request |
messages | Array.<external.messageBus.message> |
Messages found. |
browser~notificationsCallback
Notifications Completion Callback
Kind: inner typedef of browser
Param | Type | Default | Description |
---|---|---|---|
[err] | Excption |
|
Error encountered processing request |
notifications | external.notifications.notifications |
Notifications found. |
browser~eachTopicCallback
Each Topic Callback
Kind: inner typedef of browser
Param | Type | Description |
---|---|---|
topic | external.topics.Topic |
Topic to process |
callback | completedCallback |
Completion callback |
browser~eachPostCallback
Each Post Callback
Kind: inner typedef of browser
Param | Type | Description |
---|---|---|
post | external.posts.CleanedPost |
Post to process |
callback | completedCallback |
Completion callback |