Beispiel #1
0
        public async Task GoNextLinksStep(UserWrapper user)
        {
            if (user.LastCallBackQuery == null)
            {
                return;
            }

            var linkName = user.LastCallBackQuery.Data.Replace(InlinePrefixKeys.LinksKey + "Edit", "");

            if (user.WaitingMessageQuery == null || user.WaitingMessageQuery != nameof(GoNextLinksStep))
            {
                user.WaitingMessageQuery = nameof(GoNextLinksStep);

                user.LastCallBackQuery.Message = await Bot.EditMessageReplyMarkupAsync(user.LastCallBackQuery.Message.Chat.Id,
                                                                                       user.LastCallBackQuery.Message.MessageId, KeyboardCollection.CancelInlineKeyboard());

                await AnswerCallbackQueryAsync(user, $"Please enter new {linkName} link and press Enter key.", cacheTime : 6000);
            }
            else
            {
                if (Regex.IsMatch(user.LastMessageQuery.Text, StringHelper.UriPattern) &&
                    Uri.TryCreate(user.LastMessageQuery.Text, UriKind.RelativeOrAbsolute, out Uri uri) &&
                    (uri.Scheme == Uri.UriSchemeHttp ||
                     uri.Scheme == Uri.UriSchemeHttps ||
                     uri.Scheme == Uri.UriSchemeFtp ||
                     uri.Scheme == Uri.UriSchemeMailto))
                {
                    var prop = WebsiteManager.GetType()
                               .GetProperties()
                               .FirstOrDefault(p => p.Name.StartsWith(linkName));

                    prop?.SetValue(WebsiteManager, uri.ToString());

                    await Bot.SendTextMessageAsync(user.LastCallBackQuery.Message.Chat.Id, "The link updated.");

                    user.LastCallBackQuery.Message = await Bot.EditMessageReplyMarkupAsync(user.LastCallBackQuery.Message.Chat.Id,
                                                                                           user.LastCallBackQuery.Message.MessageId, KeyboardCollection.LinksInlineKeyboard(WebsiteManager));

                    user.WaitingMessageQuery = null; // waiting method called and then clear buffer
                }
                else
                {
                    await Bot.SendTextMessageAsync(user.LastCallBackQuery.Message.Chat.Id,
                                                   "Please enter just Uri format like example: http://sampleuri.com");
                }
            }
        }
Beispiel #2
0
        public async Task GoNextAboutStep(UserWrapper user)
        {
            if (user.LastCallBackQuery == null)
            {
                return;
            }

            var propName = user.LastCallBackQuery.Data.Replace(InlinePrefixKeys.AboutKey + "Edit", "");

            if (user.WaitingMessageQuery == null || user.WaitingMessageQuery != nameof(GoNextAboutStep))
            {
                user.WaitingMessageQuery = nameof(GoNextAboutStep);
                await Bot.EditMessageReplyMarkupAsync(user.LastCallBackQuery.Message.Chat.Id,
                                                      user.LastCallBackQuery.Message.MessageId, KeyboardCollection.CancelInlineKeyboard());

                await AnswerCallbackQueryAsync(user, $"Please enter new {Localization.ResourceManager.GetString(propName)?.ToLower()} and press Enter key.", false, cacheTime : 6000);
            }
            else
            {
                var prop = WebsiteManager.GetType().GetProperties().FirstOrDefault(p => p.Name == propName);
                prop?.SetValue(WebsiteManager, user.LastMessageQuery.Text);
                await Bot.EditMessageTextAsync(user.LastCallBackQuery.Message.Chat.Id, user.LastCallBackQuery.Message.MessageId,
                                               Localization.ResourceManager.GetString(propName) + ": \n\r" + (prop?.GetValue(WebsiteManager) ?? "---"),
                                               ParseMode.Default, false, (IReplyMarkup)KeyboardCollection.GetType().GetProperties().FirstOrDefault(p => p.Name.StartsWith(propName))?.GetValue(KeyboardCollection));

                user.WaitingMessageQuery = null; // waiting method called and then clear buffer
            }
        }
Beispiel #3
0
        public async Task GoNextLogoStep(UserWrapper user)
        {
            if (user.LastCallBackQuery == null)
            {
                return;
            }

            if (user.WaitingMessageQuery == null || user.WaitingMessageQuery != nameof(GoNextLogoStep))
            {
                user.WaitingMessageQuery = nameof(GoNextLogoStep);
                await Bot.EditMessageReplyMarkupAsync(user.LastCallBackQuery.Message.Chat.Id,
                                                      user.LastCallBackQuery.Message.MessageId, KeyboardCollection.CancelInlineKeyboard());

                await AnswerCallbackQueryAsync(user, "Please send an image to change logo ...", false, cacheTime : 6000);
            }
            else if (user.LastMessageQuery.Photo.Any())
            {
                using (var mem = new MemoryStream())
                {
                    await Bot.GetFileAsync(user.LastMessageQuery.Photo.Last().FileId, mem);

                    WebsiteManager.Logo = mem.ToByte();
                    await DeleteMessageAsync(user.LastCallBackQuery.Message);

                    await Bot.SendTextMessageAsync(user.LastCallBackQuery.Message.Chat.Id, "The logo changed successfully.");
                }
                user.WaitingMessageQuery = null; // waiting method called and then clear buffer
            }
            else
            {
                await AnswerCallbackQueryAsync(user, "Please send an image to change logo ...", false, cacheTime : 6000);
            }
        }