Exemple #1
0
        private IEnumerable <BotAction> CreateReaderActions()
        {
            var listActions = new List <BotAction>();

            var setReaderAction = new BotAction()
            {
                CommandLine = Constants.CMD_READER_SET,
                Description = Constants.DESC_READER_SET,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    if (parameters == null || !parameters.Any())
                    {
                        return(Task.FromResult($"Vous devez fournir le nom du lecteur"));
                    }

                    var name = parameters[0];

                    var reader = _readers.Where(r => r.Name.ToLowerInvariant() == name.ToLowerInvariant()).FirstOrDefault();

                    if (reader == null)
                    {
                        return(Task.FromResult($"Le lecteur avec le nom *{name}* n'a pas pu être trouvé"));
                    }

                    if (_currentReader != null)
                    {
                        _currentReader.Stop(log);
                    }

                    _currentReader = reader;

                    return(Task.FromResult($"Le lecteur courant est maintenant *{_currentReader.Name}*"));
                }
            };

            listActions.Add(setReaderAction);

            var getReadersAction = new BotAction()
            {
                CommandLine = Constants.CMD_READER_GET_ALL,
                Description = Constants.DESC_READER_GET_ALL,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    if (!_readers.Any())
                    {
                        return(Task.FromResult($"Il n'y a pas de lecteurs enregistrés"));
                    }

                    return(Task.FromResult(string.Join("\n", _readers.Select(r => r.Name).ToList())));
                }
            };

            listActions.Add(getReadersAction);

            var getReaderAction = new BotAction()
            {
                CommandLine = Constants.CMD_READER_GET,
                Description = Constants.DESC_READER_GET,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    if (_currentReader == null)
                    {
                        return(Task.FromResult($"Il n'y a pas de lecteur sélectionné"));
                    }

                    return(Task.FromResult($"Le lecteur courant est *{_currentReader.Name}*"));
                }
            };

            listActions.Add(getReaderAction);

            return(listActions);
        }
Exemple #2
0
        private IEnumerable <BotAction> CreateCategoryActions()
        {
            var listActions = new List <BotAction>();

            var helpAction = new BotAction()
            {
                CommandLine = Constants.CMD_HELP,
                Description = Constants.DESC_HELP,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    return(Task.FromResult("Pour voir les catégories *!categories*, pour voir les commandes d'une categorie *!category <category>*"));
                }
            };

            listActions.Add(helpAction);

            var categoryAction = new BotAction()
            {
                CommandLine = Constants.CMD_CATEGORY_ACTIONS,
                Description = Constants.DESC_CATEGORY_ACTIONS,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    if (parameters == null || !parameters.Any())
                    {
                        return(Task.FromResult($"Vous devez fournir la categorie"));
                    }

                    var name = parameters[0];

                    var actions = _actions.Where(r => r.Category.ToLowerInvariant() == name.ToLowerInvariant()).ToList();

                    if (!actions.Any())
                    {
                        return(Task.FromResult($"Il n'y a pas d'actions pour la catégorie *{name}*"));
                    }

                    return(Task.FromResult(string.Join("\n", actions.Select(a => $"*{a.CommandLine}* ({a.Description})"))));
                }
            };

            listActions.Add(categoryAction);

            var categoriesAction = new BotAction()
            {
                CommandLine = Constants.CMD_CATEGORY_ALL,
                Description = Constants.DESC_CATEGORY_ALL,
                Category    = Constants.CAT_OTHER,
                Execute     = (parameters, log, currentReader, user, time) =>
                {
                    if (!_actions.Any())
                    {
                        return(Task.FromResult($"Il n'y a pas d'actions d'enregistrées"));
                    }

                    var categories = _actions.Select(a => $"*{a.Category}*").Distinct();

                    return(Task.FromResult(string.Join("\n", categories)));
                }
            };

            listActions.Add(categoriesAction);

            return(listActions);
        }