Ejemplo n.º 1
0
        public override void OnDataReceived(object sender, IRCReadEventArgs e)
        {
            if (Activate)
            {
                if (e.Message.Contains("PRIVMSG") &&
                        Regex.IsMatch(e.Message, @".+http(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\0'\/\\\+&%\$#_]*)?$", RegexOptions.IgnoreCase | RegexOptions.Multiline))
                {
                    Connection C = (Connection)sender;
                    WebClient client = new WebClient();
                    List<string> URLs = new List<string>();
                    List<string> shortened = new List<string>();

                    foreach (var match in new Regex(@"http(s?)://\S+").Matches(e.Message)) URLs.Add(match.ToString());
                    try
                    {
                        foreach (string URL in URLs) shortened.Add(client.DownloadString("http://tinyurl.com/api-create.php?url=" + URL));
                    }
                    catch (WebException)
                    {
                        C.WriteLine("PRIVMSG " + e.Message.Split(' ')[2] + " :There was an error accessing tinyurl's API.");
                        return;
                    }
                    C.WriteLine("PRIVMSG " + e.Message.Split(' ')[2] + " :·· " + string.Join(", ", shortened));
                }
            }
        }
Ejemplo n.º 2
0
        public override void OnDataReceived(object sender, IRCReadEventArgs e)
        {
            if (Activate)
            {
                if (e.Message.Contains("PRIVMSG") &&
                    !Regex.IsMatch(e.Message, @".+https?://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?") &&
                    Regex.IsMatch(e.Message, @".+http(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\0'\/\\\+&amp;%\$#_]*)?$", RegexOptions.IgnoreCase | RegexOptions.Multiline))
                {
                    Connection C = (Connection)sender;
                    WebClient client = new WebClient();
                    string source = e.Message;
                    List<string> URLs = new List<string>();

                    foreach (var match in new Regex(@"http(s?)://\S+").Matches(source)) URLs.Add(match.ToString());
                    foreach (string URL in URLs)
                    {
                        try
                        {
                            source = client.DownloadString(URL);
                        }
                        catch (WebException)
                        {
                            C.WriteLine("PRIVMSG " + e.Message.Split(' ')[2] + " :There was an error fetching website title.");
                            return;
                        }
                        Match titleMatch = Regex.Match(source, @"\<title\b[^>]*\>\s*(?<Title>[\s\S]*?)\</title\>", RegexOptions.IgnoreCase);
                        string title = titleMatch.Groups["Title"].Value;
                        C.WriteLine("PRIVMSG " + e.Message.Split(' ')[2] + " :·· " + title);
                    }
                }
            }
        }
Ejemplo n.º 3
0
 public override void OnDataReceived(object sender, IRCReadEventArgs e)
 {
     #           if DEBUG