예제 #1
0
파일: IRCBot.cs 프로젝트: HaxtonFale/HuxBot
 public IRCBot(IRCConfig config, bool save)
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     StartUI();
     this.tc = new TimeCounter();
     this.saveall = save;
     this.config = config;
     if (saveall)
         this.pattern = @"(https?|ftp)://[^ \n\t]+?";
     else
     {
         if (File.Exists(this.config.filterpath))
         {
             string append = null;
             this.pattern = @"https?://([a-zA-Z0-9/\.\-&:@%\?_]+?\.(png|jpe?g|gif)";
             using (StreamReader hl = new StreamReader(this.config.filterpath))
             {
                 string line;
                 while ((line = hl.ReadLine()) != null)
                 {
                     if (!line.StartsWith("&"))
                     {
                         line = Regex.Replace(line, @"\.", @"\.");
                         line = Regex.Replace(line, @"\?", @"\?");
                         this.pattern += "|" + line + @"[^ \n\t]+";
                     }
                     else
                     {
                         append += "|" + line.Substring(1);
                     }
                 }
             }
             this.pattern += ")";
             if (append != null)
                 this.pattern = "(" + this.pattern + append + ")";
         }
         else
         {
             Console.WriteLine("No custom filters found.");
             this.pattern = @"https?://[a-zA-Z0-9/\.\-&:@%\?_]+?\.(png|jpe?g|gif)";
         }
     }
     this.matcher = new Regex(this.pattern);
     try
     {
         this.IRCConnection = new TcpClient(config.server, config.port);
     }
     catch
     {
         Console.WriteLine("Connection error!");
     }
     try
     {
         this.ns = IRCConnection.GetStream();
         this.sr = new StreamReader(ns);
         this.sw = new StreamWriter(ns);
         this.SendData("USER", "HuxBot +xB Befriending.without.mercy :HuxBot");
         this.SendData("NICK", config.nick);
     }
     catch
     {
         Console.WriteLine("Communication error!");
     }
     this.LoadTriggers(config.triggerpath);
     this.sq = new SendQueue(this);
     this.rtimer = new System.Timers.Timer(250000);
     this.rtimer.Elapsed += rtimer_Elapsed;
     this.IRCWork();
 }
예제 #2
0
 static void Main(string[] args)
 {
     bool saveall = false;
     bool verbose = true;
     IRCConfig conf = new IRCConfig();
     conf.filepath = "imglist.txt";
     conf.triggerpath = "triggers.txt";
     conf.filterpath = "filters.txt";
     string confpath = "config.ini";
     conf.ReadConfig(confpath);
     for(int i=0; i<args.Length; i++)
     {
         switch (args[i])
         {
             case "-all":
                 saveall = true;
                 break;
             case "-c":
                 if (args.Length > i + 1 && File.Exists(args[i + 1]))
                 {
                     confpath = args[i + 1];
                     i++;
                 }
                 else
                     Console.WriteLine("Unable to load provided config. Searching in default location.");
                 break;
             case "-t":
                 if (args.Length > i + 1 && File.Exists(args[i + 1]))
                 {
                     conf.triggerpath = args[i + 1];
                     i++;
                 }
                 else
                     Console.WriteLine("Unable to load provided trigger list. Searching in default location.");
                 break;
             case "-s":
                 verbose = false;
                 break;
             case "-f":
                 if (args.Length > i + 1 && File.Exists(args[i + 1]))
                 {
                     conf.filterpath = args[i + 1];
                     i++;
                 }
                 else
                     Console.WriteLine("Unable to load provided filter list. Searching in default location.");
                 break;
         }
     }
     if (conf.server == null)
     {
         Console.WriteLine("Please provide the server URL:");
         conf.server = Console.ReadLine();
         using (StreamWriter sw = new StreamWriter(confpath, true))
             sw.WriteLine("server=" + conf.server);
     }
     if (conf.chan == null)
     {
         Console.WriteLine("Please provide the channel:");
         conf.chan = Console.ReadLine();
         using (StreamWriter sw = new StreamWriter(confpath, true))
             sw.WriteLine("chan=" + conf.chan);
     }
     if (conf.nick == null)
     {
         Console.WriteLine("Please provide the nickname:");
         conf.nick = Console.ReadLine();
         using (StreamWriter sw = new StreamWriter(confpath, true))
             sw.WriteLine("nick=" + conf.nick);
     }
     if (conf.nspass == null)
     {
         Console.WriteLine("Please provide the NickServ password:"******"nspass="******"Please provide the master's nickname:");
         conf.master = Console.ReadLine();
         using (StreamWriter sw = new StreamWriter(confpath, true))
             sw.WriteLine("master=" + conf.master);
     }
     conf.name = conf.nick;
     conf.port = 6667;
     IRCBot bot = new IRCBot(conf, saveall);
     if (verbose || !bot.uiRun)
     {
         Console.WriteLine("Bot quit/crashed");
         Console.ReadKey();
     }
 }