コード例 #1
0
ファイル: Utilities.cs プロジェクト: riiji/ITMOScheduleBot
        public static CommandArgumentContainer ParseCommand(BotEventArgs botArgs)
        {
            string[] commands = botArgs.Text.Split();

            var commandName = commands.FirstOrDefault() ?? throw new BotValidException("ParseCommand: commandName was null");

            //commandName = prefixCommand + commandName.ToLower();

            //skip command name
            IEnumerable <string> args = commands.Skip(1);

            return(new CommandArgumentContainer(commandName, new SenderData(botArgs.GroupId), args.ToList()));
        }
コード例 #2
0
ファイル: Bot.cs プロジェクト: riiji/ITMOScheduleBot
        private void ApiProviderOnMessage(object sender, BotEventArgs e)
        {
            try
            {
                CommandArgumentContainer commandWithArgs = Utilities.ParseCommand(e);

                var commandTaskResult = _commandHandler.IsCommandCorrect(commandWithArgs);

                LoggerHolder.Log.Verbose(commandTaskResult.ExecuteMessage);

                if (!commandTaskResult.IsSuccess)
                {
                    return;
                }

                var commandExecuteResult = _commandHandler.ExecuteCommand(commandWithArgs);

                if (!commandExecuteResult.IsSuccess)
                {
                    LoggerHolder.Log.Warning(commandExecuteResult.ExecuteMessage);
                }

                var writeMessageResult =
                    _botProvider.WriteMessage(new SenderData(e.GroupId), commandExecuteResult.ExecuteMessage);

                LoggerHolder.Log.Verbose(writeMessageResult.ExecuteMessage);
            }
            catch (Exception error)
            {
                LoggerHolder.Log.Error(error.Message);
                _botProvider.Dispose();
                var result = _botProvider.Initialize();
                if (result.Exception != null)
                {
                    LoggerHolder.Log.Verbose(result.ExecuteMessage);
                }

                LoggerHolder.Log.Verbose(result.ExecuteMessage);
            }
        }