discourse
Used for communicating to discourse and the web.
Author: Accalia
License: MIT
- discourse
- static
- .uuid() ⇒
string
- .sleep(until) ⇒
number
- .version() ⇒
Version
- .log(message)
- .warn(message)
- .error(message)
- .saveFile(url, filename, callback)
- .login(callback)
- .reply(post, raw, callback)
- .createPrivateMessage(to, title, raw, callback)
- .editPost(postId, raw, [editReason], callback)
- .deletePost(postId, callback)
- .postAction(action, postId, [message], callback)
- .deletePostAction(action, postId, [message], callback)
- .readPosts(topicId, posts, callback)
- .getPost(postId, callback)
- .getTopic(topicId, callback)
- .getLastPosts(topicId, eachPost, callback)
- .getAllPosts(topicId, eachChunk, callback)
- .getAllTopics(eachChunk, callback)
- .getMessageBus(channels, callback)
- .getNotifications(callback)
- .getUserData(username, callback)
- .uuid() ⇒
- inner
- ~dGet(url, callback, [delayAfter])
- ~dPost(url, form, callback, [delayAfter])
- ~dPut(url, form, callback, [delayAfter])
- ~dDelete(url, form, callback, [delayAfter])
- ~addTimestamp(message) ⇒
string
- ~cleanPost(post) ⇒
CleanedPost
- ~schedule(task, [delayGroup])
- [~createPost(topic, [replyTo], raw, callback, [nomute])](#module_discourse..createPost)
discourse.uuid() ⇒ string
Generate a type 4 UUID.
I don't understand how this does what it does, but it works. It's a lot slower than using node-uuid but i only need one of these so its good enough Source: http://jsperf.com/node-uuid-performance/19
Kind: static method of discourse
Returns: string
- A type 4 UUID
discourse.sleep(until) ⇒ number
Set the bot to muted status until a time or query sleep status.
Most actions that would create a post will fail with error 'Muted' if bot is asleep
Kind: static method of discourse
Returns: number
- current timestamp the bot is set to sleep until
Param | Type | Description |
---|---|---|
until | number |
Unix Timestamp representing time for the bot to unmute |
discourse.version() ⇒ Version
Get the current version information
Kind: static method of discourse
Returns: Version
- Active Version module
discourse.log(message)
Log a message to the console
Kind: static method of discourse
Param | Type | Description |
---|---|---|
message | * |
Message to log |
discourse.warn(message)
Log a warning to the console
Kind: static method of discourse
Param | Type | Description |
---|---|---|
message | * |
Warning to log |
discourse.error(message)
Log an error to the console
Kind: static method of discourse
Param | Type | Description |
---|---|---|
message | * |
Error to log |
discourse.saveFile(url, filename, callback)
Issue a GET request and save result to filesystem
Kind: static method of discourse
Param | Type | Description |
---|---|---|
url | string |
Url to fetch |
filename | string |
Filename to save to |
callback | Completion callback |
discourse.login(callback)
Log into Discourse
Uses username
and password
configuration settings to login to discourse
Kind: static method of discourse
Param | Type | Description |
---|---|---|
callback | request |
Completion callback |
discourse.reply(post, raw, callback)
Reply to a post.
Kind: static method of discourse
Param | Type | Description |
---|---|---|
post | Post |
Post object to reply to |
raw | string |
Raw post data |
callback | request |
Completion callback |
discourse.createPrivateMessage(to, title, raw, callback)
Create a new private message.
Kind: static method of discourse
Param | Type | Description |
---|---|---|
to | string | Array.<string> |
Username or names to create PM to |
title | string |
Title of the Private Message |
raw | string |
Raw post data |
callback | request |
Completion callback |
discourse.editPost(postId, raw, [editReason], callback)
Edit an existing post.
Kind: static method of discourse
Param | Type | Description |
---|---|---|
postId | number |
Id number of the post to edit |
raw | string |
New raw post data |
[editReason] | string |
Optional Edit Reason that no one ever uses |
callback | request |
Completion callback |
discourse.deletePost(postId, callback)
Delete an existing post.
Kind: static method of discourse
Param | Type | Description |
---|---|---|
postId | number |
Id of the post to delete |
callback | request |
Completion callback |
discourse.postAction(action, postId, [message], callback)
Perform a post action on a post
Kind: static method of discourse
Param | Type | Description |
---|---|---|
action | PostAction |
Action to perform |
postId | number |
Id of the post to act on |
[message] | string |
Content of any applicable moderation message |
callback | request |
Completion callback |
discourse.deletePostAction(action, postId, [message], callback)
Remove a post action from a post
Kind: static method of discourse
Param | Type | Description |
---|---|---|
action | PostAction |
Action to perform |
postId | number |
Id of the post to act on |
[message] | string |
Content of any applicable moderation message |
callback | request |
Completion callback |
discourse.readPosts(topicId, posts, callback)
Read a lists of posts from a topic
Kind: static method of discourse
Param | Type | Description |
---|---|---|
topicId | number |
The topic the posts are from |
posts | Array.<number> |
List of post_number fields from posts to read |
callback | request |
Completion callback |
discourse.getPost(postId, callback)
Get a specific post
Kind: static method of discourse
Param | Type | Description |
---|---|---|
postId | number |
Id of the post to retrieve |
callback | request |
Completion callback |
discourse.getTopic(topicId, callback)
Get topic information
Kind: static method of discourse
Param | Type | Description |
---|---|---|
topicId | number |
Id of topic to get information about |
callback | request |
Completion callback |
discourse.getLastPosts(topicId, eachPost, callback)
Get the last page of a topic.
Kind: static method of discourse
Param | Type | Description |
---|---|---|
topicId | number |
Id of topic to get information about |
eachPost | singleenumeration |
Callback to handle each post |
callback | function |
Completion callback |
discourse.getAllPosts(topicId, eachChunk, callback)
Get all posts in a topic
Kind: static method of discourse
Param | Type | Description |
---|---|---|
topicId | number |
Id of topic to get information about |
eachChunk | enumeration |
Callback to handle each chunk |
callback | function |
Completion callback |
discourse.getAllTopics(eachChunk, callback)
Get all topics visible to current user from /latest
Kind: static method of discourse
Param | Type | Description |
---|---|---|
eachChunk | enumeration |
Callback to handle each chunk |
callback | function |
Completion callback |
discourse.getMessageBus(channels, callback)
Poll message-bus for messages
Kind: static method of discourse
Param | Type | Description |
---|---|---|
channels | Object.<string, number> |
Channels of interest |
callback | request |
Completion callback |
discourse.getNotifications(callback)
Poll for notifications
Kind: static method of discourse
Param | Type | Description |
---|---|---|
callback | request |
Completion callback |
discourse.getUserData(username, callback)
Get user data for an arbitrary user. Will fail if bot is not at least moderator status
Kind: static method of discourse
Param | Type | Description |
---|---|---|
username | string |
Target Username |
callback | request |
Completion callback |
discourse~dGet(url, callback, [delayAfter])
Schedule a GET request to discourse
Kind: inner method of discourse
Param | Type | Default | Description |
---|---|---|---|
url | string |
Site relative URL to fetch | |
callback | request |
Response callback | |
[delayAfter] | number |
0 |
Apply this rate limiting to requests |
discourse~dPost(url, form, callback, [delayAfter])
Schedule a POST request to discourse
Kind: inner method of discourse
Param | Type | Default | Description |
---|---|---|---|
url | string |
Site relative URL to post to | |
form | Object |
Form to post | |
callback | request |
Response callback | |
[delayAfter] | number |
0 |
Apply this rate limiting to requests |
discourse~dPut(url, form, callback, [delayAfter])
Schedule a POST request to discourse
Kind: inner method of discourse
Param | Type | Default | Description |
---|---|---|---|
url | string |
Site relative URL to post to | |
form | Object |
Form to post | |
callback | request |
Response callback | |
[delayAfter] | number |
0 |
Apply this rate limiting to requests |
discourse~dDelete(url, form, callback, [delayAfter])
Schedule a DELETE request to discourse
Kind: inner method of discourse
Param | Type | Default | Description |
---|---|---|---|
url | string |
Site relative URL to post to | |
form | Object |
Form to post | |
callback | request |
Response callback | |
[delayAfter] | number |
0 |
Apply this rate limiting to requests |
discourse~addTimestamp(message) ⇒ string
Add timestamp to message.
if datestamp
configuration setting is truthy add UTC date and time, else
if timestamp
configuration setting is truthy add UTC time, else
return message unaltered
Kind: inner method of discourse
Returns: string
- timestamped input message
Param | Type | Description |
---|---|---|
message | * |
Message to timestamp |
discourse~cleanPost(post) ⇒ CleanedPost
Apply normalization to a post.
Add cleaned
key that contains post raw with bbcode quotes removed
Alter trust_level key as follows:
If poster matches admin.owner
configuration setting set TL to 9
Else if poster is an admin set TL to 8
Else if poster is a moderator set TL to 7
Else if poster is a staff member set TL to 6
* Else if poster is a member of admin.ignore
configuration list set TL to 0
add url
and reply_to
keys to the post
Kind: inner method of discourse
Returns: CleanedPost
- Cleaned Discourse Post Object
Param | Type | Description |
---|---|---|
post | Post |
Discourse Post Object |
discourse~schedule(task, [delayGroup])
Schedule a task
if delayGroup
is provided will schedule such that tasks with the same value
for delayGroup
will be executed at most once per delayGroup
milliseconds
Kind: inner method of discourse
Param | Type | Description |
---|---|---|
task | function |
Task to schedule |
[delayGroup] | number |
Ensure task is rate limited to this rate |
discourse~createPost(topic, [replyTo], raw, callback, [nomute])
Create a post.
Kind: inner method of discourse
Param | Type | Description |
---|---|---|
topic | number |
Id of the topic to reply to |
[replyTo] | number |
Post_number of the post replyied to |
raw | string |
Raw post data |
callback | request |
Completion callback |
[nomute] | boolean |
INTERNAL USE ONLY. Do not set! |