Skip to content

Commit

Permalink
Merge pull request #8933 from ramrami/internal-hubot-support-room-types
Browse files Browse the repository at this point in the history
[NEW] Internal hubot support for Direct Messages and Private Groups
  • Loading branch information
rodrigok authored Feb 17, 2018
2 parents 490fa2d + cf8f8f1 commit 99928a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/rocketchat-i18n/i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,9 @@
"InternalHubot_ScriptsToLoad": "Scripts to Load",
"InternalHubot_ScriptsToLoad_Description": "Please enter a comma separated list of scripts to load from your custom folder",
"InternalHubot_Username_Description": "This must be a valid username of a bot registered on your server.",
"InternalHubot_EnableForChannels": "Enable for Public Channels",
"InternalHubot_EnableForDirectMessages": "Enable for Direct Messages",
"InternalHubot_EnableForPrivateGroups": "Enable for Private Channels",
"Invalid_confirm_pass": "The password confirmation does not match password",
"Invalid_email": "The email entered is invalid",
"Invalid_Export_File": "The file uploaded isn't a valid %s export file.",
Expand Down
10 changes: 9 additions & 1 deletion packages/rocketchat-internal-hubot/hubot.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,16 @@ const InternalHubotReceiver = (message) => {
if (DEBUG) { console.log(message); }
if (message.u.username !== InternalHubot.name) {
const room = RocketChat.models.Rooms.findOneById(message.rid);
const enabledForC = RocketChat.settings.get('InternalHubot_EnableForChannels');
const enabledForD = RocketChat.settings.get('InternalHubot_EnableForDirectMessages');
const enabledForP = RocketChat.settings.get('InternalHubot_EnableForPrivateGroups');
const subscribedToP = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(room._id, InternalHubot.user._id);

if (room.t === 'c') {
if (
(room.t === 'c' && enabledForC)
|| (room.t === 'd' && enabledForD)
|| (room.t === 'p' && enabledForP && subscribedToP)
) {
const InternalHubotUser = new Hubot.User(message.u.username, {room: message.rid});
const InternalHubotTextMessage = new Hubot.TextMessage(InternalHubotUser, message.msg, message._id);
InternalHubot.adapter.receive(InternalHubotTextMessage);
Expand Down
3 changes: 3 additions & 0 deletions packages/rocketchat-internal-hubot/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ RocketChat.settings.addGroup('InternalHubot', function() {
this.add('InternalHubot_Username', 'rocket.cat', { type: 'string', i18nLabel: 'Username', i18nDescription: 'InternalHubot_Username_Description', 'public': true });
this.add('InternalHubot_ScriptsToLoad', '', { type: 'string'});
this.add('InternalHubot_PathToLoadCustomScripts', '', { type: 'string' });
this.add('InternalHubot_EnableForChannels', true, { type: 'boolean' });
this.add('InternalHubot_EnableForDirectMessages', false, { type: 'boolean' });
this.add('InternalHubot_EnableForPrivateGroups', false, { type: 'boolean' });
// this.add('InternalHubot_reload', 'reloadInternalHubot', {
// type: 'action',
// actionText: 'reload'
Expand Down

0 comments on commit 99928a1

Please sign in to comment.