예제 #1
0
        public static Change String2Change(string text)
        {
            // get a page
            if (!text.Contains(variables.color + "14[["))
            {
                core.DebugLog("Parser error #1", 6);
                return null;
            }
            Change change = new Change("", "", "");

            if (text.Contains(variables.color + "4 M"))
            {
                change.Minor = true;
            }

            if (text.Contains(variables.color + "4 B"))
            {
                change.Bot = true;
            }

            if (text.Contains(variables.color + "4 N"))
            {
                change.New = true;
            }

            change.Page = text.Substring(text.IndexOf(variables.color + "14[[") + 5);
            change.Page = change.Page.Substring(3);
            if (!change.Page.Contains(variables.color + "14]]"))
            {
                core.DebugLog("Parser error #2", 6);
                return null;
            }

            change.Page = change.Page.Substring(0, change.Page.IndexOf(variables.color + "14"));

            text = text.Substring(text.IndexOf(variables.color + "14]]") + 5);

            if (text.Contains("?oldid="))
            {
                change.oldid = text.Substring(text.IndexOf("?oldid=") + 7);

                if (!change.oldid.Contains("&") && !change.oldid.Contains(" "))
                {
                    core.DebugLog("Parser error #4", 6);
                    return null;
                }

                if (change.oldid.Contains(" "))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf(" "));
                }

                if (change.oldid.Contains("&"))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf("&"));
                }
            }

            if (text.Contains("?diff="))
            {
                change.diff = text.Substring(text.IndexOf("?diff=") + 6);

                if (!change.diff.Contains("&"))
                {
                    core.DebugLog("Parser error #4", 6);
                    return null;
                }
                change.diff = change.diff.Substring(0, change.diff.IndexOf("&"));
            }

            text = text.Substring(text.IndexOf("?diff=") + 6);

            if (!text.Contains(variables.color + "03"))
            {
                core.DebugLog("Parser error #5", 6);
                return null;
            }

            change.User = text.Substring(text.IndexOf(variables.color + "03") + 3);

            if (!change.User.Contains(variables.color + " " + variables.color + "5*"))
            {
                core.DebugLog("Parser error #6", 6);
                return null;
            }

            change.User = change.User.Substring(0, change.User.IndexOf(variables.color + " " + variables.color + "5*"));

            if (!text.Contains(variables.color + "5"))
            {
                core.DebugLog("Parser error #7", 6);
                return null;
            }

            text = text.Substring(text.IndexOf(variables.color + "5"));

            if (text.Contains("("))
            {
                change.Size = text.Substring(text.IndexOf("(") + 1);

                if (!change.Size.Contains(")"))
                {
                    core.DebugLog("Parser error #10", 6);
                    return null;
                }

                change.Size = change.Size.Substring(0, change.Size.IndexOf(")"));
            }

            if (!text.Contains(variables.color + "10"))
            {
                core.DebugLog("Parser error #14", 6);
                return null;
            }

            change.Description = text.Substring(text.IndexOf(variables.color + "10") + 3);

            change.Special = change.Page.StartsWith("Special:");

            return change;
        }
예제 #2
0
 public override void Load()
 {
     try
     {
         RecentChanges.channels = new List <string>();
         if (!File.Exists(RecentChanges.channeldata))
         {
             File.WriteAllText(RecentChanges.channeldata, "#mediawiki.wikipedia");
         }
         string message = "";
         try
         {
             string[] list = System.IO.File.ReadAllLines(RecentChanges.channeldata);
             Log("Loading feed", false);
             lock (RecentChanges.channels)
             {
                 foreach (string chan in list)
                 {
                     RecentChanges.channels.Add(chan);
                 }
             }
             RecentChanges.Connect();
             Log("Loaded feed", false);
             while (true)
             {
                 try
                 {
                     if (RecentChanges.RD == null)
                     {
                         return;
                     }
                     while (!RecentChanges.RD.EndOfStream)
                     {
                         message = RecentChanges.RD.ReadLine();
                         if (!message.Contains(" PRIVMSG "))
                         {
                             continue;
                         }
                         Change edit = String2Change(message);
                         //Match Edit = RecentChanges.line.Match(message);
                         if (edit != null)
                         {
                             string _channel = message.Substring(message.IndexOf("PRIVMSG"));
                             _channel = _channel.Substring(_channel.IndexOf("#"));
                             _channel = _channel.Substring(0, _channel.IndexOf(" "));
                             List <RecentChanges> R = new List <RecentChanges>();
                             lock (RecentChanges.rc)
                             {
                                 R.AddRange(RecentChanges.rc);
                             }
                             foreach (RecentChanges curr in R)
                             {
                                 if (curr != null)
                                 {
                                     if (edit.Special && !GetConfig(curr.channel, "RC.Special", false))
                                     {
                                         continue;
                                     }
                                     if (GetConfig(curr.channel, "RC.Enabled", false))
                                     {
                                         lock (curr.pages)
                                         {
                                             foreach (RecentChanges.IWatch w in curr.pages)
                                             {
                                                 if (w != null)
                                                 {
                                                     if (w.Channel == _channel || w.Channel == "all")
                                                     {
                                                         if (edit.Page == w.Page)
                                                         {
                                                             if (edit.Size != null)
                                                             {
                                                                 edit.Summary = "[" + edit.Size + "] " + edit.Summary;
                                                             }
                                                             if (w.URL == null)
                                                             {
                                                                 DebugLog("NULL pointer on idata 1", 2);
                                                             }
                                                             core.irc._SlowQueue.DeliverMessage(
                                                                 Format(w.URL.name, w.URL.url, edit.Page, edit.User, edit.diff, edit.Summary, curr.channel, edit.Bot, edit.New, edit.Minor), curr.channel.Name, IRC.priority.low);
                                                         }
                                                         else
                                                         if (w.Page.EndsWith("*"))
                                                         {
                                                             if (edit.Page.StartsWith(w.Page.Replace("*", "")))
                                                             {
                                                                 if (w.URL == null)
                                                                 {
                                                                     DebugLog("NULL pointer on idata 2", 2);
                                                                 }
                                                                 core.irc._SlowQueue.DeliverMessage(
                                                                     Format(w.URL.name, w.URL.url, edit.Page, edit.User, edit.diff, edit.Summary, curr.channel, edit.Bot, edit.New, edit.Minor), curr.channel.Name, IRC.priority.low);
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         else
                         {
                             DebugLog("Error on: " + message);
                         }
                         Thread.Sleep(10);
                     }
                     Thread.Sleep(100);
                 }
                 catch (ThreadAbortException)
                 {
                     return;
                 }
                 catch (IOException)
                 {
                     RecentChanges.Connect();
                 }
                 catch (Exception fail)
                 {
                     core.LastText = message;
                     handleException(fail);
                 }
             }
         }
         catch (ThreadAbortException)
         {
             return;
         }
         catch (Exception fail)
         {
             handleException(fail);
             // abort
         }
     }
     catch (ThreadAbortException)
     {
         return;
     }
     catch (Exception fail)
     {
         handleException(fail);
     }
 }
예제 #3
0
        public static Change String2Change(string text)
        {
            // get a page
            if (!text.Contains(Variables.ColorChar + "14[["))
            {
                ptrModule.DebugLog("Parser error #1", 6);
                return null;
            }
            Change change = new Change("", "", "");

            if (text.Contains(Variables.ColorChar + "4 "))
            {
                string flags = text.Substring(text.IndexOf(Variables.ColorChar + "4 ") + 3);
                if (flags.Contains(Variables.ColorChar))
                {
                    flags = flags.Substring(0, flags.IndexOf(Variables.ColorChar));
                }
                if (flags.Contains("N"))
                {
                    change.New = true;
                }

                if (flags.Contains("M"))
                {
                    change.Minor = true;
                }
                if (flags.Contains("B"))
                {
                    change.Bot = true;
                }
            }

            change.Page = text.Substring(text.IndexOf(Variables.ColorChar + "14[[") + 5);
            change.Page = change.Page.Substring(3);
            if (!change.Page.Contains(Variables.ColorChar + "14]]"))
            {
                ptrModule.DebugLog("Parser error #2", 6);
                return null;
            }

            change.Page = change.Page.Substring(0, change.Page.IndexOf(Variables.ColorChar + "14"));

            text = text.Substring(text.IndexOf(Variables.ColorChar + "14]]") + 5);

            if (text.Contains("?oldid="))
            {
                change.oldid = text.Substring(text.IndexOf("?oldid=") + 7);

                if (!change.oldid.Contains("&") && !change.oldid.Contains(" "))
                {
                    ptrModule.DebugLog("Parser error #4", 6);
                    return null;
                }

                if (change.oldid.Contains(" "))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf(" "));
                }

                if (change.oldid.Contains("&"))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf("&"));
                }
            }

            if (text.Contains("?diff="))
            {
                change.diff = text.Substring(text.IndexOf("?diff=") + 6);

                if (!change.diff.Contains("&"))
                {
                    ptrModule.DebugLog("Parser error #4", 6);
                    return null;
                }
                change.diff = change.diff.Substring(0, change.diff.IndexOf("&"));
            }

            text = text.Substring(text.IndexOf("?diff=") + 6);

            if (!text.Contains(Variables.ColorChar + "03"))
            {
                ptrModule.DebugLog("Parser error #5", 6);
                return null;
            }

            change.User = text.Substring(text.IndexOf(Variables.ColorChar + "03") + 3);

            if (!change.User.Contains(Variables.ColorChar + " " + Variables.ColorChar + "5*"))
            {
                ptrModule.DebugLog("Parser error #6", 6);
                return null;
            }

            change.User = change.User.Substring(0, change.User.IndexOf(Variables.ColorChar + " " + Variables.ColorChar + "5*"));

            if (!text.Contains(Variables.ColorChar + "5"))
            {
                ptrModule.DebugLog("Parser error #7", 6);
                return null;
            }

            text = text.Substring(text.IndexOf(Variables.ColorChar + "5"));

            if (text.Contains("("))
            {
                change.Size = text.Substring(text.IndexOf("(") + 1);

                if (!change.Size.Contains(")"))
                {
                    ptrModule.DebugLog("Parser error #10", 6);
                    return null;
                }

                change.Size = change.Size.Substring(0, change.Size.IndexOf(")"));
            }

            if (!text.Contains(Variables.ColorChar + "10"))
            {
                ptrModule.DebugLog("Parser error #14", 6);
                return null;
            }

            change.Summary = text.Substring(text.IndexOf(Variables.ColorChar + "10") + 3);
            if (change.Summary.EndsWith(Variables.ColorChar))
            {
                change.Summary = change.Summary.Substring(0, change.Summary.Length - 1);
            }

            change.Special = change.Page.StartsWith("Special:");

            return change;
        }
예제 #4
0
        public static Change String2Change(string text)
        {
            // get a page
            if (!text.Contains(variables.color + "14[["))
            {
                core.DebugLog("Parser error #1", 6);
                return(null);
            }
            Change change = new Change("", "", "");

            if (text.Contains(variables.color + "4 "))
            {
                string flags = text.Substring(text.IndexOf(variables.color + "4 ") + 3);
                if (flags.Contains(variables.color))
                {
                    flags = flags.Substring(0, flags.IndexOf(variables.color));
                }
                if (flags.Contains("N"))
                {
                    change.New = true;
                }

                if (flags.Contains("M"))
                {
                    change.Minor = true;
                }
                if (flags.Contains("B"))
                {
                    change.Bot = true;
                }
            }

            change.Page = text.Substring(text.IndexOf(variables.color + "14[[") + 5);
            change.Page = change.Page.Substring(3);
            if (!change.Page.Contains(variables.color + "14]]"))
            {
                core.DebugLog("Parser error #2", 6);
                return(null);
            }

            change.Page = change.Page.Substring(0, change.Page.IndexOf(variables.color + "14"));

            text = text.Substring(text.IndexOf(variables.color + "14]]") + 5);

            if (text.Contains("?oldid="))
            {
                change.oldid = text.Substring(text.IndexOf("?oldid=") + 7);

                if (!change.oldid.Contains("&") && !change.oldid.Contains(" "))
                {
                    core.DebugLog("Parser error #4", 6);
                    return(null);
                }

                if (change.oldid.Contains(" "))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf(" "));
                }

                if (change.oldid.Contains("&"))
                {
                    change.oldid = change.oldid.Substring(0, change.oldid.IndexOf("&"));
                }
            }

            if (text.Contains("?diff="))
            {
                change.diff = text.Substring(text.IndexOf("?diff=") + 6);

                if (!change.diff.Contains("&"))
                {
                    core.DebugLog("Parser error #4", 6);
                    return(null);
                }
                change.diff = change.diff.Substring(0, change.diff.IndexOf("&"));
            }


            text = text.Substring(text.IndexOf("?diff=") + 6);

            if (!text.Contains(variables.color + "03"))
            {
                core.DebugLog("Parser error #5", 6);
                return(null);
            }

            change.User = text.Substring(text.IndexOf(variables.color + "03") + 3);

            if (!change.User.Contains(variables.color + " " + variables.color + "5*"))
            {
                core.DebugLog("Parser error #6", 6);
                return(null);
            }

            change.User = change.User.Substring(0, change.User.IndexOf(variables.color + " " + variables.color + "5*"));

            if (!text.Contains(variables.color + "5"))
            {
                core.DebugLog("Parser error #7", 6);
                return(null);
            }

            text = text.Substring(text.IndexOf(variables.color + "5"));

            if (text.Contains("("))
            {
                change.Size = text.Substring(text.IndexOf("(") + 1);

                if (!change.Size.Contains(")"))
                {
                    core.DebugLog("Parser error #10", 6);
                    return(null);
                }

                change.Size = change.Size.Substring(0, change.Size.IndexOf(")"));
            }

            if (!text.Contains(variables.color + "10"))
            {
                core.DebugLog("Parser error #14", 6);
                return(null);
            }

            change.Summary = text.Substring(text.IndexOf(variables.color + "10") + 3);
            if (change.Summary.EndsWith(variables.color))
            {
                change.Summary = change.Summary.Substring(0, change.Summary.Length - 1);
            }

            change.Special = change.Page.StartsWith("Special:");

            return(change);
        }