private static void Restrict(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("Please specify restrict action", parameters.SourceChannel); return; } List <string> pm = new List <string>(parameters.Parameters.Trim().Split(' ')); switch (pm[0]) { case "add": if (pm.Count == 1) { IRC.DeliverMessage("This command requires channel name to be specified", parameters.SourceChannel.Name); break; } string channel_name = pm[1]; if (!Core.ValidFile(channel_name) || !channel_name.StartsWith("#")) { IRC.DeliverMessage(messages.Localize("InvalidName", parameters.SourceChannel.Language, new List <string> { channel_name }), parameters.SourceChannel); return; } if (Configuration.RestrictedChannels.ContainsKey(channel_name)) { IRC.DeliverMessage("Channel " + channel_name + " is already restricted to join", parameters.SourceChannel.Name); return; } int restriction_level = Security.Roles["root"].Level; if (pm.Count >= 3) { if (Security.Roles.ContainsKey(pm[2])) { restriction_level = Security.Roles[pm[2]].Level; } else { IRC.DeliverMessage("Unknown user role: " + pm[2], parameters.SourceChannel.Name); return; } } foreach (KeyValuePair <string, Instance> instance in wmib.Instance.Instances) { foreach (Channel channel in instance.Value.ChannelList) { if (channel.Name == channel_name) { instance.Value.Network.Transfer("PART " + channel_name); break; } } } lock (Configuration.Channels) { Configuration.Channels.RemoveAll(c => c.Name == channel_name); } lock (Configuration.RestrictedChannels) { Configuration.RestrictedChannels[channel_name] = restriction_level; } Configuration.Save(); IRC.DeliverMessage("I will not join " + channel_name + " anymore", parameters.SourceChannel.Name); break; default: IRC.DeliverMessage("Unknown restrict action: " + pm[0], parameters.SourceChannel.Name); break; } }
/// <summary> /// Join channel /// </summary> public static void AddChannel(CommandParams parameters) { if (!String.IsNullOrEmpty(parameters.Parameters)) { while (!IRC.FinishedJoining) { Syslog.Log("Postponing request to join " + parameters.Parameters + " because bot is still loading", true); Thread.Sleep(2000); } List <string> pm = new List <string>(parameters.Parameters.Trim().Split(' ')); if (pm.Count > 2 || pm.Count == 0) { IRC.DeliverMessage("Invalid number of parameters, please provide up to 2 parameters (name, password)", parameters.SourceChannel); return; } string channel_name = pm[0]; string password = null; if (pm.Count > 1) { password = pm[1]; } if (!Core.ValidFile(channel_name) || !channel_name.StartsWith("#")) { IRC.DeliverMessage(messages.Localize("InvalidName", parameters.SourceChannel.Language, new List <string> { channel_name }), parameters.SourceChannel); return; } lock (Configuration.Channels) { foreach (Channel cu in Configuration.Channels) { if (channel_name == cu.Name) { IRC.DeliverMessage(messages.Localize("ChannelIn", parameters.SourceChannel.Language), parameters.SourceChannel); return; } } } bool existing = Channel.ConfigExists(channel_name); Channel channel = new Channel(channel_name) { Password = password }; lock (Configuration.Channels) { Configuration.Channels.Add(channel); } IRC.DeliverMessage("Attempting to join " + channel_name + " using " + channel.PrimaryInstance.Nick, parameters.SourceChannel.Name); Configuration.Save(); Syslog.DebugLog("Sending join " + channel_name); channel.PrimaryInstance.Network.Join(channel_name, password); Channel Chan = Core.GetChannel(channel_name); if (!existing) { Chan.SystemUsers.AddUser("admin", Security.EscapeUser(parameters.User.Nick) + "!.*@" + Security.EscapeUser(parameters.User.Host)); } if (Chan.Extension_GetConfig("generic.founder") == null) { Chan.Extension_SetConfig("generic.founder", parameters.User.ToString()); Chan.Extension_SetConfig("generic.owner", parameters.User.ToString()); } else { Chan.Extension_SetConfig("generic.owner", parameters.User.ToString()); } Chan.Extension_SetConfig("generic.joindate", DateTime.Now.ToString()); Chan.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("InvalidName", parameters.SourceChannel.Language), parameters.SourceChannel); return; }