Example #1
0
        private void SendRandomResponse(JID replyTo, string chatText, MessageType messageType)
        {
            string[] chatTextWords = chatText.Split(' ');
            string   message       = string.Empty;

            switch (chatTextWords[0])
            {
            case "coolio":
            case "gaytroll":
                message = "Get-RandomImage " + chatText;
                break;

            default:
                break;
            }

            if (message != string.Empty)
            {
                PowerShellCommand     powerShellCommand = BuildPowerShellCommand(message);
                Collection <PSObject> psObjects         = _powershellRunner.RunPowerShellModule(powerShellCommand.CommandText,
                                                                                                powerShellCommand.ParameterText);
                SendResponse(replyTo, psObjects, messageType);
            }
            return;
        }
Example #2
0
        private void Session_OnMessageReceived(object sender, Message message)
        {
            if (message.Body == null && message.X == null)
            {
                return;
            }

            string chatText = message.Body == null?message.X.InnerText.Trim() : message.Body.Trim();

            if (string.IsNullOrEmpty(chatText) || chatText == " ")
            {
                return;
            }

            JID responseJid = new JID(message.From.User, message.From.Server, message.From.Resource);

            // intercept a handful of messages not directly for AutoBot
            if (message.Type == MessageType.groupchat && !chatText.Trim().StartsWith(_mentionName))
            {
                chatText = RemoveMentionFromMessage(chatText);
                SendRandomResponse(responseJid, chatText, message.Type);
                return;
            }

            // ensure the message is intended for AutoBot
            chatText = RemoveMentionFromMessage(chatText);
            PowerShellCommand     powerShellCommand = BuildPowerShellCommand(chatText);
            Collection <PSObject> psObjects         = _powershellRunner.RunPowerShellModule(powerShellCommand.CommandText,
                                                                                            powerShellCommand.ParameterText);

            SendResponse(responseJid, psObjects, message.Type);
        }