Ejemplo n.º 1
0
        private void HandleCommandEvent(ChatEventArgs e)
        {
            var r = e.Room;

            foreach (ICommand command in commands)
            {
                if (!commandStates[command])
                {
                    continue;
                }

                if (command.CommandPattern.IsMatch(e.Message.Content))
                {
                    command.ProcessMessage(e.Message, ref r);
                    return;
                }
            }

            con.ProcessMessage(e.Message, ref r);
        }
Ejemplo n.º 2
0
        private void EventCallback(EventType evt, Message m, User u, Room r, string raw)
        {
            if (evt == EventType.UserMentioned)
            {
                var n = new byte[4];
                Extensions.RNG.GetBytes(n);
                var i = BitConverter.ToUInt32(n, 0);

                if (i % 50 == 0)
                {
                    r.PostMessageLight(errors.PickRandom());
                    return;
                }

                if (Regex.IsMatch(m.Content, @"(?i)^(die|stop|shutdown)$"))
                {
                    if (i % 2 == 0)
                    {
                        r.PostMessageLight("Nope.");
                        return;
                    }
                    ShutdownMre.Set();
                    return;
                }
            }

            Console.WriteLine("{0} - {1} - {2}",
                              evt,
                              u != null ? u.Name : (m != null ? m.Author.Name : ""),
                              m != null ? m.Content : "");

            var args    = new ChatEventArgs(evt, m, u, r, raw);
            var handled = HandleTriggerEvent(args);

            if (!handled && m != null &&
                (evt == EventType.UserMentioned ||
                 evt == EventType.MessageReply))
            {
                HandleCommandEvent(args);
            }
        }
Ejemplo n.º 3
0
        private bool HandleTriggerEvent(ChatEventArgs e)
        {
            bool stayActive = false;

            if (!Triggers.ContainsKey(e.Type))
            {
                return(false);
            }

            // Last active gets first crack
            if (ActiveTriggers[e.Type] != null)
            {
                stayActive = ActiveTriggers[e.Type].HandleEvent(this, e);
                if (e.Handled)
                {
                    return(e.Handled);
                }
            }

            foreach (ITrigger trigger in Triggers[e.Type])
            {
                stayActive = trigger.HandleEvent(this, e);
                if (stayActive && e.Handled)
                {
                    ActiveTriggers[e.Type] = trigger;
                }
                if (e.Handled)
                {
                    break;
                }
            }

            if (!stayActive)
            {
                ActiveTriggers[e.Type] = null;
            }

            return(e.Handled);
        }
Ejemplo n.º 4
0
        private bool HandleTriggerEvent(ChatEventArgs e)
        {
            bool stayActive = false;

            if (!Triggers.ContainsKey(e.Type)) return false;

            // Last active gets first crack
            if (ActiveTriggers[e.Type] != null)
            {
                stayActive = ActiveTriggers[e.Type].HandleEvent(this, e);
                if (e.Handled)
                {
                    return e.Handled;
                }
            }

            foreach (ITrigger trigger in Triggers[e.Type])
            {
                stayActive = trigger.HandleEvent(this, e);
                if (stayActive && e.Handled)
                {
                    ActiveTriggers[e.Type] = trigger;
                }
                if (e.Handled)
                {
                    break;
                }
            }

            if (!stayActive)
            {
                ActiveTriggers[e.Type] = null;
            }

            return e.Handled;
        }
Ejemplo n.º 5
0
        private void HandleCommandEvent(ChatEventArgs e)
        {
            foreach (ICommand command in commands)
            {
                if (!commandStates[command]) continue;

                if (command.CommandPattern.IsMatch(e.Message.Content))
                {
                    Room r = e.Room;
                    command.ProcessMessage(e.Message, ref r);
                    break;
                }
            }
        }
Ejemplo n.º 6
0
        private void EventCallback(EventType evt, Message m, User u, Room r, string raw)
        {
            if (evt == EventType.UserMentioned)
            {
                if (Regex.IsMatch(m.Content, @"(?i)^(die|stop|shutdown)$"))
                {
                    ShutdownMre.Set();
                    return;
                }
            }

            Console.WriteLine("{0} - {1} - {2}",
                evt,
                u != null ? u.GetChatFriendlyUsername() : (m != null ? m.Author.GetChatFriendlyUsername() : ""),
                m != null ? m.Content : "");

            ChatEventArgs args = new ChatEventArgs(evt, m, u, r, raw);
            bool handled = HandleTriggerEvent(args);
            if (!handled && m != null && evt == EventType.UserMentioned) HandleCommandEvent(args);
        }