public void Update(Dictionary <string, string> pars)
 {
     if (IsEqual(_pars, pars))
     {
         return;
     }
     _pars = pars;
     _echo.Update(EchoOptions.EchoInlineButtons(pars));
 }
        public static StepCollection AddCommandWithParameter(this Step step, string command, ILocalizedString suggestParameterText)
        {
            var commandWithParameter      = new CommandStep(command, true);
            var commandWithoutOfParameter = new CommandStep(command, false);

            commandWithoutOfParameter.EchoReply(suggestParameterText, EchoOptions.EchoForceReply());
            var commandAwaitParameter = commandWithoutOfParameter.AddAnyInput();

            step.AddChildStep(commandWithParameter);
            step.AddChildStep(commandWithoutOfParameter);
            return(new StepCollection(new[] { commandWithParameter, commandAwaitParameter }));
        }
Example #3
0
    public static ProcessResult <Clip[]> Apply(EchoOptions options, params Clip[] clips)
    {
        var processedClips = new Clip[clips.Length];

        // naive version
        // proper algo needs to also delete notes that are covered by an echoed note
        var i = 0;

        foreach (var clip in clips)
        {
            processedClips[i++] = AddEchoes(clip, options.Lengths, options.Echoes);
        }
        return(new ProcessResult <Clip[]>(processedClips));
    }
        private void AddLanguageCommand(Step engine)
        {
            var languages = new[] { "english", "russian" };

            engine.AddCommand("language")
            .EchoReply(new OneLanguageString("Choose language/Выберите язык: " + languages.Aggregate(string.Empty, (s, s1) => $"{s}/{s1}")),
                       EchoOptions.EchoReplyButtons(languages))
            .AddAnyInput()
            .Execute(context =>
            {
                uint?selectedIndex = null;
                var languageStr    = context[0];
                for (uint i = 0; i < languages.Length; i++)
                {
                    var language = languages[i];
                    if (!string.Equals(language, languageStr, StringComparison.InvariantCultureIgnoreCase))
                    {
                        continue;
                    }

                    selectedIndex = i;
                    break;
                }

                if (selectedIndex != null)
                {
                    var gameProvider    = (GameProvider)context.UserState;
                    var choosenLanguage = (uint)selectedIndex;
                    gameProvider.UsingDb(dbContext =>
                    {
                        var userInChatPersistance    = dbContext.UsersInChat.GetUserInChatPersistance(context.UserInChat);
                        var chatInTelegram           = userInChatPersistance.ChatInTelegram;
                        chatInTelegram.LanguageIndex = choosenLanguage;
                        dbContext.SaveChanges();
                    });
                    LocalizedStrings.Language = choosenLanguage;
                    context.ReplyEcho(LocalizedStrings.CommonEngine_LanguageSwitched);
                }
                else
                {
                    context.ReplyEcho("Can not recognize selected language/Не удаётся распознать выбранный язык");    //todo: low в реусрс
                }
            });
        }
Example #5
0
 public void PrivateMessage(User user, string text, string[] replyOptions = null)
 {
     _apiChat.PrivateEcho(user.Id, text, replyOptions == null?EchoOptions.SimpleEcho() : EchoOptions.EchoReplyButtons(replyOptions));
 }
 public static Step EchoReply(this Step step, ILocalizedString localizedString, EchoOptions echoOptions = null)
 {
     step.AppendExecutor(new EchoExecutor(localizedString, echoOptions));
     return(step);
 }
 public EchoExecutor(ILocalizedString echoText, EchoOptions echoOptions)
 {
     _echoText    = echoText;
     _echoOptions = echoOptions;
 }
Example #8
0
        private readonly Dictionary <Guid, UserInChat> _sessions = new Dictionary <Guid, UserInChat>();//not thread safe but we don't care

        public void BuildAdminFlow()
        {
            List <string> commands = new List <string>();

            /*AppendAuthorizedCommand("test", commands, context =>
             * {
             *  context.ReplyEcho(@"Game has not been started yet. _Players are allowed to enter and exit the game_
             * @Yukichang28
             * ");
             *
             *  @chanyuhan
             * @n
             * mafia* - 1, *civilian* - 2, Loose on all civilians kill
             * });*/

            AppendAuthorizedCommand("list_stories", commands, context =>
            {
                var allStories = DatabaseHelper.GetAllStories(_connectionString);
                if (!allStories.Any())
                {
                    context.ReplyEcho("Нет историй");
                }
                for (int index = 0; index < allStories.Length; index++)
                {
                    var story = allStories[index];
                    context.ApiChat.PhotoEcho($"{index+1}. " + story.Body, story.PhotoId);
                }
            });

            AppendAuthorizedCommand("add_story", commands)
            .EchoReply(new OneLanguageString("Введите название истории"))
            .AddAnyInput()
            .EchoReply(new OneLanguageString("Пришлите банер"))
            .AddPhotoInput()
            .Execute(context =>
            {
                var photoId = context[0];
                var caption = context[1];
                if (caption.Length > 200)
                {
                    context.ReplyEcho("Длина заголовка должна быть не более 200 символов");
                }
                else
                {
                    DatabaseHelper.AddStory(photoId, caption, _connectionString);
                    context.ReplyEcho("История добавлена");
                }
            });

            AppendAuthorizedCommand("stat", commands,
                                    context =>
            {
                context.ReplyEcho(context.GetGameProvider().GetStat());
            });

            AppendAuthorizedCommand("delete_story", commands)
            .EchoReply(new OneLanguageString("Укажите номер истории"))
            .AddAnyInput()
            .Execute(context =>
            {
                var indexStr = context[0];
                int index;
                if (!int.TryParse(indexStr, out index))
                {
                    throw new BrakeFlowCallException("Необходимо указать порядковый номер истории");
                }
                index--;
                if (index < 0)
                {
                    throw new BrakeFlowCallException("Номер должен быть больше 0");
                }
                var allStories = DatabaseHelper.GetAllStories(_connectionString);
                var count      = allStories.Length;
                if (index >= count)
                {
                    throw new BrakeFlowCallException("Индекс должен быть меньше, чем кол-во историй");
                }
                DatabaseHelper.DeleteStory(index, _connectionString);
            })
            .EchoReply(new OneLanguageString("История удалена"));

            _privateEngine.AddCommandWithParameter("admin", new OneLanguageString("Введите код доступа"))
            .ForEach(step =>
            {
                step.Execute(context =>
                {
                    if (context[0] != string.Empty)     //todo: low may be redundant
                    {
                        var code = context[0];
                        if (code != ConfigurationManager.AppSettings["ADMIN_PASSWORD"])
                        {
                            throw new BrakeFlowCallException("Неверный код");
                        }
                        var sessionId = Guid.NewGuid();

                        List <string> authorizedCommands = new List <string>();
                        _sessions.Add(sessionId, context.UserInChat);
                        foreach (var command in commands)
                        {
                            authorizedCommands.Add(@"/" + command + $" {sessionId}");
                        }
                        context.ReplyEcho("Выберите команду",
                                          EchoOptions.EchoReplyButtons(authorizedCommands.ToArray()));
                    }
                });
            });
        }
 public void Terminate()
 {//todo: low terminate should be called not only coz of timer, but also coz of abortion
     _echo.Update(EchoOptions.SimpleEcho());
 }