Exemplo n.º 1
0
 public Trigger(TimeCounter cnt, string rep, int tim = 0, string list = null, string countpath = null)
 {
     this.counter = cnt;
     this.secs = 0;
     if (rep.StartsWith("list:"))
     {
         repList = new List<string>();
         string path = rep.Substring(5);
         try
         {
             this.rand = new Random();
             using (StreamReader sr = new StreamReader(path))
             {
                 string word;
                 while ((word = sr.ReadLine()) != null)
                 {
                     repList.Add(word);
                 }
             }
             this.count = repList.Count;
             if (File.Exists(countpath))
             {
                 this.countpath = countpath;
                 this.countlist = new Hashtable();
                 using (StreamReader sr = new StreamReader(this.countpath))
                 {
                     string line;
                     while ((line = sr.ReadLine()) != null)
                     {
                         string[] entry = line.Split('=');
                         this.countlist.Add(entry[0], Int32.Parse(entry[1]));
                     }
                 }
             }
             this.isList = true;
         }
         catch
         {
             Console.WriteLine("File {0} is not acceptable as list file.", path);
         }
     }
     else
     {
         this.reply = rep;
         this.isList = false;
     }
     this.timer = tim;
 }
Exemplo n.º 2
0
 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();
 }