Skip to content

Commit

Permalink
Convert rocketchat-internal-hubot to main module structure (#12671)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcosSpessatto authored and rodrigok committed Nov 20, 2018
1 parent fff398a commit 51df48a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
16 changes: 2 additions & 14 deletions packages/rocketchat-internal-hubot/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,9 @@ Package.onUse(function(api) {
'ecmascript',
'tracker',
'rocketchat:lib',
'templating',
]);

api.use('templating', 'client');

api.addFiles([
'hubot.js',
'settings.js',
], ['server']);

api.export('Hubot', ['server']);
api.export('HubotScripts', ['server']);
api.export('InternalHubot', ['server']);
api.export('InternalHubotReceiver', ['server']);
api.export('RocketChatAdapter', ['server']);

api.mainModule('server/index.js', 'server');
});

// It needs to be here cuz they are coffee files and need to be compiled
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* globals __meteor_bootstrap__ */
import { Meteor } from 'meteor/meteor';
import { RocketChat } from 'meteor/rocketchat:lib';
import _ from 'underscore';
import s from 'underscore.string';

Expand All @@ -12,7 +13,7 @@ const Hubot = Npm.require('hubot');
// Log messages?
const DEBUG = false;

let InternalHubot = {};
export let InternalHubot = {};

const sendHelper = Meteor.bindEnvironment((robot, envelope, strings, map) => {
while (strings.length > 0) {
Expand All @@ -36,6 +37,10 @@ Hubot.Response.prototype.priv = (...strings) => this.robot.adapter.priv(this.env
// More monkey-patching
Hubot.Robot.prototype.loadAdapter = () => {}; // disable

export {
Hubot,
};

// grrrr, Meteor.bindEnvironment doesn't preserve `this` apparently
const bind = function(f) {
const g = Meteor.bindEnvironment((self, ...args) => f.apply(self, args));
Expand Down Expand Up @@ -64,7 +69,7 @@ class Robot extends Hubot.Robot {
catchAll(callback) { return super.catchAll(Meteor.bindEnvironment(callback)); }
}

class RocketChatAdapter extends Hubot.Adapter {
export class RocketChatAdapter extends Hubot.Adapter {
// Public: Raw method for sending data back to the chat source. Extend this.
//
// envelope - A Object with message, room and user details.
Expand Down Expand Up @@ -170,7 +175,7 @@ class RocketChatAdapter extends Hubot.Adapter {
}
}

const InternalHubotReceiver = (message) => {
export const InternalHubotReceiver = (message) => {
if (DEBUG) { console.log(message); }
if (message.u.username !== InternalHubot.name) {
const room = RocketChat.models.Rooms.findOneById(message.rid);
Expand All @@ -192,7 +197,7 @@ const InternalHubotReceiver = (message) => {
return message;
};

class HubotScripts {
export class HubotScripts {
constructor(robot) {
const modulesToLoad = [
'hubot-help/src/help.coffee',
Expand Down
10 changes: 10 additions & 0 deletions packages/rocketchat-internal-hubot/server/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './settings';
import { Hubot, HubotScripts, InternalHubot, InternalHubotReceiver, RocketChatAdapter } from './hubot';

export {
Hubot,
HubotScripts,
InternalHubot,
InternalHubotReceiver,
RocketChatAdapter,
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RocketChat } from 'meteor/rocketchat:lib';

RocketChat.settings.addGroup('InternalHubot', function() {
this.add('InternalHubot_Enabled', false, { type: 'boolean', i18nLabel: 'Enabled' });
this.add('InternalHubot_Username', 'rocket.cat', { type: 'string', i18nLabel: 'Username', i18nDescription: 'InternalHubot_Username_Description', public: true });
Expand Down

0 comments on commit 51df48a

Please sign in to comment.