private void ReadWaitInputs()
        {
            while (true)
            {
                if (StopConsoleThread == true)
                {
                    break;
                }

                //if (Console.KeyAvailable == false)
                //    continue;

                string line = Console.ReadLine();

                User user = UserData;

                //Send message event
                EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
                {
                    UsrMessage = new EvtUserMsgData(user.Name, user.Name,
                                                    user.Name, string.Empty, line)
                };

                UserSentMessageEvent?.Invoke(user, umArgs);

                //Attempt to parse the message as an input
                ProcessMsgAsInput(user, umArgs);

                //Check for a command
                if (line.Length > 0 && line[0] == Globals.CommandIdentifier)
                {
                    //Build args list
                    List <string> argsList  = new List <string>(line.Split(' '));
                    string        argsAsStr = string.Empty;

                    //Remove the command itself and the space from the string
                    if (argsList.Count > 1)
                    {
                        argsAsStr = line.Remove(0, argsList[0].Length + 1);
                    }

                    //Remove command identifier
                    string cmdText = argsList[0].Remove(0, 1);

                    //Now remove the first entry from the list, which is the command, retaining only the arguments
                    argsList.RemoveAt(0);

                    EvtChatCommandArgs chatcmdArgs = new EvtChatCommandArgs();
                    EvtUserMsgData     msgData     = new EvtUserMsgData(user.Name, user.Name, user.Name, string.Empty, line);

                    chatcmdArgs.Command = new EvtChatCommandData(argsList, argsAsStr, msgData, Globals.CommandIdentifier, cmdText);

                    ChatCommandReceivedEvent?.Invoke(UserData, chatcmdArgs);
                }
            }
        }
Example #2
0
        //Break up much of the message handling by sending events
        private void OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
            {
                //UserData = user,
                UsrMessage = new EvtUserMsgData(e.ChatMessage.UserId, e.ChatMessage.Username,
                                                e.ChatMessage.DisplayName, e.ChatMessage.Channel, e.ChatMessage.Message)
            };

            UserSentMessageEvent?.Invoke(umArgs);
        }
        private void ReadWaitInputs()
        {
            while (true)
            {
                if (StopConsoleThread == true)
                {
                    break;
                }

                string line = Console.ReadLine();

                //Send message event
                EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
                {
                    UsrMessage = new EvtUserMsgData(TerminalUsername, TerminalUsername, TerminalUsername,
                                                    string.Empty, line)
                };

                UserSentMessageEvent?.Invoke(umArgs);

                //Check for a command
                if (line.Length > 0 && line[0] == CommandIdentifier)
                {
                    //Build args list
                    List <string> argsList  = new List <string>(line.Split(' '));
                    string        argsAsStr = string.Empty;

                    //Remove the command itself and the space from the string
                    if (argsList.Count > 1)
                    {
                        argsAsStr = line.Remove(0, argsList[0].Length + 1);
                    }

                    //Remove command identifier
                    string cmdText = argsList[0].Remove(0, 1);

                    //Now remove the first entry from the list, which is the command, retaining only the arguments
                    argsList.RemoveAt(0);

                    EvtChatCommandArgs chatcmdArgs = new EvtChatCommandArgs();
                    EvtUserMsgData     msgData     = new EvtUserMsgData(TerminalUsername, TerminalUsername, TerminalUsername,
                                                                        string.Empty, line);

                    chatcmdArgs.Command = new EvtChatCommandData(argsList, argsAsStr, msgData, CommandIdentifier, cmdText);

                    ChatCommandReceivedEvent?.Invoke(chatcmdArgs);
                }
            }
        }
Example #4
0
        //Break up much of the message handling by sending events
        private void OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            User user = BotProgram.GetOrAddUser(e.ChatMessage.DisplayName, false);

            EvtUserMessageArgs umArgs = new EvtUserMessageArgs()
            {
                UsrMessage = new EvtUserMsgData(e.ChatMessage.UserId, e.ChatMessage.Username,
                                                e.ChatMessage.DisplayName, e.ChatMessage.Channel, e.ChatMessage.Message)
            };

            UserSentMessageEvent?.Invoke(user, umArgs);

            //Attempt to parse the message as an input
            ProcessMsgAsInput(user, umArgs);
        }