Beispiel #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);
                    }
                }
            }
        }
Beispiel #2
0
 protected override void OnPart(IrcContext context)
 {
     if(context.InvolvesBotClient)
     {
         _timer.Stop();
     }
 }
Beispiel #3
0
 protected override void OnJoin(IrcContext context)
 {
     if(context.InvolvesBotClient)
     {
         _context = context;
         _channel = _context.Parameters.First();
         _timer.Start();
     }
 }
Beispiel #4
0
        private void HandleMessage(Message msg)
        {
            Console.WriteLine(msg.Raw);
            var context = new IrcContext(msg, _conn, _info);

            if (context.GetReplyCode() == ServerReplyCode.ISupport)
            {
                var validParms = msg.Parameters.Skip(1).Take(msg.Parameters.Length - 2);
                _info.Append(validParms);
            }

            _listeners.ForEach(l =>
            {
                l.IncomingMessage(context);
            });
        }
Beispiel #5
0
        private void HandleMessage(Message msg)
        {
            Console.WriteLine(msg.Raw);
            var context = new IrcContext(msg, _conn, _info);

            if(context.GetReplyCode() == ServerReplyCode.ISupport)
            {
                var validParms = msg.Parameters.Skip(1).Take(msg.Parameters.Length - 2);
                _info.Append(validParms);
            }

            _listeners.ForEach(l =>
            {
                l.IncomingMessage(context);
            });
        }
Beispiel #6
0
 protected override void OnMode(IrcContext context)
 {
     context.Names(_channel);
 }
Beispiel #7
0
 private void Log(string title, Match match, IrcContext context)
 {
     var record = new Record
     {
         Title = title,
         Url = match.Value,
         Domain = match.Groups["domain"].Value,
         User = context.Nickname,
         Channel = context.Parameters[0],
         Timestamp = DateTime.Now
     };
     _repo.Add(record);
     _repo.CommitChanges();
 }
Beispiel #8
0
 private bool Authorized(IrcContext context)
 {
     var ops = _names.Where(n => n.StartsWith("@"));
     return ops.Any(o => o.Substring(1).Equals(context.Nickname, StringComparison.InvariantCultureIgnoreCase));
 }
Beispiel #9
0
        protected override void OnServerMessage(IrcContext context)
        {
            var code = context.GetReplyCode();

            if(code == ServerReplyCode.EndOfMessageOfTheDay)
            {
                context.Join(_channel);
            }
            else if(code == ServerReplyCode.NameReply)
            {
                _nameBuffer.AddRange(context.Parameters.Last().Split(' '));
            }
            else if(code == ServerReplyCode.EndOfNames)
            {
                _names = _nameBuffer.ToArray();
                _nameBuffer.Clear();
            }
        }