/// <summary> /// Creates a new bot instance but not connect it to IRC /// </summary> /// <param name="name">Name</param> /// <param name="port">Port</param> public Instance(string name, int port = 0) { Nick = name; Port = port; irc = new IRC(Configuration.IRC.NetworkHost, Nick, Configuration.IRC.Username, Configuration.IRC.Username, this); irc.Bouncer = Hostname; irc.BouncerPort = Port; }
/// <summary> /// Creates a new bot instance but not connect it to IRC /// </summary> /// <param name="name"></param> public Instance(string name, int port = 0) { Nick = name; Port = port; irc = new IRC(config.network, Nick, config.name, config.name, this); irc.Bouncer = Hostname; irc.BouncerPort = Port; }
/// <summary> /// Connect to network /// </summary> public static void Connect() { irc = Instances[config.username].irc; // now we load all instances lock (Instances) { foreach (Instance instance in Instances.Values) { // connect it to irc instance.Init(); } // now we need to wait for all instances to connect core.Log("Waiting for all instances to connect to irc"); bool IsOk = false; while (!IsOk) { foreach (Instance instance in Instances.Values) { if (!instance.IsWorking) { core.DebugLog("Waiting for " + instance.Nick); Thread.Sleep(1000); IsOk = false; break; } else { core.DebugLog("Connected to " + instance.Nick); IsOk = true; } } } // now we make all instances join their channels foreach (Instance instance in Instances.Values) { instance.Join(); } // wait for all instances to join their channels core.Log("Waiting for all instances to join channels"); IsOk = false; while (!IsOk) { foreach (Instance instance in Instances.Values) { if (!instance.irc.ChannelsJoined) { Thread.Sleep(100); IsOk = false; break; } IsOk = true; } } core.Log("All instances joined their channels"); } core.FinishedJoining = true; while (_Status == Status.OK) { Thread.Sleep(200); } }
/// <summary> /// Creates new queue /// </summary> /// <param name="_parent">Parent object</param> public SlowQueue(IRC _parent) { Parent = _parent; }
/// <summary> /// Creates new queue /// </summary> /// <param name="_parent">Parent object</param> public MessageQueue(IRC _parent) { Parent = _parent; }
/// <summary> /// Connect to network /// </summary> public static void Connect() { irc = Instances[Configuration.IRC.NickName].irc; // now we load all instances foreach (Instance instance in Instances.Values) { // connect it to irc instance.Init(); } // now we need to wait for all instances to connect Syslog.Log("Waiting for all instances to connect to irc"); bool IsOk = false; while (!IsOk) { foreach (Instance instance in Instances.Values) { if (!instance.IsWorking) { Syslog.DebugLog("Waiting for " + instance.Nick, 2); Thread.Sleep(1000); IsOk = false; break; } else { Syslog.DebugLog("Connected to " + instance.Nick, 6); IsOk = true; } } } // wait for all instances to join their channels Syslog.Log("Waiting for all instances to join channels"); IsOk = false; while (!IsOk) { foreach (Instance instance in Instances.Values) { if (!instance.irc.ChannelsJoined) { Thread.Sleep(100); IsOk = false; break; } IsOk = true; } } Syslog.Log("All instances joined their channels"); Core.FinishedJoining = true; }
private static void Info(CommandParams parameters) { IRC.DeliverMessage(Configuration.WebPages.WebpageURL + Configuration.Paths.DumpDir + "/" + HttpUtility.UrlEncode(parameters.SourceChannel.Name) + ".htm", parameters.SourceChannel); }
private static void TrustedList(CommandParams parameters) { IRC.DeliverMessage(messages.Localize("TrustedUserList", parameters.SourceChannel.Language) + parameters.SourceChannel.SystemUsers.ListAll(), parameters.SourceChannel); }
private static void Restart(CommandParams parameters) { IRC.DeliverMessage("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name, Configuration.System.DebugChan, libirc.Defs.Priority.High); Syslog.Log("System is shutting down, requested by " + parameters.User.Nick + " from " + parameters.SourceChannel.Name); Core.Kill(); }
private static void TrafficOn(CommandParams parameters) { Configuration.Network.Logging = true; IRC.DeliverMessage("Logging started", parameters.SourceChannel); }
private static void Configure(CommandParams parameters) { if (string.IsNullOrEmpty(parameters.Parameters)) { return; } if (parameters.Parameters.Contains("=") && !parameters.Parameters.EndsWith("=")) { string name = parameters.Parameters.Substring(0, parameters.Parameters.IndexOf("=")); string value = parameters.Parameters.Substring(parameters.Parameters.IndexOf("=") + 1); bool _temp_a; switch (name) { case "ignore-unknown": if (bool.TryParse(value, out _temp_a)) { parameters.SourceChannel.IgnoreUnknown = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> { value, name }), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> { name, value }), parameters.SourceChannel); return; case "respond-wait": int _temp_b; if (int.TryParse(value, out _temp_b)) { if (_temp_b > 1 && _temp_b < 364000) { parameters.SourceChannel.RespondWait = _temp_b; IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> { value, name }), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); return; } } IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> { name, value }), parameters.SourceChannel); return; case "respond-message": if (bool.TryParse(value, out _temp_a)) { parameters.SourceChannel.RespondMessage = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> { value, name }), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> { name, value }), parameters.SourceChannel); return; case "suppress-warnings": if (bool.TryParse(value, out _temp_a)) { parameters.SourceChannel.SuppressWarnings = _temp_a; IRC.DeliverMessage(messages.Localize("configuresave", parameters.SourceChannel.Language, new List <string> { value, name }), parameters.SourceChannel); parameters.SourceChannel.SaveConfig(); return; } IRC.DeliverMessage(messages.Localize("configure-va", parameters.SourceChannel.Language, new List <string> { name, value }), parameters.SourceChannel); return; } bool exist = false; foreach (Module curr in ExtensionHandler.ExtensionList) { try { if (curr.IsWorking && curr.Hook_SetConfig(parameters.SourceChannel, parameters.User, name, value)) { exist = true; } } catch (Exception fail) { Syslog.Log("Error on Hook_SetConfig module " + curr.Name); Core.HandleException(fail, curr.Name); } } if (!parameters.SourceChannel.SuppressWarnings && !exist) { IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel); } return; } if (!parameters.Parameters.Contains(" ")) { switch (parameters.Parameters) { case "ignore-unknown": IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> { parameters.Parameters, parameters.SourceChannel.IgnoreUnknown.ToString() }), parameters.SourceChannel); return; case "respond-message": IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> { parameters.Parameters, parameters.SourceChannel.RespondMessage.ToString() }), parameters.SourceChannel); return; case "suppress-warnings": IRC.DeliverMessage(messages.Localize("Responses-Conf", parameters.SourceChannel.Language, new List <string> { parameters.Parameters, parameters.SourceChannel.SuppressWarnings.ToString() }), parameters.SourceChannel); return; } bool exist = false; foreach (Module curr in ExtensionHandler.ExtensionList) { try { if (curr.IsWorking && curr.Hook_GetConfig(parameters.SourceChannel, parameters.User, parameters.Parameters)) { exist = true; } } catch (Exception fail) { Syslog.Log("Error on Hook_GetConfig module " + curr.Name); Core.HandleException(fail); } } if (exist) { return; } } if (!parameters.SourceChannel.SuppressWarnings) { IRC.DeliverMessage(messages.Localize("configure-wrong", parameters.SourceChannel.Language), parameters.SourceChannel); } }
private static void VerbosityUp(CommandParams parameters) { Configuration.System.SelectedVerbosity++; IRC.DeliverMessage("Verbosity: " + Configuration.System.SelectedVerbosity, parameters.SourceChannel, libirc.Defs.Priority.High); }
protected override void __evt_PRIVMSG(NetworkPRIVMSGEventArgs args) { if (args.ChannelName == null) { // private message // store which instance this message was from so that we can send it using same instance lock (Instance.TargetBuffer) { if (!Instance.TargetBuffer.ContainsKey(args.SourceInfo.Nick)) { Instance.TargetBuffer.Add(args.SourceInfo.Nick, this.instance); } else { Instance.TargetBuffer[args.SourceInfo.Nick] = this.instance; } } string modules = ""; bool respond = !Commands.Trusted(args.Message, args.SourceInfo.Nick, args.SourceInfo.Host); if (!respond) { modules += "@trusted "; } foreach (Module module in ExtensionHandler.ExtensionList) { if (module.IsWorking) { try { if (module.Hook_OnPrivateFromUser(args.Message, args.SourceInfo)) { respond = false; modules += module.Name + " "; } } catch (Exception fail) { Core.HandleException(fail); } } } if (respond) { IRC.DeliverMessage("Hi, I am robot, this command was not understood." + " Please bear in mind that every message you send" + " to me will be logged for debuging purposes. See" + " documentation at http://meta.wikimedia.org/wiki" + "/WM-Bot for explanation of commands", args.SourceInfo, libirc.Defs.Priority.Low); Syslog.Log("Ignoring private message: (" + args.SourceInfo.Nick + ") " + args.Message, false); } else { modules = Core.Trim(modules); Syslog.Log("Private message: (handled by " + modules + " from " + args.SourceInfo.Nick + ") " + args.Message, false); } } else { if (args.ChannelName == Configuration.System.DebugChan && this.instance != Instance.PrimaryInstance) { return; } if (args.IsAct) { Core.GetAction(args.Message, args.ChannelName, args.SourceInfo.Host, args.SourceInfo.Nick); return; } Core.GetMessage(args.ChannelName, args.SourceInfo.Nick, args.SourceInfo.Host, args.Message); } }