function ChannelsPlugin(bot) {
	var self = this;
	self.name = "channels";
	self.help = "Channel management and autojoining";
	self.depend = ["cmd"];
	
	self.autojoins = [];
	self.autojoinTime = 5000;

	self.events = {
		"invite": function(channel, from) {
			bot.join(channel);
		},

		"cmd#join": function(nick, to, args) {
			for (var i = 1; i < args.length; i++)
				bot.join(args[i]);
		},

		"cmd#part": function(nick, to, args) {
			if (args.length > 1) {
				for (var i = 1; i < args.length; i++)
					bot.part(args[i]);
			}
			else
				bot.part(to);
		},

		"cmd#cycle": function(nick, to, args) {
			if (args.length > 1) {
				for (var i = 1; i < args.length; i++) {
					bot.part(args[i]);
					bot.join(args[i]);
				}
			}
			else {
				bot.part(to);
				bot.join(to);
			}
		},

		"cmd#autojoin": function(nick, to, args) {
			var chan = args[1] || to;
			var i = self.autojoins.indexOf(chan);
			if (i != -1) {
				self.autojoins.splice(i, 1);
				bot.say(to, "not autojoining " + chan);
			}
			else {
				self.autojoins.push(chan);
				bot.say(to, "autojoining " + chan);
				if (!(chan in bot.chans))
					bot.join(chan);
			}
		},

		"part": function(channel, nick) {
			if ((nick == bot.nick) && (self.autojoins.indexOf(channel) != -1))
				setTimeout(function() {
					bot.join(channel);
				}, self.autojoinTime);
		},

		"kick": function(channel, nick) {
			if ((nick == bot.nick) && (self.autojoins.indexOf(channel) != -1))
				setTimeout(function() {
					bot.join(channel);
				}, self.autojoinTime);
		}
	}
}

module.exports = ChannelsPlugin;

@@ -139,19 +139,27 @@
 = %5B%22cmd%22
+, %22auth%22
 %5D;%0A
-
 %09%0A%09self.
@@ -202,16 +202,423 @@
  5000;%0A%0A
+%09self.load = function(data) %7B%0A%09%09if (data !== undefined) %7B%0A%09%09%09self.autojoins = data.autojoins;%0A%09%09%09self.autojoinTime = data.autojoinTime;%0A%09%09%7D%0A%09%7D;%0A%0A%09self.unload = function() %7B%0A%09%09var data = %7B%7D;%0A%09%09data.autojoins = self.autojoins;%0A%09%09data.autojoinTime = self.autojoinTime;%0A%09%09return data;%0A%09%7D;%0A%0A%09self.enable = function() %7B%0A%09%09for (var i = 0; i %3C self.autojoins.length; i++) %7B%0A%09%09%09bot.join(self.autojoins%5Bi%5D);%0A%09%09%7D%0A%09%7D;%0A%0A
 %09self.ev
@@ -1214,24 +1214,50 @@
 d#autojoin%22:
+ bot.plugins.auth.proxy(6,
  function(ni
@@ -1575,27 +1575,166 @@
 chan);%0A%09%09%09%7D%0A
-
 %09%09%7D
+),%0A%0A%09%09%22cmd#autojoins%22: bot.plugins.auth.proxy(6, function(nick, to, args) %7B%0A%09%09%09bot.say(to, %22autojoins: %22 + self.autojoins.join(%22, %22));%0A%09%09%7D)
 ,%0A%0A%09%09%22part%22:

Make autojoin channels persistent, require auth level to change