public bool TryReact( Network network, string message )
        {
            var m = Regex.Match(message);
            if (!m.Success) return false;

            Reaction( network, m );
            return true;
        }
        public bool TryReact( Network network, string message )
        {
            var m = Regex.Match(message);
            if (!m.Success) return false;

            if ( MultipleChannels )
            foreach ( var channel in m.Groups["channels"].Value.Split( new[]{','} ).Where( ch=>network.Channels.Contains(ch) ) )
            {
                network.Logs.Channel(channel).Log(m,OutputFormat);
            }
            else // !MultipleChannels
            {
                var channel = m.Groups["channel"].Value;
                if ( !network.Channels.Contains(channel) ) return false;
                network.Logs.Channel(channel).Log(m,OutputFormat);
            }

            return true;
        }
示例#3
0
        static void Work()
        {
            try {
                Console.CancelKeyPress += (sender,args) => {
                    args.Cancel = true;
                };
            } catch ( NullReferenceException ) {
                // generated by *nix when run in the background?
            }

            var procstart = DateTime.Now;
            Debug.WriteLine( "=== Process start at {0} ===", procstart );

            var logpattern = Paths.LogsDirectory+"{network}-{channel}-{year}-{month}-{day}.log";
            #if DEBUG
            var channels = new[] { "#sparta" };
            var whitelistChannels = new[] { "#sparta" };
            #else
            var channels = new[] { "#gamedev", "#graphicschat", "#graphicsdev", "#anime", "#starcraft" };
            var whitelistChannels = new[] { "#gamedev" };
            #endif
            var logs = new AllLogs() { { "irc.afternet.org", new NetworkLogs("irc.afternet.org",logpattern) } };
            var afternet = logs["irc.afternet.org"];
            foreach ( var ch in channels ) afternet.Channel(ch);
            foreach ( var ch in whitelistChannels ) afternet.Channel(ch).RequireAuth = true;
            afternet.Channel("#gamedev");

            Debug.Write( "Beginning log server..." );
            var server = new HttpLogServer();
            Debug.WriteLine( "\rLog server started.                             " );

            Debug.Write("LoggingMonkey comming online...");
            var bot = new Network( "irc.afternet.org", channels, logs );
            var bott = new Thread(bot.Work);
            bott.Start();
            Debug.WriteLine("\rLoggingMonkey online.                            ");

            Debug.Write("Getting directory list...");
            var files = Directory
                .GetFiles(Paths.LogsDirectory, "*.log", SearchOption.TopDirectoryOnly )
                .OrderBy( file => {
                    var m = Regexps.LogFilename.Match(file);
                    return new DateTime
                        ( int.Parse(m.Groups["year"].Value)
                        , int.Parse(m.Groups["month"].Value)
                        , int.Parse(m.Groups["day"].Value)
                        );
                })
                .ToArray()
                ;

            var bglogs = new AllLogs() { { "irc.afternet.org", new NetworkLogs("irc.afternet.org",logpattern) } };
            var bgafternet = bglogs["irc.afternet.org"];
            foreach ( var ch in channels ) bgafternet.Channel(ch);

            Debug.Write("Starting GC...");
            var before = GC.GetTotalMemory(false);
            var after  = GC.GetTotalMemory(true);
            Debug.WriteLine("\rFinished GC. Before: {0}  After: {1}  Saved: {2}"
                , Pretty.FormatMemory(before)
                , Pretty.FormatMemory(after)
                , Pretty.FormatMemory(before-after)
                );

            server.SetLogs(logs);
            Debug.WriteLine("Logs now being served.");

            for (;;) {
                //Console.Write("> ");
                string command;
                try {
                    command = Console.ReadLine();
                    if ( command == null ) for (;;) {}
                } catch ( NullReferenceException ) {
                    for (;;);
                }
                var split = command.Split(new[]{' '});

                switch ( split[0] ) {
                case "help":
                    Console.WriteLine("\t  Command                     Description");
                    Console.WriteLine("\thelp                        displays this command list");
                    Console.WriteLine("\tquit                        Quits");
                    break;
                case "quit":
                    return;
                default:
                    Console.WriteLine( "No such command: {0}", split[0] );
                    break;
                }
            }
        }