示例#1
0
        public override List <IRCResponse> GetResponse(BotMessage message)
        {
            List <IRCResponse> responses = new List <IRCResponse>();

            List <string> feeds = new List <string>(FeedMap.Keys);

            foreach (string feed in feeds)
            {
                if (FeedMap[feed].LastCheck > DateTime.Now.AddMinutes(-10))
                {
                    continue;
                }

                FeedMap[feed].LastCheck = DateTime.Now;

                URL.WebPage feedPage;
                try
                {
                    feedPage = URL.FetchURL(FeedMap[feed].URL);
                }
                catch (System.Exception ex)
                {
                    Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                    continue;
                }

                XmlDocument feedDoc = new XmlDocument();

                feedDoc.LoadXml(feedPage.Page);

                XmlNode firstItem = feedDoc.SelectSingleNode(@"/rss/channel/item");

                DateTime newestDate = new DateTime();
                DateTime.TryParse(firstItem.SelectSingleNode("pubDate").FirstChild.Value, out newestDate);

                FeedMap[feed].LatestTitle = firstItem.SelectSingleNode("title").FirstChild.Value;
                FeedMap[feed].LatestLink  = URL.Shorten(ChannelList.EvadeChannelLinkBlock(message, firstItem.SelectSingleNode("link").FirstChild.Value));

                if (newestDate > FeedMap[feed].LastUpdate)
                {
                    FeedMap[feed].LastUpdate = newestDate;

                    responses.Add(new IRCResponse(ResponseType.Say, "New " + feed + "! Title: " + FeedMap[feed].LatestTitle + " (" + FeedMap[feed].LatestLink + ")", message.ReplyTo));
                }
            }

            if (responses.Count == 0)
            {
                return(null);
            }

            return(responses);
        }
示例#2
0
        public override List <IRCResponse> GetResponse(BotMessage message)
        {
            if (Regex.IsMatch(message.Command, "^(m(odd)?t(unes)?)$", RegexOptions.IgnoreCase))
            {
                Mpc mpc = new Mpc();

                var addresses = System.Net.Dns.GetHostAddresses("moddington.net");
                if (addresses.Length > 0)
                {
                    mpc.Connection = new MpcConnection(new IPEndPoint(addresses[0], 6600));

                    var    song    = mpc.CurrentSong();
                    string songMsg = "";
                    if (song.HasTitle || song.HasArtist)
                    {
                        if (song.HasTitle)
                        {
                            songMsg += song.Title;
                        }
                        else
                        {
                            songMsg += "<Unknown Title>";
                        }
                        if (song.HasArtist)
                        {
                            songMsg += " - " + song.Artist;
                        }
                        else
                        {
                            songMsg += "<Unknown Artist>";
                        }
                    }
                    else
                    {
                        songMsg += song.File;
                    }

                    var      status  = mpc.Status();
                    TimeSpan elapsed = TimeSpan.FromSeconds(status.TimeElapsed);
                    TimeSpan total   = TimeSpan.FromSeconds(status.TimeTotal);
                    string   timeMsg = (elapsed.Hours > 0 ? elapsed.Hours + ":" : "") + elapsed.Minutes + ":" + elapsed.Seconds.ToString("D2") + "/" +
                                       (total.Hours > 0 ? total.Hours + ":" : "") + total.Minutes + ":" + total.Seconds.ToString("D2");

                    string output = "Playing: " + songMsg +
                                    " [" + timeMsg + "] - Listen here: " + ChannelList.EvadeChannelLinkBlock(message, "http://moddington.net:8000/moddtunes.ogg");

                    return(new List <IRCResponse>()
                    {
                        new IRCResponse(ResponseType.Say, output, message.ReplyTo)
                    });
                }
                else
                {
                    return(new List <IRCResponse>()
                    {
                        new IRCResponse(ResponseType.Say, "Moddington's internet radio seems to be down", message.ReplyTo)
                    });
                }
            }

            return(null);
        }
示例#3
0
        public override List <IRCResponse> GetResponse(BotMessage message)
        {
            //foreach (KeyValuePair<string, Feed> feed in FeedMap)
            //{


            URL.WebPage feedPage;
            try
            {
                feedPage = URL.FetchURL(FeedMap["Homestuck"].URL);
            }
            catch (System.Exception ex)
            {
                Logger.Write(ex.Message, Settings.Instance.ErrorFile);
                return(null);
            }

            XmlDocument feedDoc = new XmlDocument();

            feedDoc.LoadXml(feedPage.Page);

            XmlNode firstItem = feedDoc.SelectSingleNode(@"/rss/channel/item");

            DateTime newestDate = new DateTime();

            DateTime.TryParse(firstItem.SelectSingleNode("pubDate").FirstChild.Value, out newestDate);

            if (newestDate > FeedMap["Homestuck"].LastUpdate)
            {
                XmlNode oldestNew = feedDoc.SelectSingleNode(@"/rss/channel/item");

                int numUpdates = 0;

                foreach (XmlNode item in feedDoc.SelectNodes(@"/rss/channel/item"))
                {
                    DateTime itemDate = new DateTime();
                    DateTime.TryParse(item.SelectSingleNode("pubDate").FirstChild.Value, out itemDate);

                    if (itemDate > FeedMap["Homestuck"].LastUpdate)
                    {
                        oldestNew = item;
                        numUpdates++;
                    }
                    else
                    {
                        break;
                    }
                }

                FeedMap["Homestuck"] = new Feed(FeedMap["Homestuck"].URL, newestDate);

                string itemTitle = oldestNew.SelectSingleNode("title").FirstChild.Value;
                string itemLink  = ChannelList.EvadeChannelLinkBlock(message, oldestNew.SelectSingleNode("link").FirstChild.Value);

                return(new List <IRCResponse>()
                {
                    new IRCResponse(ResponseType.Say, "Homestuck has updated, " + numUpdates + " new pages! New ones start here: " + itemTitle + " (" + itemLink + ")", message.ReplyTo)
                });
            }
            //}
            return(null);
        }