Skip to content
This repository has been archived by the owner on Feb 5, 2020. It is now read-only.

Small changes/adding cfg #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.swp
node_modules
npm-debug.log
npm-debug.log
9 changes: 4 additions & 5 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var EventEmitter = require('eventemitter3');
var carrier = require('carrier');
var ircMessage = require('irc-message');
var uuid = require('uuid');
var config = require('./config');

// The Client handles a single socket client,
// parses each line and emits an event when an
Expand All @@ -20,10 +21,8 @@ function Client(socket) {
this.carry = carrier.carry(socket);
this.carry.on('line', this.parse.bind(this));

// TODO Get network and hostname from a config file
this.hostname = 'irc.gitter.im';
this.hostname = config.hostname;
this.host = ':' + this.hostname;

this.user = null;
this.nick = null;

Expand Down Expand Up @@ -132,7 +131,7 @@ Client.prototype.disconnect = function(opts) {

if (opts.msg) {
try {
var mask = ':gitter!gitter@irc.gitter.im';
var mask = ':'+config.irc.user+'!'+config.irc.user+'@'+config.irc.hostname;
this.send(mask, 'PRIVMSG', this.nick, ': ' + opts.msg);
}
catch(err) {
Expand All @@ -143,4 +142,4 @@ Client.prototype.disconnect = function(opts) {
this.socket.end();
};

module.exports = Client;
module.exports = Client;
13 changes: 13 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* jshint unused:true, node:true */
"use strict";

var config = {}

config.hostname = process.env.DEV ? "localhost" : "irc.gitter.im";
config.user = 'gitter';
// '&& false' because of no 'faye'
config.gitter = process.env.DEV && false ? {client: {host: "localhost", port: 5000, prefix: true}, faye: {host: 'http://localhost:5000/faye'}} : {};

config.irc = { hostname : config.hostname, user : config.user };

module.exports = config;
26 changes: 12 additions & 14 deletions lib/gitter-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var debug = require('debug')('irc-gitter-adapter');
var irc = require('./protocol');
var Gitter = require('node-gitter');
var manifest = require('../package.json');
var config = require('./config');
var VERSION = manifest.version;
var DATE = Date();

Expand Down Expand Up @@ -49,7 +50,7 @@ Adapter.prototype.listenForOneToOnes = function() {
.then(function(room) {
if (!room.oneToOne) return;
var nick = room.user.username;
var mask = ':' + nick + '!' + nick + '@irc.gitter.im';
var mask = ':' + nick + '!' + nick + '@' + config.irc.hostname;
msg.text.split('\n').forEach(function(line) {
c.send(mask, 'PRIVMSG', c.nick, ':' + line);
});
Expand All @@ -64,11 +65,8 @@ Adapter.prototype.listenForOneToOnes = function() {
};

Adapter.prototype.setup = function(token) {
var c = this.client;

// TODO move this to a config file
var opts = {};
if (process.env.DEV) opts = {client: {host: "localhost", port: 5000, prefix: true}, faye: {host: 'http://localhost:5000/faye'}};
var c = this.client;
var opts= config.gitter;

this.gitterClient = new Gitter(token, opts);
this.gitterClient.currentUser()
Expand All @@ -80,8 +78,8 @@ Adapter.prototype.setup = function(token) {
}.bind(this))
.catch(function(err) {
log('Authentication failed for token ', token);
var mask = ':gitter!gitter@irc.gitter.im';
c.send(mask, 'PRIVMSG', 'gitter', ': Authentication failed. Get a valid token from https://irc.gitter.im');
var mask = ':'+config.irc.user+'!'+config.irc.user+'@'+config.irc.hostname;
c.send(mask, 'PRIVMSG', config.irc.user, ': Authentication failed. Get a valid token from https://irc.gitter.im');
this.quit();
}.bind(this));
};
Expand All @@ -104,7 +102,7 @@ Adapter.prototype.subscribeToRoom = function(room) {
var nick = message.fromUser.username;
if (nick === c.nick) return; // User's own message

var mask = ':' + nick + '!' + nick + '@irc.gitter.im';
var mask = ':' + nick + '!' + nick + '@' + config.irc.hostname;

var text;
message.text.split('\n').forEach(function(line) {
Expand All @@ -118,7 +116,7 @@ Adapter.prototype.subscribeToRoom = function(room) {
room.on('events', function(evt) {
if (evt.operation !== 'create') return;
var message = evt.model;
var mask = ':gitter!gitter@irc.gitter.im';
var mask = ':'+config.irc.user+'!'+config.irc.user+'@' + config.irc.hostname;

c.send(mask, 'PRIVMSG', '#' + room.uri, ':' + message.text);
}.bind(this));
Expand All @@ -127,12 +125,12 @@ Adapter.prototype.subscribeToRoom = function(room) {
var nick, mask;
if (evt.operation === 'create') {
nick = evt.model.username;
mask = ':' + nick + '!' + nick + '@irc.gitter.im';
mask = ':' + nick + '!' + nick + '@' + config.irc.hostname;
c.send(mask, 'JOIN', '#' + room.uri);
}
if (evt.operation === 'remove') {
nick = evt.model.username;
mask = ':' + nick + '!' + nick + '@irc.gitter.im';
mask = ':' + nick + '!' + nick + '@' + config.irc.hostname;
c.send(mask, 'PART', '#' + room.uri);
}
});
Expand Down Expand Up @@ -190,10 +188,10 @@ Adapter.prototype.joinRoom = function(channel) {
})
.spread(function(room, users) {
var _channel = '#' + room.uri;
var channelType = '*'; // TODO set right type -> * private, @ secret, = public
var channelType = '=';

var usernames = users.map(function(u) { return u.username; });
usernames.push('gitter'); // Fake gitter user for Events
usernames.push( config.irc.user ); // Fake gitter user for Events
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're missing a require('./config') on this file? Also check line number 72 to use config.gitter endpoint there.


c.send(c.mask(), 'JOIN', _channel);
c.send(c.host, irc.reply.topic, c.nick, _channel, ':' + room.topic);
Expand Down