Skip to content

Commit

Permalink
Merge pull request #390 from SockDrawer/feature-PMs-#359
Browse files Browse the repository at this point in the history
Feature pms #359
  • Loading branch information
AccaliaDeElementia authored Dec 5, 2016
2 parents 0d0cb5e + 4165155 commit da730a6
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 44 deletions.
34 changes: 17 additions & 17 deletions docs/api/lib/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ NodeBB provider module User class
* [.getPost()](#sockbot.lib.module_commands..Command+getPost) ⇒ <code>Promise.&lt;Post&gt;</code>
* [.getTopic()](#sockbot.lib.module_commands..Command+getTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.getUser()](#sockbot.lib.module_commands..Command+getUser) ⇒ <code>Promise.&lt;User&gt;</code>
* [.getRoom()](#sockbot.lib.module_commands..Command+getRoom) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.getPM()](#sockbot.lib.module_commands..Command+getPM) ⇒ <code>Promise.&lt;PrivateMessage&gt;</code>
* [.reply(content)](#sockbot.lib.module_commands..Command+reply)
* [.appendReply(content)](#sockbot.lib.module_commands..Command+appendReply)
* [~Commands](#sockbot.lib.module_commands..Commands)
Expand All @@ -42,8 +42,8 @@ NodeBB provider module User class
* [.setPost(post)](#sockbot.lib.module_commands..Commands+setPost)
* [.getTopic()](#sockbot.lib.module_commands..Commands+getTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.setTopic(topic)](#sockbot.lib.module_commands..Commands+setTopic)
* [.getRoom()](#sockbot.lib.module_commands..Commands+getRoom) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.setRoom(room)](#sockbot.lib.module_commands..Commands+setRoom)
* [.getPM()](#sockbot.lib.module_commands..Commands+getPM) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.setPM(pm)](#sockbot.lib.module_commands..Commands+setPM)
* [.getUser()](#sockbot.lib.module_commands..Commands+getUser) ⇒ <code>Promise.&lt;User&gt;</code>
* [.setUser(user)](#sockbot.lib.module_commands..Commands+setUser)
* [.execute()](#sockbot.lib.module_commands..Commands+execute) ⇒ <code>Promise.&lt;Commands&gt;</code>
Expand Down Expand Up @@ -137,7 +137,7 @@ Command Class. Represents a single command within a post
* [.getPost()](#sockbot.lib.module_commands..Command+getPost) ⇒ <code>Promise.&lt;Post&gt;</code>
* [.getTopic()](#sockbot.lib.module_commands..Command+getTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.getUser()](#sockbot.lib.module_commands..Command+getUser) ⇒ <code>Promise.&lt;User&gt;</code>
* [.getRoom()](#sockbot.lib.module_commands..Command+getRoom) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.getPM()](#sockbot.lib.module_commands..Command+getPM) ⇒ <code>Promise.&lt;PrivateMessage&gt;</code>
* [.reply(content)](#sockbot.lib.module_commands..Command+reply)
* [.appendReply(content)](#sockbot.lib.module_commands..Command+appendReply)

Expand Down Expand Up @@ -240,13 +240,13 @@ Get User who posted the command
**Kind**: instance method of <code>[Command](#sockbot.lib.module_commands..Command)</code>
**Returns**: <code>Promise.&lt;User&gt;</code> - Resolved to retrieved User
**Access:** public
<a name="sockbot.lib.module_commands..Command+getRoom"></a>
<a name="sockbot.lib.module_commands..Command+getPM"></a>

#### command.getRoom() ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
Get ChatRoom who posted the command
#### command.getPM() ⇒ <code>Promise.&lt;PrivateMessage&gt;</code>
Get PrivateMessage who posted the command

**Kind**: instance method of <code>[Command](#sockbot.lib.module_commands..Command)</code>
**Returns**: <code>Promise.&lt;ChatRoom&gt;</code> - Resolved to retrieved ChatRoom
**Returns**: <code>Promise.&lt;PrivateMessage&gt;</code> - Resolved to retrieved PrivateMessage
**Access:** public
<a name="sockbot.lib.module_commands..Command+reply"></a>

Expand Down Expand Up @@ -290,8 +290,8 @@ Commands class. Represents all commands for a Notification
* [.setPost(post)](#sockbot.lib.module_commands..Commands+setPost)
* [.getTopic()](#sockbot.lib.module_commands..Commands+getTopic) ⇒ <code>Promise.&lt;Topic&gt;</code>
* [.setTopic(topic)](#sockbot.lib.module_commands..Commands+setTopic)
* [.getRoom()](#sockbot.lib.module_commands..Commands+getRoom) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.setRoom(room)](#sockbot.lib.module_commands..Commands+setRoom)
* [.getPM()](#sockbot.lib.module_commands..Commands+getPM) ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
* [.setPM(pm)](#sockbot.lib.module_commands..Commands+setPM)
* [.getUser()](#sockbot.lib.module_commands..Commands+getUser) ⇒ <code>Promise.&lt;User&gt;</code>
* [.setUser(user)](#sockbot.lib.module_commands..Commands+setUser)
* [.execute()](#sockbot.lib.module_commands..Commands+execute) ⇒ <code>Promise.&lt;Commands&gt;</code>
Expand Down Expand Up @@ -375,25 +375,25 @@ Set the Topic this Commands object refers to
| --- | --- | --- |
| topic | <code>Topic</code> | The Topic to cache |

<a name="sockbot.lib.module_commands..Commands+getRoom"></a>
<a name="sockbot.lib.module_commands..Commands+getPM"></a>

#### commands.getRoom() ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
Get the ChatRoom this Commands object referrs to
#### commands.getPM() ⇒ <code>Promise.&lt;ChatRoom&gt;</code>
Get the PrivateMessage this Commands object referrs to

**Kind**: instance method of <code>[Commands](#sockbot.lib.module_commands..Commands)</code>
**Returns**: <code>Promise.&lt;ChatRoom&gt;</code> - Resolves to the retrieved ChatRoom
**Access:** public
<a name="sockbot.lib.module_commands..Commands+setRoom"></a>
<a name="sockbot.lib.module_commands..Commands+setPM"></a>

#### commands.setRoom(room)
Set the ChatRoom this Commands object refers to
#### commands.setPM(pm)
Set the PrivateMessage this Commands object refers to

**Kind**: instance method of <code>[Commands](#sockbot.lib.module_commands..Commands)</code>
**Access:** public

| Param | Type | Description |
| --- | --- | --- |
| room | <code>ChatRoom</code> | The ChatRoom to cache |
| pm | <code>PrivateMessage</code> | The pm to cache |

<a name="sockbot.lib.module_commands..Commands+getUser"></a>

Expand Down
22 changes: 11 additions & 11 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,14 +217,14 @@ exports.bindCommands = function bindCommands(forum) {
}

/**
* Get ChatRoom who posted the command
* Get PrivateMessage who posted the command
*
* @public
*
* @returns {Promise<ChatRoom>} Resolved to retrieved ChatRoom
* @returns {Promise<PrivateMessage>} Resolved to retrieved PrivateMessage
*/
getRoom() {
return this.parent.getRoom();
getPM() {
return this.parent.getPM();
}

/**
Expand Down Expand Up @@ -422,25 +422,25 @@ exports.bindCommands = function bindCommands(forum) {
}

/**
* Get the ChatRoom this Commands object referrs to
* Get the PrivateMessage this Commands object referrs to
*
* @public
*
* @returns {Promise<ChatRoom>} Resolves to the retrieved ChatRoom
*/
getRoom() {
return this._getItem('room', this.ids.room, forum.Chat);
getPM() {
return this._getItem('pm', this.ids.pm, forum.PrivateMessage);
}

/**
* Set the ChatRoom this Commands object refers to
* Set the PrivateMessage this Commands object refers to
*
* @public
*
* @param {ChatRoom} room The ChatRoom to cache
* @param {PrivateMessage} pm The pm to cache
*/
setRoom(room) {
this._setItem('room', room);
setPM(pm) {
this._setItem('pm', pm);
}

/**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"eslint": "^3.11.0",
"ghooks": "^1.3.2",
"istanbul": "^0.4.3",
"jsdoc-to-markdown": "^2.0.1",
"mkdirp": "^0.5.1",
"mocha": "^3.0.2",
"semantic-release": "^4.3.5",
Expand Down
2 changes: 1 addition & 1 deletion providers/nodebb/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ exports.bindChat = function bindChat(forum) {
post: -1,
topic: -1,
user: message.from.id,
room: message.room,
pm: message.room,
chat: message.id
};
return forum.Commands.get(ids, message.content, (content) => message.reply(content))
Expand Down
5 changes: 3 additions & 2 deletions providers/nodebb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class Forum extends EventEmitter {
this.Category = categoryModule.bindCategory(this);
this.User = userModule.bindUser(this);
this.Notification = notifications.bindNotification(this);
this.Chat = chatModule.bindChat(this);
this.PrivateMessage = chatModule.bindChat(this);
this.Chat = this.PrivateMessage;
this.Format = formatters;
this._plugins = [];
}
Expand Down Expand Up @@ -404,7 +405,7 @@ class Forum extends EventEmitter {
*/
supports(supportString) {
const supported = [
'Chats',
'PrivateMessage',
'Users', 'Users.Avatars', 'Users.Follow', 'Users.URL', 'Users.Seen', 'Users.PostCount',
'Posts', 'Posts.Edit', 'Posts.Vote', 'Posts.Delete', 'Posts.Bookmark', 'Posts.URL',
'Topics', 'Topics.URL', 'Topics.Watch', 'Topics.Mute',
Expand Down
2 changes: 1 addition & 1 deletion providers/nodebb/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ exports.bindNotification = function bindNotification(forum) {
post: notification.postId,
topic: notification.topicId,
user: notification.userId,
room: -1,
pm: -1,
chat: -1
};
return notification.getText()
Expand Down
12 changes: 6 additions & 6 deletions test/lib/commandsTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ describe('lib/config', () => {
getPost: sinon.stub(),
getTopic: sinon.stub(),
getUser: sinon.stub(),
getRoom: sinon.stub()
getPM: sinon.stub()
};
command = new Command({}, parent);
});
Expand All @@ -739,9 +739,9 @@ describe('lib/config', () => {
});
it('should proxy getRoom() to parent.getRoom()', () => {
const expected = Math.random();
parent.getRoom.returns(expected);
command.getRoom().should.equal(expected);
parent.getRoom.should.have.been.calledOnce;
parent.getPM.returns(expected);
command.getPM().should.equal(expected);
parent.getPM.should.have.been.calledOnce;
});
});
describe('reply()', () => {
Expand Down Expand Up @@ -883,7 +883,7 @@ describe('lib/config', () => {
['getPost', 'Post', 'post'],
['getTopic', 'Topic', 'topic'],
['getUser', 'User', 'user'],
['getRoom', 'Chat', 'room']
['getPM', 'PrivateMessage', 'pm']
].forEach((config) => {
const method = config[0],
object = config[1],
Expand Down Expand Up @@ -932,7 +932,7 @@ describe('lib/config', () => {
[
['setPost', 'post'],
['setTopic', 'topic'],
['setRoom', 'room'],
['setPM', 'pm'],
['setUser', 'user']
].forEach((config) => {
const method = config[0],
Expand Down
4 changes: 2 additions & 2 deletions test/providers/nodebb/chatTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1068,11 +1068,11 @@ describe('providers/nodebb/chat', () => {
message: 1
}).then(() => {
const param = forum.Commands.get.firstCall.args[0];
param.should.have.all.keys('post', 'topic', 'user', 'room', 'chat');
param.should.have.all.keys('post', 'topic', 'user', 'pm', 'chat');
param.post.should.equal(-1);
param.topic.should.equal(-1);
param.user.should.equal(userId);
param.room.should.equal(roomId);
param.pm.should.equal(roomId);
param.chat.should.equal(chatId);
});
});
Expand Down
6 changes: 3 additions & 3 deletions test/providers/nodebb/indexTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ describe('providers/nodebb', () => {
});

it('must return true if a capability is supported', () => {
forum.supports('Chats').should.be.true;
forum.supports('PrivateMessage').should.be.true;
forum.supports('Users').should.be.true;
forum.supports('Posts').should.be.true;
forum.supports('Topics').should.be.true;
Expand All @@ -900,11 +900,11 @@ describe('providers/nodebb', () => {
});

it('should return true if all items in an array are supported', () => {
forum.supports(['Users', 'Chats']).should.be.true;
forum.supports(['Users', 'PrivateMessage']).should.be.true;
});

it('must return false if any items in an array are not supported', () => {
forum.supports(['Users', 'Chats', 'Halloween']).should.be.false;
forum.supports(['Users', 'PrivateMessage', 'Halloween']).should.be.false;
});
});
describe('_emit', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/providers/nodebb/notificationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ describe('providers/nodebb/notification', () => {
post: post,
topic: topic,
user: user,
room: -1,
pm: -1,
chat: -1
});
args[1].should.eql(text);
Expand Down

0 comments on commit da730a6

Please sign in to comment.