Skip to content

Commit

Permalink
Merge pull request #261 from SockDrawer/integration
Browse files Browse the repository at this point in the history
Preparing 2.11.4 release
  • Loading branch information
AccaliaDeElementia committed Oct 6, 2015
2 parents 61c4cf1 + 9fac932 commit 2489806
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 347 deletions.
6 changes: 3 additions & 3 deletions docs/api/lib/browser.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Webbrowser abstraction for communicating with discourse
* [~createPost(topicId, [replyTo], content, callback)](#module_browser..createPost)
* [~createPrivateMessage(to, title, content, callback)](#module_browser..createPrivateMessage)
* [~editPost(postId, content, [editReason], callback)](#module_browser..editPost)
* [~readPosts(topicId, postIds, callback)](#module_browser..readPosts)
* [~readPosts(topicId, postNumbers, callback)](#module_browser..readPosts)
* [~getPost(postId, callback)](#module_browser..getPost)
* [~getPosts(topicId, eachPost, complete)](#module_browser..getPosts)
* [~getLastPosts(topicId, eachPost, complete)](#module_browser..getLastPosts)
Expand Down Expand Up @@ -233,15 +233,15 @@ Edit an existing post.
| callback | <code>postedCallback</code> | Completion callback |

<a name="module_browser..readPosts"></a>
### browser~readPosts(topicId, postIds, callback)
### browser~readPosts(topicId, postNumbers, callback)
Read post

**Kind**: inner method of <code>[browser](#module_browser)</code>

| Param | Type | Description |
| --- | --- | --- |
| topicId | <code>number</code> | Id of topic to read |
| postIds | <code>Array.&lt;number&gt;</code> | Ids of posts to read |
| postNumbers | <code>Array.&lt;number&gt;</code> | Numbers of posts to read |
| callback | <code>postedCallback</code> | Completion callback |

<a name="module_browser..getPost"></a>
Expand Down
3 changes: 2 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ SockBot is configured via a JSON or YAML configuration file. The configuration c
one core configuration dictionary and one plugin configuration dictionary.

Core configuration options are fixed and can be found described in the API documentation for [defaultConfig].
Plugin configuration options are determined by the individual plugins and will vary from plugin to plugin.
Plugin configuration options are determined by the individual plugins and will vary from plugin to plugin;
consult each plugins' documentation for more details.

[defaultConfig]: api/config/#defaultConfig

Expand Down
18 changes: 11 additions & 7 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,12 +427,13 @@ function editPost(postId, content, editReason, callback) {
if (typeof callback !== 'function') {
throw new Error('callback must be supplied');
}
const signature = internals.signature.replace('%NOW%', new Date().toISOString());
this.queue.push({
method: 'PUT',
url: '/posts/' + postId,
form: {
post: {
raw: content + internals.signature,
raw: content + signature,
'edit_reason': editReason
}
},
Expand All @@ -450,21 +451,21 @@ function editPost(postId, content, editReason, callback) {
* Read post
*
* @param {number} topicId Id of topic to read
* @param {number[]} postIds Ids of posts to read
* @param {number[]} postNumbers Numbers of posts to read
* @param {postedCallback} callback Completion callback
*/
function readPosts(topicId, postIds, callback) {
function readPosts(topicId, postNumbers, callback) {
const ctx = this;
if (typeof callback !== 'function') {
throw new Error('callback must be supplied');
}
if (typeof postIds === 'number') {
postIds = [postIds];
if (typeof postNumbers === 'number') {
postNumbers = [postNumbers];
}
async.whilst(function () {
return postIds.length > 0;
return postNumbers.length > 0;
}, function (next) {
const part = postIds.splice(0, 200),
const part = postNumbers.splice(0, 200),
form = {
'topic_id': topicId,
'topic_time': 4242
Expand Down Expand Up @@ -531,6 +532,9 @@ function getPosts(topicId, eachPost, complete) {
if (err2) {
return next(err2);
}
if (!topic2.post_stream || !Array.isArray(topic2.post_stream.posts)) {
return next(new Error('Invalid post_stream; cannot continue'));
}
async.eachSeries(topic2.post_stream.posts.map((p) => cleanPost(p)), (post, postNext) => {
setTimeout(() => eachPost(post, (error) => postNext(error)), 0);
}, next);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sockbot",
"version": "2.11.3",
"version": "2.11.4",
"releaseName": "Cheery Chiffon",
"description": "A sockpuppet bot to use on http://what.thedailywtf.com.",
"repository": "https://github.com/SockDrawer/SockBot",
Expand Down
8 changes: 4 additions & 4 deletions plugins/autoreader.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ exports.readify = function () {
}
internals.events.emit('logMessage', 'Reading topic `' + topic.slug + '`');
const now = new Date().getTime() - internals.config.minAge;
const postIds = [];
const postNumbers = [];
internals.browser.getPosts(topic.id, (post, nextPost) => {
if (post && !post.read && Date.parse(post.created_at) < now) {
postIds.push(post.id);
postNumbers.push(post.post_number);
}
nextPost();
}, () => {
if (postIds.length > 0) {
internals.browser.readPosts(topic.id, postIds, () => 0);
if (postNumbers.length > 0) {
internals.browser.readPosts(topic.id, postNumbers, () => 0);
}
});
nextTopic();
Expand Down
155 changes: 0 additions & 155 deletions plugins/powerlevel.js

This file was deleted.

34 changes: 34 additions & 0 deletions test/lib/browserTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,40 @@ describe('browser', () => {
});
spy.lastCall.args.should.deep.equal([null]);
});
it('should gracefully handle null post_stream', () => {
const spy = sinon.spy(),
eachSpy = sinon.stub(),
topic = {
'post_stream': {
stream: [2]
}
},
posts = {};
eachSpy.yields(null);
queue.push.onFirstCall().yieldsTo('callback', null, topic);
queue.push.onSecondCall().yieldsTo('callback', null, posts);
object.getPosts(314159, eachSpy, spy);
sandbox.clock.tick();
//No assertions needed
});
it('should gracefully handle invalid post_stream', () => {
const spy = sinon.spy(),
eachSpy = sinon.stub(),
topic = {
'post_stream': {
stream: [2]
}
},
posts = {
'post_stream': {}
};
eachSpy.yields(null);
queue.push.onFirstCall().yieldsTo('callback', null, topic);
queue.push.onSecondCall().yieldsTo('callback', null, posts);
object.getPosts(314159, eachSpy, spy);
sandbox.clock.tick();
//No assertions needed
});
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/plugins/autoreaderTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('autoreader', () => {
});
sandbox.stub(browser, 'getPosts', (_, each, complete) => {
each({
id: 1,
post_number: 1,
read: false,
created_at: '2000-01-01 00:00'
}, complete);
Expand All @@ -151,7 +151,7 @@ describe('autoreader', () => {
});
sandbox.stub(browser, 'getPosts', (_, each, complete) => {
each({
id: 1,
post_number: 1,
read: true,
created_at: '2000-01-01 00:00'
}, complete);
Expand All @@ -170,7 +170,7 @@ describe('autoreader', () => {
});
sandbox.stub(browser, 'getPosts', (_, each, complete) => {
each({
id: 1,
post_number: 1,
read: false,
created_at: '2100-01-01 00:00'
}, complete);
Expand Down
6 changes: 5 additions & 1 deletion test/plugins/likesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

const chai = require('chai'),
sinon = require('sinon'),
async = require('async');
async = require('async'),
sinonChai = require('sinon-chai');
chai.should();
chai.use(sinonChai);
const expect = chai.expect;

const later = require('later');

// The thing we're testing
const likes = require('../../plugins/likes'),
utils = require('../../lib/utils');
const dummyCfg = {
Expand Down
Loading

0 comments on commit 2489806

Please sign in to comment.