public static GetChannel ( string name ) : |
||
name | string | Name |
Результат |
protected override void __evt_JOIN(NetworkChannelEventArgs args) { if (args.ChannelName == Configuration.System.DebugChan && this.instance != Instance.PrimaryInstance) { return; } Channel channel = Core.GetChannel(args.ChannelName); if (channel != null) { foreach (Module module in ExtensionHandler.ExtensionList) { try { if (module.IsWorking) { module.Hook_Join(channel, args.SourceInfo); } } catch (Exception fail) { Syslog.Log("MODULE: exception at Hook_Join in " + module.Name, true); Core.HandleException(fail); } } } }
private static void ChannelOverview(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { IRC.DeliverMessage("You need to provide exactly 1 parameter", parameters.SourceChannel); return; } string channel_name = parameters.Parameters.Trim(); Channel channel = Core.GetChannel(channel_name); if (channel == null) { IRC.DeliverMessage("Unknown channel: " + channel_name, parameters.SourceChannel); return; } string founder = channel.Extension_GetConfig("generic.owner"); if (founder != null) { founder += " (original founder: " + channel.Extension_GetConfig("generic.founder", "N/A") + ")"; } else { founder = channel.Extension_GetConfig("generic.founder"); } if (founder == null) { founder = "N/A"; } IRC.DeliverMessage("Channel " + channel.Name + " was joined " + channel.Extension_GetConfig("generic.joindate", "unknown time") + ", requested by " + founder, parameters.SourceChannel); }
protected override void __evt_PART(NetworkChannelDataEventArgs args) { if (args.ChannelName == Configuration.System.DebugChan && this.instance != Instance.PrimaryInstance) { return; } Channel channel = Core.GetChannel(args.ChannelName); if (channel != null) { foreach (Module module in ExtensionHandler.ExtensionList) { if (!module.IsWorking) { continue; } try { module.Hook_Part(channel, args.SourceInfo); } catch (Exception fail) { Core.HandleException(fail); } } } }
protected override void __evt_KICK(NetworkKickEventArgs args) { if (args.ChannelName == Configuration.System.DebugChan && this.instance != Instance.PrimaryInstance) { return; } Channel channel = Core.GetChannel(args.ChannelName); if (channel == null) { return; } SystemHooks.IrcKick(channel, args.SourceInfo, args.Target); if (this.Nickname.ToLower() == args.Target.ToLower()) { Syslog.Log("I was kicked from " + args.ChannelName + " by " + args.SourceInfo.Nick + " with kick message: " + args.Message); lock (Configuration.Channels) { if (Configuration.Channels.Contains(channel)) { Configuration.Channels.Remove(channel); } } Configuration.Save(); } }
private static void TrustDel(CommandParams parameters) { Channel channel = parameters.SourceChannel; string[] rights_info = parameters.Parameters.Split(' '); if (rights_info[0] == null) { IRC.DeliverMessage(messages.Localize("InvalidUser", parameters.SourceChannel.Language), parameters.SourceChannel); return; } if (rights_info.Length > 1) { if (channel.SystemUsers.IsApproved(parameters.User, "root")) { channel = Core.GetChannel(rights_info[1]); if (channel == null) { IRC.DeliverMessage("I don't know this channel: " + rights_info[1], parameters.SourceChannel); return; } } else { IRC.DeliverMessage("Sorry, only root users can manage permissions for other channels.", parameters.SourceChannel); return; } } channel.SystemUsers.DeleteUser(parameters.SourceChannel.SystemUsers.GetUser(parameters.User), rights_info[0], parameters.SourceChannel); }
private static void dm(string text, string target, libirc.Defs.Priority priority = libirc.Defs.Priority.Normal, bool is_act = false) { // get a target instance if (target.StartsWith("#")) { // it's a channel Channel ch = Core.GetChannel(target); if (ch == null) { Syslog.Log("Not sending message to unknown channel: " + target); return; } if (!ch.PrimaryInstance.IsConnected) { Syslog.Log("Not sending message using disconnected instance: " + ch.PrimaryInstance.Nick + " target: " + target + " message: " + text); return; } if (!ch.Suppress) { Self(text, ch); if (!is_act) { ch.PrimaryInstance.Network.Message(text, target, priority); } else { ch.PrimaryInstance.Network.Act(text, target, priority); } } } else { lock (Instance.TargetBuffer) { if (Instance.TargetBuffer.ContainsKey(target)) { if (is_act) { Instance.TargetBuffer[target].Network.Act(text, target, priority); } else { Instance.TargetBuffer[target].Network.Message(text, target, priority); } return; } } if (!is_act) { Instance.PrimaryInstance.Network.Message(text, target, priority); } else { Instance.PrimaryInstance.Network.Act(text, target, priority); } } }
protected override void __evt_FinishChannelParseUser(NetworkChannelDataEventArgs args) { Channel channel = Core.GetChannel(args.ChannelName); Syslog.DebugLog("Finished parsing of user list for channel: " + args.ChannelName); if (channel != null) { channel.HasFreshUserList = true; } }
/// <summary> /// Return number of channels that infobot share db with /// </summary> /// <returns></returns> public int InitializeShares() { foreach (string x in SharedChans) { Channel channel = Core.GetChannel(x.Trim()); if (channel != null && !SharedLinkedChan.Contains(channel)) { SharedLinkedChan.Add(channel); } } return(0); }
private static void TrustedList(CommandParams parameters) { Channel channel = parameters.SourceChannel; if (!String.IsNullOrEmpty(parameters.Parameters)) { channel = Core.GetChannel(parameters.Parameters.Trim()); if (channel == null) { IRC.DeliverMessage("I don't know this channel: " + parameters.Parameters, parameters.SourceChannel); return; } } IRC.DeliverMessage(messages.Localize("TrustedUserList", parameters.SourceChannel.Language) + channel.SystemUsers.ListAll(), parameters.SourceChannel); }
public static bool Trusted(string message, string user, string host) { try { if (message.StartsWith(Configuration.System.CommandPrefix + "trusted ")) { Channel ch = Core.GetChannel(message.Substring("xtrusted ".Length)); if (ch != null) { IRC.DeliverMessage(messages.Localize("TrustedUserList", ch.Language) + ch.SystemUsers.ListAll(), user); return(true); } IRC.DeliverMessage("There is no such a channel I know of", user); return(true); } } catch (Exception fail) { Core.HandleException(fail); } return(false); }
public override void Load() { try { // TODO: Install CA certificate used by wikitech to // Mono. ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => true; pRequestsChannel = Core.GetChannel(RequestChannel); if (pRequestsChannel == null) { Log("CRITICAL: the bot isn't in " + RequestChannel + " unloading requests", true); return; } PendingRequests = new Thread(Run) { Name = "Pending queries thread for requests extension" }; PendingRequests.Start(); Thread.Sleep(60000); while (this.IsWorking) { if (GetConfig(pRequestsChannel, "Requests.Enabled", false) && displayWaiting(false)) { Thread.Sleep(800000); } else { Thread.Sleep(20000); } } } catch (Exception fail) { HandleException(fail); } }
private static void Part(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { return; } string channel = parameters.Parameters.Trim(); if (!string.IsNullOrEmpty(channel)) { Channel _Channel = Core.GetChannel(channel); if (_Channel == null) { IRC.DeliverMessage(messages.Localize("UnknownChan", parameters.SourceChannel.Language), parameters.SourceChannel, libirc.Defs.Priority.Low); return; } PartChannel(_Channel, parameters.User.Nick, parameters.User.Host, Configuration.System.CommandPrefix + "part", parameters.SourceChannel.Name); return; } IRC.DeliverMessage(messages.Localize("Responses-PartFail", parameters.SourceChannel.Language), parameters.SourceChannel, libirc.Defs.Priority.Low); }
private static void Instance(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters) || !parameters.Parameters.Contains(" ")) { IRC.DeliverMessage("This command needs 2 parameters", parameters.SourceChannel); return; } string channel = parameters.Parameters.Substring(parameters.Parameters.IndexOf(" ") + 1); string instance = parameters.Parameters.Substring(0, parameters.Parameters.IndexOf(" ")); Channel ch = Core.GetChannel(channel); if (ch == null) { IRC.DeliverMessage("This channel I never heard of :'(", parameters.SourceChannel); return; } if (!wmib.Instance.Instances.ContainsKey(instance)) { IRC.DeliverMessage("This instance I never heard of :'(", parameters.SourceChannel); return; } Instance _instance = wmib.Instance.Instances[instance]; if (_instance == ch.PrimaryInstance) { IRC.DeliverMessage("This channel is already in this instance", parameters.SourceChannel); return; } ch.PrimaryInstance.Network.Transfer("PART " + ch.Name + " :Switching instance"); ch.PrimaryInstance = _instance; ch.PrimaryInstance.Network.Transfer("JOIN " + ch.Name); ch.DefaultInstance = ch.PrimaryInstance.Nick; ch.SaveConfig(); IRC.DeliverMessage("Changed default instance of " + channel + " to " + instance, parameters.SourceChannel); }
/// <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; }
private static void TrustAdd(CommandParams parameters) { Channel channel = parameters.SourceChannel; if (parameters.Parameters == null) { return; } string[] rights_info = parameters.Parameters.Split(' '); if (rights_info.Length < 2) { IRC.DeliverMessage(messages.Localize("Trust1", parameters.SourceChannel.Language), parameters.SourceChannel); return; } if (!Security.Roles.ContainsKey(rights_info[1])) { IRC.DeliverMessage(messages.Localize("Unknown1", parameters.SourceChannel.Language), parameters.SourceChannel); return; } int level = Security.GetLevelOfRole(rights_info[1]); // This optional hack disallow to grant roles like "root" to anyone so that this role can be granted only to users // with shell access to server and hard-inserting it to admins file. If you wanted to allow granting of root, just // change System.MaxGrantableRoleLevel to 65535, this isn't very secure though if (level > Configuration.System.MaxGrantableRoleLevel) { IRC.DeliverMessage("You can't grant this role because it's over the maximum grantable role level, sorry", parameters.SourceChannel); return; } // now we check if role that user is to grant doesn't have higher level than the role they have // if we didn't do that, users with low roles could grant admin to someone and exploit this // to grant admins to themselves if (level > parameters.SourceChannel.SystemUsers.GetLevel(parameters.User)) { IRC.DeliverMessage(messages.Localize("RoleMismatch", parameters.SourceChannel.Language), parameters.SourceChannel); return; } if (rights_info.Length > 2) { if (channel.SystemUsers.IsApproved(parameters.User, "root")) { channel = Core.GetChannel(rights_info[2]); if (channel == null) { IRC.DeliverMessage("I don't know this channel: " + rights_info[2], parameters.SourceChannel); return; } } else { IRC.DeliverMessage("Sorry, only root users can manage permissions for other channels.", parameters.SourceChannel); return; } } if (channel.SystemUsers.AddUser(rights_info[1], rights_info[0], parameters.SourceChannel)) { IRC.DeliverMessage(messages.Localize("UserSc", parameters.SourceChannel.Language) + rights_info[0], parameters.SourceChannel); return; } }