Esempio n. 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");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="contact">
        /// The contact.
        /// </param>
        /// <param name="chat">
        /// The chat.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public override string Execute(SkypeContact contact, SkypeChat chat, string message)
        {
            string args = this.ExtractCommandArgument(message, chat.Contacts.Count == 2);

            if (string.IsNullOrWhiteSpace(args))
            {
                var sb = new StringBuilder();
                sb.AppendLine("The commands supported by this bot:");
                sb.AppendLine("help - displays this help message");

                foreach (AbstractDirectCommand command in this.commands)
                {
                    sb.AppendLine(string.Format("{0} - {1}", command.Name, command.Help));
                }

                sb.AppendLine();
                sb.Append("To get more commands, you should be subscribed to some project.");
                sb.Append("To get detailed help for a certain command, type a command ");
                sb.AppendLine("name after the 'help' command. For example:");
                sb.AppendLine("help on");

                return(sb.ToString());
            }

            if (string.Equals(args, "help", StringComparison.CurrentCultureIgnoreCase))
            {
                return("Displays the main help page");
            }

            AbstractDirectCommand directCommand =
                this.commands.FirstOrDefault(c => string.Equals(c.Name, args, StringComparison.OrdinalIgnoreCase));

            if (directCommand != null)
            {
                return(directCommand.Usage);
            }

            return("The command is not found. Please type 'help' to see available commands");
        }