Exemplo n.º 1
0
        /// <summary>
        /// Handles the OnMessage event of the HipChatService.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="HipBot.Events.MessageEventArgs"/> instance containing the event data.</param>
        void HipChatService_OnMessage(object sender, MessageEventArgs e)
        {
            Out.WriteLine("{0:HH:mm:ss} [{1}] {2}", e.Message.Received, e.Message.From, e.Message.Body);

            ThreadPool.QueueUserWorkItem(OnMessageCallback, e);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Occurs when an incoming message is received
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="msg">The MSG.</param>
        void ConnectionOnMessage(object sender, Msg msg)
        {
            // Prevent loop-back
            if (msg.From.Resource == current.Name) return;

            // Ignore composing messages
            if (msg.Chatstate == Chatstate.composing) return;

            // Construct message
            var message = new Message
            {
                From = msg.From.Resource,
                Room = msg.From.User,
                Body = msg.Body,
                To = msg.To.Resource,
                Received = DateTime.Now
            };

            var room = new Room
            {
                JabberId = msg.From.User,
                IsChat = msg.Type == MessageType.chat
            };

            if (room.IsChat)
            {
                room.JabberId = msg.From.User;
            }

            // Construct args
            var args = new MessageEventArgs
            {
                Message = message,
                Room = room
            };

            // Fire
            OnMessage(this, args);
        }