Skip to content

Instantly share code, notes, and snippets.

@czbaker
Last active August 29, 2015 14:13
Show Gist options
  • Save czbaker/f0c8dcaa2c4f46ffeac7 to your computer and use it in GitHub Desktop.
Save czbaker/f0c8dcaa2c4f46ffeac7 to your computer and use it in GitHub Desktop.
// Event Handlers
Template.channelAdmin.events({
'click #join': function() {
channel = "#" + Meteor.user().username;
Meteor.call("joinchannel", channel, function(err, res) {
if (err) {
throw new Meteor.Error("join-error", "Unable to join channel.");
} else {
console.log("Join Channel Called? (" + channel + ")")
}
});
},
'click #part': function() {
channel = "#" + Meteor.user().username;
Meteor.call("partchannel", channel, function(err, res) {
if (err) {
throw new Meteor.Error("part-error", "Unable to part channel.");
} else {
console.log("Part Channel Called? (" + channel + ")")
}
});
}
});
// Set client options
var chanList = [];
var theChannels = IRCChannels.find();
theChannels.forEach(function(doc) {
chanList.push(doc.channel);
});
var options = {
server: 'irc.freenode.net',
port: 6667,
nick: 'wasdbot',
password: false,
realname: "WASDBot",
username: "WASDBot",
debug: false,
stripColors: true,
channels: chanList
};
// Try to connect to the server, attach server instance to Meteor for control.
ircClient = new IRC(options);
ircClient.connect();
Meteor.methods({
// Join a Channel
joinchannel: function(channel) {
// Check channel presence
inChannel = IRCChannels.find({"channel": channel}, {"_id": 1}).count();
if (inChannel == 0) {
ircClient.join(channel);
chans = IRCChannels.find().count();
console.log("Current channels: " + chans);
}
},
partchannel: function(channel) {
// Check channel presence
var inChannel = IRCChannels.find({"channel": channel}, {"_id": 1}).count();
if (inChannel == 1) {
ircClient.part(channel);
var chans = IRCChannels.find().count();
console.log("Current channels: " + chans);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment