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);
                }
            }
        }
Exemple #2
0
        private void OnChatCommandReceived(object sender, OnChatCommandReceivedArgs e)
        {
            ChatMessage cMsg = e.Command.ChatMessage;

            EvtUserMsgData msgData = new EvtUserMsgData(cMsg.UserId, cMsg.Username, cMsg.DisplayName,
                                                        cMsg.Channel, cMsg.Message);

            EvtChatCommandArgs chatCmdArgs = new EvtChatCommandArgs
            {
                Command = new EvtChatCommandData(e.Command.ArgumentsAsList, e.Command.ArgumentsAsString,
                                                 msgData, e.Command.CommandIdentifier, e.Command.CommandText)
            };

            ChatCommandReceivedEvent?.Invoke(chatCmdArgs);
        }