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 2 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
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;
12 changes: 12 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* jshint unused:true, node:true */
"use strict";

var config = {}

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

Choose a reason for hiding this comment

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

process.env.DEBUG should be process.env.DEV


config.irc = { hostname : 'irc.gitter.im', user : 'gitti' };
Copy link
Contributor

Choose a reason for hiding this comment

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

hostname is repeated, would be better at the top level. The same for user, maybe use config.user = 'gitter'


module.exports = config;
2 changes: 1 addition & 1 deletion lib/gitter-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ Adapter.prototype.joinRoom = function(channel) {
var channelType = '*'; // TODO set right type -> * private, @ secret, = public

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