Exemplo n.º 1
0
        protected override void OnPrivateMessage(IrcContext context)
        {
            if (context.IsBangCommand)
            {
                if (context.Parameters.Last().Equals("!url", StringComparison.InvariantCultureIgnoreCase) && Authorized(context))
                {
                    Enabled = !Enabled;
                    context.Privmsg(context.Parameters[0], string.Format("UrlBot: [\x02{0}\x02]", Enabled ? "Active" : "Inactive"));
                }

                if (context.Parameters.Last().Equals("!geno", StringComparison.InvariantCultureIgnoreCase))
                {
                    var rec     = _repo.Random <Record>();
                    var tinyUrl = GetTinyUrl(rec.Url);
                    context.Privmsg(context.Parameters[0], string.Format("Here's your random link - {0}", tinyUrl));
                }
            }
            else if (Enabled)
            {
                var match = Regex.Match(context.Parameters.Last(), REGEX_URL);
                if (match.Success)
                {
                    var title = GetTitle(match.Value);

                    if (title != null)
                    {
                        var tinyUrl = GetTinyUrl(match.Value);
                        context.Privmsg(context.Parameters[0], string.Format("[\x02Title\x02] {0} ({1})", title, tinyUrl));
                        Log(title, match, context);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void PostDemTweets()
        {
            var feedUrl = string.IsNullOrEmpty(_since_id) ?
                          GENO_INITIAL_FEED :
                          string.Format(GENO_FEED, _since_id);

            XDocument feed    = XDocument.Load(feedUrl);
            var       updates = feed.Root.Elements("status").Select(e => new
            {
                Id    = e.Element("id").Value,
                Text  = e.Element("text").Value,
                Stamp = DateTime.ParseExact(e.Element("created_at").Value, "ddd MMM dd HH:mm:ss +ffff yyyy", CultureInfo.CurrentCulture).ToLocalTime()
            }).OrderBy(x => x.Id);

            if (updates.Any())
            {
                foreach (var tweet in updates)
                {
                    _context.Privmsg(_channel, tweet.Text);
                    Thread.Sleep(2000);
                }

                _since_id = updates.Last().Id;
            }
        }