Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix channel join regression and fix possibly joining parted channels #411

Merged
merged 1 commit into from Jun 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 11 additions & 30 deletions src/client.js
Expand Up @@ -137,6 +137,16 @@ Client.prototype.connect = function(args) {

var nick = args.nick || "lounge-user";
var webirc = null;
var channels = [];

if (args.join) {
var join = args.join.replace(/\,/g, " ").split(/\s+/g);
join.forEach(function(chan) {
channels.push(new Chan({
name: chan
}));
});
Copy link
Member

@astorije astorije Jun 19, 2016

Choose a reason for hiding this comment

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

What about:

channels = args.join.replace(/\,/g, " ").split(/\s+/g).map(function(chan) {
    return new Chan({
        name: chan,
    });
});

or, if you don't want that long first line:

var join = args.join.replace(/\,/g, " ").split(/\s+/g);
channels = join.map(...)

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, got ruled out in priv by @xPaw, who plans to use the channels variable in a further PR and cannot blindly overwrite it.

}

var network = new Network({
name: args.name || "",
Expand All @@ -149,6 +159,7 @@ Client.prototype.connect = function(args) {
commands: args.commands,
ip: args.ip,
hostname: args.hostname,
channels: channels,
});
network.setNick(nick);

Expand Down Expand Up @@ -221,36 +232,6 @@ Client.prototype.connect = function(args) {
webirc: webirc,
});

network.irc.on("registered", function() {
if (network.irc.network.cap.enabled.length > 0) {
network.channels[0].pushMessage(client, new Msg({
text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", ")
}));
}

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;
});
}

var join = (args.join || "");
if (join) {
setTimeout(function() {
join = join.split(/\s+/);
network.irc.join(join[0], join[1]);
}, delay);
}
});

events.forEach(function(plugin) {
var path = "./plugins/irc-events/" + plugin;
require(path).apply(client, [
Expand Down
29 changes: 29 additions & 0 deletions src/plugins/irc-events/connection.js
Expand Up @@ -10,6 +10,35 @@ module.exports = function(irc, network) {
text: "Network created, connecting to " + network.host + ":" + network.port + "..."
}));

irc.on("registered", function() {
if (network.irc.network.cap.enabled.length > 0) {
network.channels[0].pushMessage(client, new Msg({
text: "Enabled capabilities: " + network.irc.network.cap.enabled.join(", ")
}));
}

var delay = 1000;
var commands = network.commands;
if (Array.isArray(commands)) {
commands.forEach(function(cmd) {
setTimeout(function() {
client.input({
target: network.channels[0].id,
text: cmd
});
}, delay);
delay += 1000;
Copy link
Member

Choose a reason for hiding this comment

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

This could be simplified a bit;

const delay = 1000;
commands.forEach((text, idx) => {
    setTimeout(() => client.input({
          target: network.channels[0].id,
          text,
     }), delay * ++idx);
});

Copy link
Member Author

Choose a reason for hiding this comment

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

Joins have to run after commands, so that won't work. I also didn't touch this code, only moved it to another file.

Copy link
Member

Choose a reason for hiding this comment

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

To be honest, I'm not sure the delay * ++idx statement is something I would call "simplified"...

Copy link
Member

Choose a reason for hiding this comment

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

Agreed with @astorije, plus apart from changing the functions to arrow functions (thus breaking older versions), it doesn't actually change much. idx*1000 would do the same, as forEach already provide the index and thus doesn't need to be incremented.

});
}

network.channels.forEach(function(chan) {
setTimeout(function() {
network.irc.join(chan.name);
}, delay);
delay += 100;
});
});

irc.on("socket connected", function() {
network.channels[0].pushMessage(client, new Msg({
text: "Connected to the network."
Expand Down