Exemplo n.º 1
0
 private static MatchResult Match(Regex regex, Message message)
 {
     if (!(message is TextMessage))
     {
         return new MatchResult(false);
     }
     var match = regex.Matches(((TextMessage) message).Text);
     return match.Cast<Match>().Any(m => m.Success)
         ? new MatchResult(true, match)
         : new MatchResult(false);
 }
Exemplo n.º 2
0
        public bool Call(Message message)
        {
            var lm = message as TopicMessage;
            if (lm != null)
            {
                _callback(Response.Create(_robot, lm));
                return true;
            }

            return false;
        }
Exemplo n.º 3
0
        public bool Call(Message message)
        {
            var cam = message as CatchAllMessage;
            if (cam != null)
            {
                _callback(Response.Create(_robot, cam));
                return true;
            }

            var tm = message as TextMessage;
            if (tm != null)
            {
                var catchAll = new CatchAllMessage(tm.User, tm.Text);
                _callback(Response.Create(_robot, catchAll));
                return true;
            }

            var em = message as EnterMessage;
            if (em != null)
            {
                var catchAll = new CatchAllMessage(em.User, string.Format("{0} joined {1}", em.User.Name, em.User.Room));
                _callback(Response.Create(_robot, catchAll));
                return true;
            }

            var lm = message as LeaveMessage;
            if (lm != null)
            {
                var catchAll = new CatchAllMessage(lm.User, string.Format("{0} left {1}", lm.User.Name, lm.User.Room));
                _callback(Response.Create(_robot, catchAll));
                return true;
            }

            var topm = message as TopicMessage;
            if (topm != null)
            {
                var catchAll = new CatchAllMessage(topm.User, topm.Topic);
                _callback(Response.Create(_robot, catchAll));
                return true;
            }

            if (message != null)
            {
                var catchAll = new CatchAllMessage(message.User, "");
                _callback(Response.Create(_robot, catchAll));
                return true;
            }

            return false;
        }
Exemplo n.º 4
0
        public bool Call(Message message)
        {
            var lm = message as LeaveMessage;
            if (lm != null && _leaveCallback != null)
            {
                _leaveCallback(Response.Create(_robot, lm));
                return true;
            }

            var em = message as EnterMessage;
            if (em != null && _enterCallback != null)
            {
                _enterCallback(Response.Create(_robot, em));
                return true;
            }

            return false;
        }
Exemplo n.º 5
0
        public bool Call(Message message)
        {
            if (!(message is TextMessage))
            {
                return false;
            }
            var match = Match(_regex, message);
            if (match.IsMatch)
            {
                // TODO: Log
                //@robot.logger.debug \
                //  "Message '#{message}' matched regex /#{inspect @regex}/" if @regex

                _callback(Response.Create(_robot, message as TextMessage, match));
                return true;
            }
            return false;
        }
Exemplo n.º 6
0
 public virtual void Receive(Message message)
 {
     Robot.Receive(message);
 }