示例#1
0
        /// <summary>
        /// The receive message.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        public void ReceiveMessage(SkypeContact contact, SkypeChat chat, string message)
        {
            this.logger.LogMessage(
                string.Format("Received message <{0}> from <{1}> in chat <{2}>", message, contact.Id, chat.Id));

            List <ISkypeCommand> commands = this.commandManager.GetCommandsForChat(chat);

            ISkypeCommand command = this.messageParser.ParseMessage(
                message,
                commands.OfType <AbstractDirectCommand>(),
                commands.OfType <AbstractReplaceCommand>(),
                chat.Contacts.Count == 2);

            if (command != null)
            {
                ThreadPool.QueueUserWorkItem(
                    data =>
                {
                    string response;
                    try
                    {
                        response = command.Execute(contact, chat, message);
                    }
                    catch (Exception)
                    {
                        response =
                            "Something bad happened with command execution. Please address it to developers or try later";
                    }

                    this.SendMessageToChat(chat, response);
                });
            }
            else if (!this.dataManager.IsChatEnabled(chat.Id))
            {
                // for disabled chats no messages should be shown except the replies to system
                // commands (like on/help/off).
                return;
            }
            else if (AbstractDirectCommand.IsDirectCommand(message) && chat.Contacts.Count != 2)
            {
                // public chats ignore messages that don't match commands since they may be addressed
                // not to eva.
                this.SendMessageToChat(chat, "No such command found");
            }
            else if (chat.Contacts.Count == 2)
            {
                // For private chats any message is addressed to eva and if the message doesn't match
                // commands then it is considered to be an incorrect command (EVA-4 issue).
                this.SendMessageToChat(chat, "No such command found");
            }
        }
示例#2
0
        public void HandleIncomeMessage(string source, SkypeMessage message, Action <string, string> responseAction)
        {
            try
            {
                string skypeMessage = message.Message.Trim();
                Match  chatBotMatch = Regex.Match(skypeMessage, @"^bot,(.*)");
                if (chatBotMatch.Success)
                {
                    string messageForBot = chatBotMatch.Groups[1].Value;
                    if (!string.IsNullOrEmpty(messageForBot))
                    {
                        string chatBotResponse = _chatterBot.Think(messageForBot);
                        if (!string.IsNullOrEmpty(chatBotResponse))
                        {
                            chatBotResponse = string.Format("@{0}, {1}", message.AuthorDisplayName, chatBotResponse);
                            responseAction(source, chatBotResponse.Trim());
                        }
                    }
                }
                else
                {
                    ISkypeCommand command = _commandProvider.GetCommand(skypeMessage);
                    if (null != command)
                    {
                        string response = command.RunCommand();
                        if (!string.IsNullOrWhiteSpace(response))
                        {
                            responseAction(source, response);
                        }
                    }
                }

                string ruleServiceResponse = _ruleService.GetApplicableRuleResult(message.Message);
                if (!string.IsNullOrEmpty(ruleServiceResponse))
                {
                    responseAction(source, ruleServiceResponse);
                }
            }
            catch (Exception ex)
            {
                ErrorLog.LogError("HandleInclomeMessage error:\r\nsource:{0}\r\nmessage:{1}\r\nerror:{2}", source, message.ToString(), ex.Message);
            }
        }