示例#1
0
文件: index.js 项目: Ferdi265/osu-irc
module.exports = function (nick, pass) {
	var inst = new process.EventEmitter(),
		stream = net.connect({
			port: 6667,
			host: 'irc.ppy.sh'
		}),
		client = irc(stream),
		buffer = [],
		timeout = null,
		ready = false,
		startTimeout = false,
		pushIRC = function () {
			var line = buffer.splice(0, 1)[0];
			if (line) {
				client.send(line.target, line.msg);
				timeout = setTimeout(pushIRC, 2000);
			} else {
				timeout = null;
			}
		},
		send = function (target, msg) {
			buffer.push({
				msg: msg,
				target: target || nick
			});
			if (ready && timeout === null) {
				timeout = setTimeout(pushIRC, 0);
			} else if (!ready && !startTimeout) {
				startTimeout = true;
			}
		},
		checkLink = function (msg) {
			var regex = /http:\/\/osu\.ppy\.sh\/p\/ircauth\?action=allow&nick=.+&ip=\d+\.\d+\.\d+\.\d+/;
			if (regex.test(msg.trailing)) {
				inst.emit('auth', regex.exec(msg.trailing)[0]);
			}
		};
	if (pass) {
		client.pass(pass);
	}
	client.nick(nick);
	client.user(nick, nick);

	client.on('motd', function () {
		if (startTimeout) {
			timeout = setTimeout(pushIRC, 0);
		}
		ready = true;
		inst.emit('ready');
		client.removeListener('data', checkLink);
	});
	client.on('data', checkLink);
	client.on('message', function (msg) {
		inst.emit('message', msg);
	});
	inst.send = send;
	return inst;
};
示例#2
0
let connectUser = function(args, callback) {
  let userID = args.userID,
      server = args.server,
      channel= args.channel;
      console.log("\n----------------------------------------------------------\n\n");
      console.log("\nuserID : " + userID + "\nserver : " + server + "channel : " + channel);
      console.log("\n----------------------------------------------------------\n\n");

  let stream = net.connect({
    port : 6667,
    host : server
  }, function (stream){
    console.log("Connected to stream : " + server);
  });

  let client;

  if (!connections[userID]) {
    client = irc(stream);
    connections[userID] = {};
    connections[userID][server]= {
      client: client,
      channels: []
      };
    client.user(userID, "WHOIS");
    client.nick(userID, function (){
      client.on('data', function (data) {
        if (data.command === 'ERR_NICKNAMEINUSE') {
          console.log("[ X ]\tNick in use. Trying : " + userID + "_");
          client.nick(userID+"_");
          client.join(channel);
          connections[userID][server].nickname = userID+"_";
        }
        else connections[userID][server].nickname = userID;
      });
    });
  }
  else {
    client = connections[userID][server].client;
  }

  client.join(channel, null, function(){
    client.on('data', function (data) {
      if (data.command === 'RPL_ENDOFNAMES') {
        //console.log(data);
        connections[userID][server].channels.push(channel);
        console.log("\n----------------------------------------------------------\n\n");
        console.log("Joined channel : ", channel);
        console.log("\n----------------------------------------------------------\n\n");
      }
    });
  });

  if (callback) callback(client);
};
示例#3
0
    it('sends a CAP REQ for tags if needed', done => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch({ init: true, tags: true, membership: false }))

      stream.once('data', line => {
        strictEqual(line, 'CAP REQ :twitch.tv/commands twitch.tv/tags\r\n')
        done()
      })
      client.emit('motd')
    })
    it('sends a .commercial privmsg to Twitch', done => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch())

      stream.on('data', line => {
        strictEqual(line, 'PRIVMSG #channel :.commercial 60\r\n')
        done()
      })

      client.commercial('#channel', 60)
    })
    it('defaults to a 30 second commercial', done => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch())

      stream.on('data', line => {
        strictEqual(line, 'PRIVMSG #channel :.commercial 30\r\n')
        done()
      })

      client.commercial('#channel')
    })
示例#6
0
    it('sends a .timeout privmsg to Twitch', (done) => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch())

      stream.on('data', (line) => {
        strictEqual(line, 'PRIVMSG #channel :.timeout spammer 600\r\n')
        done()
      })

      client.timeout('#channel', 'spammer')
    })
示例#7
0
    it('can use a variable timeout duration', (done) => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch())

      stream.on('data', (line) => {
        strictEqual(line, 'PRIVMSG #channel :.timeout spammer 1337\r\n')
        done()
      })

      client.timeout('#channel', 'spammer', 1337)
    })
示例#8
0
    it('sends a .ban privmsg to Twitch', (done) => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch())

      stream.on('data', (line) => {
        strictEqual(line, 'PRIVMSG #channel :.ban annoying_user\r\n')
        done()
      })

      client.ban('#channel', 'annoying_user')
    })
示例#9
0
文件: irc.js 项目: topics-im/client
  createConnection: function (address, nick) {
    var stream = net.connect({
      port: 6667,
      host: address
    });
    var client = irc(stream);

    client.nick(nick);
    client.user(Math.random().toString(36).substring(2, 10), 'Topics User');

    return client;
  },
示例#10
0
function getIrcClient(props) {
	var consumer = getConsumer(props.key),
		network = consumer.networks[props.network],
		user, nick, socket, client;
	
	if(props.network && props.nick) {
		try {
			return network.clients[props.nick].client;
		} catch (e) {
			throw Error('GET_IRC_CLIENT_BAD_NETWORK_OR_NICK');
		}
	} else if(props.network && props.name) {
		user = getUser(props);
		
		if(!consumer.networks[props.network]) {
			consumer.networks[props.network] = {
				props: config(props.network).properties,
				clients: {}
			};
		}
		
		if(!user.networks[props.network]) {
			user.networks[props.network] = {
				nick: user.props.nick,
				channels: {}
			};
		}
		
		nick = user.networks[props.network].nick;
		
		if(!network.clients[nick]) {
			
			// Creating a new client connection.
			
			socket = net.connect(config(props.network).connection);
			client = irc(socket);
			
			initializeConnection(network, props, client);
			attachListeners(consumer, props.network, nick, client, props.emitter);
			
			network.clients[nick] = {
				name: props.name,
				socket: socket,
				client: client
			};
		}
		
		return network.clients[nick];
	} else {
		throw Error('GET_IRC_CLIENT_BAD_ARGS');
	}
}
示例#11
0
Bot.prototype.connect = function () {
  var stream = net.connect({
    port: this.port,
    host: this.server
  });

  this.client = irc(stream);
  this.client.use(addon(this));
  this.client.pass(this.pass);
  this.client.nick(this.name);
  this.client.user(this.name, this.realname);
  this.client.join(this.chan);
};
示例#12
0
文件: client.js 项目: GabLeRoux/shout
Client.prototype.connect = function(args) {
	var client = this;
	var server = _.defaults(_.pick(args, ['host', 'port', 'rejectUnauthorized']), {
		host: "irc.freenode.org",
		port: 6667,
		rejectUnauthorized: true
	});

	var stream = args.tls ? tls.connect(server) : net.connect(server);
	stream.on("error", function(e) {
		console.log(e);
	});

	var nick = args.nick || "shout-user";
	var realname = args.realname || "Shout User";

	var irc = slate(stream);

	if (args.password) {
		irc.pass(args.password);
	}

	irc.me = nick;
	irc.nick(nick);
	irc.user(nick, realname);

	var network = new Network({
		host: server.host,
		irc: irc
	});

	client.networks.push(network);
	client.emit("network", {
		network: network
	});

	events.forEach(function(plugin) {
		var path = "./plugins/irc-events/" + plugin;
		require(path).apply(client, [
			irc,
			network
		]);
	});

	var join = (args.join || "#shout-irc").replace(/\,/g, " ").split(/\s+/g);
	irc.on("welcome", function() {
		irc.join(join);
	});
};
示例#13
0
    it('sends a CAP REQ for commands and a TWITCHCLIENT message', done => {
      let stream = PassThrough()
      let client = irc(stream)
      client.use(twitch({ init: true }))

      stream.once('data', line => {
        strictEqual(line, 'CAP REQ :twitch.tv/commands twitch.tv/membership\r\n')
        stream.once('data', line => {
          strictEqual(line, 'TWITCHCLIENT 4\r\n')
          done()
        })
      })

      client.emit('motd')
    })
示例#14
0
function ChatStream(channel, options) {
  Duplex.apply(this);
  options = options || {};

  this.channel  = channel;
  this.server   = options.server || 'irc.freenode.net';
  this.port     = options.port || 6667;
  this.username = options.username || this.generateUsername();
  this.password = options.password;
  this.socket   = net.connect({ host: this.server, port: this.port});
  this.client   = irc(this.socket);
  this.client.nick(this.username);
  this.client.user('username', this.username);

  this.socket.on('error', this.emit.bind(this, 'error'));
  this.onConnect();
}
示例#15
0
test('motivates you', function(t) {
  t.plan(2);
  var stream = new Stream();
  var client = irc(stream);
  client.use(motivate());

  var n = 0;
  stream.on('data', function(chunk) {
    switch (n++) {
      case 0:
        t.equal(chunk, 'PRIVMSG #nwitch :!m KenanY\r\n');
        break;
      case 1:
        t.equal(chunk, 'PRIVMSG #nwitch :You\'re doing good work, KenanY!\r\n');
        break;
    }
  });

  stream.write('PRIVMSG #nwitch :!m KenanY\r\n');
});
示例#16
0
test('does nothing when passed no nicks', function(t) {
  t.plan(1);
  var stream = new Stream();
  var client = irc(stream);
  client.use(motivate());

  var n = 0;
  stream.on('data', function(chunk) {
    switch (n++) {
      case 0:
        t.equal(chunk, 'PRIVMSG #nwitch :!m\r\n');
        break;
      case 1:
        t.fail();
        break;
    }
  });

  stream.write('PRIVMSG #nwitch :!m\r\n');
});
示例#17
0
test('googles that for you', function(t) {
  t.plan(2);
  var stream = new Stream();
  var client = irc(stream);
  client.use(lmgtfy());

  var n = 0;
  stream.on('data', function(chunk) {
    switch (n++) {
      case 0:
        t.equal(chunk, 'PRIVMSG #nwitch :!lmgtfy how do i javascript\r\n');
        break;
      case 1:
        t.equal(chunk, 'PRIVMSG #nwitch :: http://lmgtfy.com/?q=how+do+i+javascript\r\n');
        break;
    }
  });

  stream.write('PRIVMSG #nwitch :!lmgtfy how do i javascript\r\n');
});
示例#18
0
test('decodes when commanded', function(t) {
  t.plan(2);
  var stream = new Stream();
  var client = irc(stream);
  client.use(nwitchBase64());

  var n = 0;
  stream.on('data', function(chunk) {
    switch (n++) {
      case 0:
        t.equal(chunk, 'PRIVMSG #nwitch :!base64 decode SGVsbG8gV29ybGQ=\r\n');
        break;
      case 1:
        t.equal(chunk, 'PRIVMSG #nwitch :: Hello World\r\n');
        break;
    }
  });

  stream.write('PRIVMSG #nwitch :!base64 decode SGVsbG8gV29ybGQ=\r\n');
});
示例#19
0
test('is confused when not told what to do', function(t) {
  t.plan(2);
  var stream = new Stream();
  var client = irc(stream);
  client.use(nwitchBase64());

  var n = 0;
  stream.on('data', function(chunk) {
    switch (n++) {
      case 0:
        t.equal(chunk, 'PRIVMSG #nwitch :!base64 SGVsbG8gV29ybGQ=\r\n');
        break;
      case 1:
        t.equal(chunk, 'PRIVMSG #nwitch :: Huh? Try `!base64 encode|decode <query>`\r\n');
        break;
    }
  });

  stream.write('PRIVMSG #nwitch :!base64 SGVsbG8gV29ybGQ=\r\n');
});
示例#20
0
文件: bot.js 项目: hagb4rd/deepblu
function Bot(nick, user, pass, host, port) {
    var self = this;
    if (nick)
        self.nick = nick;
    if (user)
        self.user = user;
    if (host)
        self.host = host;
    if (port)
        self.port = port;
    
    self.log = logdb.Factory[self.host]();
    
    
    //Secure Socket?
    if (self.pfxFile && self.pfxPass) {
        console.log('SECURE CONNECTION..')
        var tlsOptions = {
            pfx: fs.readFileSync(self.pfxFile),
            passphrase: self.pfxPass,
            host: self.host,
            port: self.port
        };
        self.stream = tls.connect(tlsOptions, () => {
            console.log('Socket conntected', util.inspect(self.stream, { showHidden: false, depth: 0, colors: true }));
        })
    } else {
        self.stream = net.connect({ port: self.port, host: self.host });
    };


    self.client = promisify(irc(self.stream), true, ["names", "whois"]);
    self.client.pass(pass);
    self.client.nick(self.nick);
    self.client.user(self.user, self.user);

    //install plugins
    //self.client.use(pong());
    self.client.use(replcmd(self));
    self.client.use(logger(self));
};
示例#21
0
Monitor.prototype._read = function() {
  var self = this;
  this.client = irc(
    net.connect({
      port: 6667,
      host: 'irc.wikimedia.org'
    })
  );
  this.channel = '#' + this.lang + '.' + this.project;

  this.client.on('data', function(msg) {
    if (msg.command !== 'PRIVMSG') {
      return;
    }

    var message = msg.trailing.replace(/[\u0003]([0-9]*)/g, '');
    var edit = regret('wikipedia.edit', message);

    if (edit === null) {
      debug('skip', message);
      return;
    }

    edit.diff_url = edit.diff_url.trim();
    edit.text = message;
    edit.lang = self.lang;
    edit.project = self.project;

    debug('emit', edit);
    self.emit('data', edit);
  });
  debug('join', this.channel);

  this.client.nick('wikiedits');
  this.client.user('wikiedits', 'dont mind me');
  this.client.join(this.channel);
};
示例#22
0
文件: index.js 项目: KenanY/nwitch
/**
 * Initialize an IRC bot.
 *
 * @param {Object} config
 */
function Nwitch(config) {
  if (!(this instanceof Nwitch)) return new Nwitch(config);

  this.config = config;

  var stream = net.connect({
    port: config.irc.port,
    host: config.irc.address
  });

  this.client = irc(stream);
  this.client.pass(config.account.password);
  this.client.nick(config.account.username);
  this.client.user(config.account.username, config.account.username);
  this.client.join('#' + config.account.channel);

  this.client.use(ping());

  if (config.debug) {
    this.client.on('message', function(evt) {
      logger.info('<' + evt.from + '> ' + evt.message);
    });
  }
}
示例#23
0
文件: stem-irc.js 项目: goldbuick/src
import net from 'net';
import irc from 'slate-irc';

let stream = net.connect({
    port: 6667,
    host: 'irc.freenode.org'
});

let client = irc(stream);

client.nick('proxygoldbuick');
client.user('proxygoldbuick', 'Proxy for Goldbuick');

client.join('#exocortex');
client.names('#exocortex', (err, names) => {
    console.log(names);
});
示例#24
0
function Connection(client, network, options) {
  // Ensure required options are present
  var requiredOptions = ['host', 'port', 'nick', 'username', 'realname'];
  var missingOptions = [];

  requiredOptions.forEach(function (option) {
    if (!options[option]) {
      missingOptions.push(option);
    }
  });

  if (missingOptions.length > 0) {
    throw new Error('Missing required option(s): ' + missingOptions.join(', '));
  }

  this.client = client;
  this.network = network;

  this.stream = net.connect({
    host: options.host,
    port: options.port
  });

  this.irc = irc(this.stream);

  if (options.pass) {
    this.irc.pass(options.pass);
  }

  this.irc.nick(options.nick);
  this.irc.user(options.username, options.realname);

  this.irc.on('data', function (event) {
    this.client.browserWindow.webContents.send('message:received', {
      buffer: {
        parent: this.network,
        name: 'server'
      },
      message: {
        timestamp: Date.now(),
        message: event.string
      }
    });
  }.bind(this));

  this.irc.on('message', function (event) {
    var buffer = (utils.isChannel(event.to)) ? event.to : event.from;

    // Ensure the buffer has been created
    this.client.createBuffer({
      parent: this.network,
      name: buffer
    });

    // Relay the message to the renderer
    this.client.browserWindow.webContents.send('message:received', {
      buffer: {
        parent: this.network,
        name: (utils.isChannel(event.to)) ? event.to : event.from
      },
      message: {
        timestamp: Date.now(),
        from: event.from,
        message: event.message,
        to: event.to
      }
    });
  }.bind(this));
}
示例#25
0
文件: client.js 项目: catrinho/shout
Client.prototype.connect = function(args) {
	var client = this;
	var server = {
		host: args.host || "irc.freenode.org",
		port: args.port || (args.tls ? 6697 : 6667),
		name: args.name || "",
		rejectUnauthorized: false
	};

	var stream = args.tls ? tls.connect(server) : net.connect(server);
	stream.on("error", function(e) {
		console.log("Client#connect():\n" + e);
		stream.end();
		var msg = new Msg({
			type: Msg.Type.ERROR,
			text: "Connection error."
		});
		client.emit("msg", {
			msg: msg
		});
	});

	var nick = args.nick || "shout-user";
	var username = args.username || nick;
	var realname = args.realname || "Shout User";

	var irc = slate(stream);

	if (args.password) {
		irc.pass(args.password);
	}

	irc.me = nick;
	irc.nick(nick);
	irc.user(username, realname);

	var network = new Network({
		host: server.host,
		name: server.name,
		irc: irc
	});

	client.networks.push(network);
	client.emit("network", {
		network: network
	});

	events.forEach(function(plugin) {
		var path = "./plugins/irc-events/" + plugin;
		require(path).apply(client, [
			irc,
			network
		]);
	});

	irc.once("welcome", function() {
		var delay = 1000;
		var commands = args.commands;
		if (Array.isArray(commands)) {
			commands.forEach(function(cmd) {
				setTimeout(function() {
					client.input({
						target: network.channels[0].id,
						text: cmd
					});
				}, delay);
				delay += 1000;
			});
		}
		setTimeout(function() {
			irc.write("PING " + network.host);
		}, delay);
	});

	irc.once("pong", function() {
		var join = (args.join || "");
		if (join) {
			join = join.replace(/\,/g, " ").split(/\s+/g);
			irc.join(join);
		}
	});
};
示例#26
0
文件: Client.js 项目: karen-irc/karen
    connect(args) {
        const config = ConfigDriver.getConfig();
        const server = {
            name: args.name || '',
            host: args.host || 'irc.freenode.org',
            port: args.port || (args.tls ? 6697 : 6667),
            rejectUnauthorized: false
        };

        if (config.bind) {
            server.localAddress = config.bind;
            if (args.tls) {
                const socket = net.connect(server);
                server.socket = socket;
            }
        }

        const stream = args.tls ? tls.connect(server) : net.connect(server);

        stream.on('error', (e) => {
            console.log('Client#connect():\n' + e);
            stream.end();
            const msg = new Message(null, {
                type: MessageType.ERROR,
                text: 'Connection error.'
            });
            this.emit('msg', {
                msg: msg
            });
        });

        const nick = args.nick || 'karen-user';
        const username = args.username || nick.replace(/[^a-zA-Z0-9]/g, '');
        const realname = args.realname || 'karen User';

        const irc = slate(stream);

        if (args.password) {
            irc.pass(args.password);
        }

        irc.me = nick;
        irc.nick(nick);
        irc.user(username, realname);

        const network = new Network({
            name: server.name,
            host: server.host,
            port: server.port,
            tls: !!args.tls,
            password: args.password,
            username: username,
            realname: realname,
            commands: args.commands,
            allowUserImage: args.allowUserImage
        });

        network.irc = irc;

        this.networks.push(network);
        this.emit('network', {
            network: network
        });

        eventPluginList.forEach((plugin) => {
            /*eslint-disable prefer-reflect */
            plugin.apply(this, [
                irc,
                network
            ]);
            /*eslint-enable */
        });

        irc.once('welcome', () => {
            let delay = 1000;
            const commands = args.commands;
            if (Array.isArray(commands)) {
                commands.forEach((cmd) => {
                    setTimeout(() => {
                        this.input({
                            target: network.channels[0].id,
                            text: cmd
                        });
                    }, delay);
                    delay += 1000;
                });
            }
            setTimeout(() => {
                irc.write('PING ' + network.host);
            }, delay);
        });

        irc.once('pong', () => {
            let join = (args.join || '');
            if (join) {
                join = join.replace(/,/g, ' ').split(/\s+/g);
                irc.join(join);
            }
        });
    }
示例#27
0
文件: client.js 项目: henriAbel/shout
Client.prototype.connect = function(args) {
	var config = Helper.getConfig();
	var client = this;
	var server = {
		name: args.name || "",
		host: args.host || "irc.freenode.org",
		port: args.port || (args.tls ? 6697 : 6667),
		rejectUnauthorized: false
	};

	// Validate port
	if (isNaN(server.port) || server.port < 0 || server.port >= 65536) {
		console.log("Client#connect(): port range error");
		var msg = new Msg({
			type: Msg.Type.ERROR,
			text: util.format("Port should be >= 0 and < 65536, but was %s", server.port)
		});
		client.emit("msg", {
			msg: msg
		});
		return;
	}

	if (config.bind) {
		server.localAddress = config.bind;
		if (args.tls) {
			var socket = net.connect(server);
			server.socket = socket;
		}
	}

	var stream = args.tls ? tls.connect(server) : net.connect(server);

	stream.on("error", function(e) {
		console.log("Client#connect():\n" + e);
		stream.end();
		var msg = new Msg({
			type: Msg.Type.ERROR,
			text: "Connection error."
		});
		client.emit("msg", {
			msg: msg
		});
	});

	var nick = args.nick || "shout-user";
	var username = args.username || nick.replace(/[^a-zA-Z0-9]/g, "");
	var realname = args.realname || "Shout User";

	var irc = slate(stream);
	identd.hook(stream, username);

	if (args.password) {
		irc.pass(args.password);
	}

	irc.me = nick;
	irc.nick(nick);
	irc.user(username, realname);

	var network = new Network({
		name: server.name,
		host: server.host,
		port: server.port,
		tls: !!args.tls,
		password: args.password,
		username: username,
		realname: realname,
		commands: args.commands
	});

	network.irc = irc;

	client.networks.push(network);
	client.emit("network", {
		network: network
	});

	events.forEach(function(plugin) {
		var path = "./plugins/irc-events/" + plugin;
		require(path).apply(client, [
			irc,
			network
		]);
	});

	irc.once("welcome", function() {
		var delay = 1000;
		var commands = args.commands;
		if (Array.isArray(commands)) {
			commands.forEach(function(cmd) {
				setTimeout(function() {
					client.input({
						target: network.channels[0].id,
						text: cmd
					});
				}, delay);
				delay += 1000;
			});
		}
		setTimeout(function() {
			irc.write("PING " + network.host);
			pollWhoIs();
		}, delay);
	});

	irc.once("pong", function() {
		var join = (args.join || "");
		if (join) {
			join = join.replace(/\,/g, " ").split(/\s+/g);
			irc.join(join);
		}
	});

	var pollWhoIs = function() {
		for (var i = 0; i < network.channels.length; i++) {
			var e = network.channels[i];
			if (e.name.startsWith('#')) {
					irc.write('WHO ' + e.name)
			}
		}
	}

	setInterval(function() {
		pollWhoIs();
	}, 10000);
};
示例#28
0
文件: wtwr.js 项目: WatchtowerBot/bot
var irc = require('slate-irc');
var net = require('net');

var conf = require('./config');
var plugin = require('./plugins');

// Connect to the IRC server
var stream = net.connect({
    port: conf.get("port"),
    host: conf.get("server")
});

var client = irc(stream);

// Pass configuration
client.nick(conf.get("nickname"));
client.user(conf.get("username"), conf.get("realname"));
client.pass(conf.get("password"));

// Join channels
var channels = conf.get("channels");
for (var i = 0; i < channels.length; i++) {
    client.join(channels[i]);
}

// client.use(plugin.debug());
// client.use(plugin.couchLog("http://localhost:5984"));