Exemple #1
0
        public Bot()
        {
            #region " Header "
            Console.WriteLine("Abbot: The petite IRC Bot  - v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString() + " - [http://abbot.berlios.de]");
            Console.WriteLine("(c) 2005 The Abbot Project");
            Console.WriteLine("===============================================================================");
            Console.WriteLine("Abbot: The petite IRC Bot comes with absolutely no warranty.");
            Console.WriteLine("This is free software, and you are welcome to redistribute it under certain");
            Console.WriteLine("conditions. See the enclosed copy of the General Public License for details.");
            Console.WriteLine("===============================================================================");
            #endregion

            #region " Load Configuration "
            configuration = new XmlDocument();
            try {
                configuration.Load("Configuration.xml");
            } catch (Exception e) {
                Console.WriteLine("# Cannot load the configuration file: " + e.Message);
                Environment.Exit(-1);
                return;
            }

            foreach (XmlElement e in configuration.GetElementsByTagName("Network")) {
                Network n = new Network();
                networks.Add(n);
                n.Name = e.Attributes["Name"].Value;
                n.Nickname = e.Attributes["Nickname"].Value;
                n.Realname = e.Attributes["Realname"].Value;
                n.Username = e.Attributes["Username"].Value;
                if (e.HasAttribute("Password")) {
                    n.UsePassword = true;
                    n.Password = e.Attributes["Password"].Value;
                }
                else
                    n.UsePassword = false;
                n.Port = int.Parse(e.Attributes["Port"].Value);
                n.SendDelay = int.Parse(e.Attributes["SendDelay"].Value);

                foreach (XmlElement f in e.GetElementsByTagName("Server"))
                    n.Servers.Add(f.Attributes["Address"].Value);

                foreach (XmlElement f in e.GetElementsByTagName("Channel"))
                    n.Channels.Add(f.Attributes["Name"].Value);

                n.OnBan += new Irc.BanEventHandler(OnBanHandler);
                n.OnChannelAction += new Irc.ActionEventHandler(OnChannelActionHandler);
                n.OnChannelActiveSynced += new Irc.IrcEventHandler(OnChannelActiveSyncedHandler);
                n.OnChannelMessage += new Irc.IrcEventHandler(OnChannelMessageHandler);
                n.OnChannelModeChange += new Irc.IrcEventHandler(OnChannelModeChangeHandler);
                n.OnChannelNotice += new Irc.IrcEventHandler(OnChannelNoticeHandler);
                n.OnChannelPassiveSynced += new Irc.IrcEventHandler(OnChannelPassiveSyncedHandler);
                n.OnConnected += new EventHandler(OnConnectedHandler);
                n.OnConnecting += new EventHandler(OnConnectingHandler);
                n.OnConnectionError += new EventHandler(OnConnectionErrorHandler);
                n.OnCtcpReply += new Irc.IrcEventHandler(OnCtcpReplyHandler);
                n.OnCtcpRequest += new Irc.IrcEventHandler(OnCtcpRequestHandler);
                n.OnDehalfop += new Irc.DehalfopEventHandler(OnDehalfopHandler);
                n.OnDeop += new Irc.DeopEventHandler(OnDeopHandler);
                n.OnDevoice += new Irc.DevoiceEventHandler(OnDevoiceHandler);
                n.OnDisconnected += new EventHandler(OnDisconnectedHandler);
                n.OnDisconnecting += new EventHandler(OnDisconnectingHandler);
                n.OnError += new Irc.ErrorEventHandler(OnErrorHandler);
                n.OnErrorMessage += new Irc.IrcEventHandler(OnErrorMessageHandler);
                n.OnHalfop += new Irc.HalfopEventHandler(OnHalfopHandler);
                n.OnInvite += new Irc.InviteEventHandler(OnInviteHandler);
                n.OnJoin += new Irc.JoinEventHandler(OnJoinHandler);
                n.OnKick += new Irc.KickEventHandler(OnKickHandler);
                n.OnModeChange += new Irc.IrcEventHandler(OnModeChangeHandler);
                n.OnMotd += new Irc.MotdEventHandler(OnMotdHandler);
                n.OnNames += new Irc.NamesEventHandler(OnNamesHandler);
                n.OnNickChange += new Irc.NickChangeEventHandler(OnNickChangeHandler);
                n.OnOp += new Irc.OpEventHandler(OnOpHandler);
                n.OnPart += new Irc.PartEventHandler(OnPartHandler);
                n.OnPing += new Irc.PingEventHandler(OnPingHandler);
                n.OnQueryAction += new Irc.ActionEventHandler(OnQueryActionHandler);
                n.OnQueryMessage += new Irc.IrcEventHandler(OnQueryMessageHandler);
                n.OnQueryNotice += new Irc.IrcEventHandler(OnQueryNoticeHandler);
                n.OnQuit += new Irc.QuitEventHandler(OnQuitHandler);
                n.OnRawMessage += new Irc.IrcEventHandler(OnRawMessageHandler);
                n.OnReadLine += new Irc.ReadLineEventHandler(OnReadLineHandler);
                n.OnRegistered += new EventHandler(OnRegisteredHandler);
                n.OnTopic += new Irc.TopicEventHandler(OnTopicHandler);
                n.OnTopicChange += new Irc.TopicChangeEventHandler(OnTopicChangeHandler);
                n.OnUnban += new Irc.UnbanEventHandler(OnUnbanHandler);
                n.OnUserModeChange += new Irc.IrcEventHandler(OnUserModeChangeHandler);
                n.OnVoice += new Irc.VoiceEventHandler(OnVoiceHandler);
                n.OnWho += new Irc.WhoEventHandler(OnWhoHandler);
                n.OnWriteLine += new Irc.WriteLineEventHandler(OnWriteLineHandler);
            }
            #endregion

            #region " Load Plugins "
            object[] o ={ this };
            foreach (System.IO.FileInfo f in new System.IO.DirectoryInfo("Plugins").GetFiles())
                if (f.Extension == ".dll") {
                    Console.WriteLine("Loading Plugins from Assembly '" + f.Name + "' ...");
                    Assembly a = System.Reflection.Assembly.LoadFile(f.FullName);
                    foreach (Type t in a.GetTypes())
                        if (t.BaseType == typeof(Plugin)) {
                            Console.WriteLine("\t\t- " + t.Name);
                            Plugin p = (Plugin)Activator.CreateInstance(t, o);
                            plugins.Add(p);
                        }
                }
            Console.WriteLine("===============================================================================");
            #endregion
        }
 void Bot_OnRawMessage(Network network, Irc.IrcEventArgs e)
 {
     Console.WriteLine(e.Data.RawMessage);
 }
 static void bot_OnRawMessage(Network sender, IrcEventArgs e)
 {
     Console.WriteLine(e.Data.Nick + ": " + e.Data.Message);
 }