Exemple #1
0
        public async Task OnTest(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            TelegramInlineKeyboard inline = new TelegramInlineKeyboard();

            inline
            .AddTextRow("567")
            .AddCallbackRow("56");
            await client.EditMessageTextAsync(query.From.Id, query.Message.MessageId, "meow");

            await client.EditMessageReplyMarkupAsync(query.From.Id, query.Message.MessageId, replyMarkup : inline.Markup);
        }
Exemple #2
0
        public async Task OnMeet(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            long userId = Convert.ToInt64(query.Data.Split('-')[1]);
            User user   = await UserDB.GetUserByChatId(context, query.From.Id);

            StringBuilder          builder = new StringBuilder();
            TelegramInlineKeyboard inline  = new TelegramInlineKeyboard();

            inline
            .AddTextRow("Отклонить", "Принять")
            .AddCallbackRow($"decline-{query.From.Id}", $"accept-{query.From.Id}");

            builder.AppendLine("Вам назначена встреча от:");
            builder.AppendLine($"{user.FirstName} {user.LastName}");

            await client.SendTextMessageAsync(userId, builder.ToString(), ParseMode.Markdown,
                                              replyMarkup : inline.Markup);
        }
Exemple #3
0
        public async Task OnAddingTag(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            int        tagId       = Convert.ToInt32(query.Data.Split('-')[1]);
            int        parentTagId = context.Tags.Where(t => t.TagId == tagId).Select(e => e.ParentTagID).First();
            List <Tag> childTags   = context.Tags.Where(x => x.Level == 2 && x.ParentTagID == parentTagId).ToList();
            User       user        = await UserDB.GetUserByChatId(context, query.From.Id);

            TelegramInlineKeyboard inline = new TelegramInlineKeyboard();

            bool added = await UserDB.AddDeleteTag(context, query.From.Id, tagId);

            string ch = "";
            bool   ex;

            foreach (var tag in childTags)
            {
                if (tag.TagId != tagId)
                {
                    ex = user.UserTags.FirstOrDefault(e => e.TagId == tag.TagId) != null;
                }
                else
                {
                    ex = added;
                }

                if (ex)
                {
                    ch = Utils.GetCheckmark();
                }
                else
                {
                    ch = "";
                }

                inline.AddTextRow($"{tag.Name} {ch}").AddCallbackRow($"tag-{tag.TagId}");
            }


//            await client.EditMessageTextAsync(query.From.Id, query.Message.MessageId, "meow");
            await client.EditMessageReplyMarkupAsync(query.From.Id, query.Message.MessageId,
                                                     replyMarkup : inline.Markup);
        }
Exemple #4
0
        public async Task OnBook(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            long userId = Convert.ToInt64(query.Data.Split('-')[1]);

            User user = await UserDB.GetUserByChatId(context, query.From.Id);                                   // kim

            InfoAboutUsers info = context.InfoAboutUsers.FirstOrDefault(N => N.EventId == user.CurrentEventId); //Liza

            info.AmountOfRequestsOfContacts++;
            context.Update(info);
            context.SaveChanges();
            User toAdd = await UserDB.GetUserByChatId(context, userId); // roma

            StringBuilder builder = new StringBuilder();

            TelegramInlineKeyboard inline = new TelegramInlineKeyboard();

            List <ContactsBook> contacts = user.Contacts;

            if (contacts.All(e => e.AnotherUserId != toAdd.TelegramId))
            {
                ContactsBook book = new ContactsBook()
                {
                    OwnerId       = user.TelegramId,
                    AnotherUserId = toAdd.TelegramId,
                    IsAccepted    = false
                };
                user.Contacts.Add(book);
                context.Update(user);
                context.SaveChanges();

                await client.SendTextMessageAsync(user.TelegramId, builder.ToString(), ParseMode.Markdown);

                inline
                .AddTextRow("Да", "Нет")
                .AddCallbackRow($"contacts_accept-{user.TelegramId}", $"contacts_decline-{user.TelegramId}");

                await client.SendTextMessageAsync(toAdd.TelegramId,
                                                  $"{user.FirstName} сделал запрос на добавление контактов, потвердить?", ParseMode.Markdown, replyMarkup : inline.Markup);
            }
        }
Exemple #5
0
        public async Task OnProfile(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            long          userId  = Convert.ToInt32(query.Data.Split('-')[1]); // roma
            StringBuilder builder = new StringBuilder();
            User          us      = await UserDB.GetUserByChatId(context, userId);

            builder.AppendLine($"{us.FirstName} {us.CompanyAndPosition}");
            builder.AppendLine();
            builder.AppendLine($"_Чем полезен_: {us.Utility}");
            builder.AppendLine();
            builder.AppendLine($"_О чем можно пообщаться_: {us.Communication}");

            TelegramInlineKeyboard inline = new TelegramInlineKeyboard();

            inline
            .AddTextRow(Utils.GetCheckmark(), "Встреча")
            .AddCallbackRow($"contact-{us.TelegramId}", $"meet-{us.TelegramId}");

            await client.SendTextMessageAsync(query.From.Id, builder.ToString(), ParseMode.Markdown,
                                              replyMarkup : inline.Markup);
        }
Exemple #6
0
        public async Task OnProfilePage(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            int  page = Convert.ToInt32(query.Data.Split('-')[1]); // roma
            User user = await UserDB.GetUserByChatId(context, query.From.Id);

            StringBuilder          builder = new StringBuilder();
            TelegramInlineKeyboard inline  = new TelegramInlineKeyboard();

            List <ContactsBook> contacts = user.Contacts.Skip(4 * (page - 1)).Take(4).ToList();
            List <string>       nums     = new List <string>(4);
            List <string>       ids      = new List <string>(4);


            var tags = user.SearchingUserTags
                       .Select(u => context.SearchingTags.FirstOrDefault(t => t.SearchingTagId == u.TagId)?.Name).ToList();

            builder.AppendLine("_Ваши теги_");
            builder.AppendLine($"`{string.Join(", ", tags)}`");
            builder.AppendLine();
            builder.AppendLine("*Ваши контакты*");
            builder.AppendLine();
            int i = 1;

            foreach (var contactsBook in contacts)
            {
                nums.Add(i.ToString());
                ids.Add($"prof-{contactsBook.AnotherUserId}");
                User another = await UserDB.GetUserByChatId(context, contactsBook.AnotherUserId);

                builder.AppendLine($"*{i})*{another.FirstName} {another.LastName} {another.CompanyAndPosition}");
                builder.AppendLine($"_Чем полезен_: {another.Utility}");
                builder.AppendLine($"_Контакт_: @{another.TelegramUserName}");
                builder.AppendLine();
                i++;
            }

            if (user.Contacts.Count > 4 * page)
            {
                if (page != 1)
                {
                    inline
                    .AddTextRow("⬅️", "➡️")
                    .AddCallbackRow($"profpage-{page - 1}", $"profpage-{page + 1}");
                }
                else
                {
                    inline
                    .AddTextRow("➡️")
                    .AddCallbackRow($"profpage-{page + 1}");
                }
            }
            else
            {
                inline
                .AddTextRow("⬅️")
                .AddCallbackRow($"profpage-{page - 1}");
            }

            inline
            .AddTextRow(nums.ToArray())
            .AddCallbackRow(ids.ToArray());

            await client.SendTextMessageAsync(query.From.Id, builder.ToString(), parseMode : ParseMode.Markdown,
                                              replyMarkup : inline.Markup);
        }
Exemple #7
0
        public async Task OnChange(ApplicationContext context, CallbackQuery query, TelegramBotClient client)
        {
            int changeId = Convert.ToInt32(query.Data.Split('-')[1]);
            int left     = changeId;


            User user = await UserDB.GetUserByChatId(context, query.From.Id);

            StringBuilder          builder       = new StringBuilder();
            TelegramInlineKeyboard inline        = new TelegramInlineKeyboard();
            List <User>            usersWithTags = context.Users
                                                   .Include(u => u.UserTags)
                                                   .ThenInclude(ut => ut.Tag)
                                                   .Where(e => e.UserTags.Any(ut =>
                                                                              user.SearchingUserTags.FirstOrDefault(t => t.TagId == ut.TagId) != null) &&
                                                          e.CurrentEventId == user.CurrentEventId).ToList();

            List <User> usersWithoutTags = context.Users
                                           .Include(u => u.UserTags)
                                           .ThenInclude(ut => ut.Tag)
                                           .Where(e =>
                                                  e.UserTags.All(ut =>
                                                                 user.SearchingUserTags.FirstOrDefault(t => t.TagId == ut.TagId) == null) &&
                                                  e.CurrentEventId == user.CurrentEventId).ToList();

            usersWithTags.AddRange(usersWithoutTags);



            if (changeId == 0)
            {
                changeId = usersWithTags.Count;
                left     = changeId;
            }

            if (changeId > 0 && changeId <= usersWithTags.Count)
            {
                User us = usersWithTags[changeId - 1];
                builder.AppendLine($"{us.FirstName} {us.CompanyAndPosition}");
                builder.AppendLine();
                builder.AppendLine($"_Теги_: {string.Join(", ", us.UserTags.Select(e => e.Tag.Name))}");
                builder.AppendLine();
                builder.AppendLine($"_Чем полезен_: {us.Utility}");
                builder.AppendLine();
                builder.AppendLine($"_О чем можно пообщаться_: {us.Communication}");
                string ch;
                if (user.Contacts.Any(e => e.AnotherUserId == us.TelegramId))
                {
                    ch = Utils.GetCheckmark();
                }
                else
                {
                    ch = "В книжку";
                }

                if (changeId + 1 > usersWithTags.Count)
                {
                    changeId = 0;
                    left     = 2;
                }

                if (changeId - 1 < 0)
                {
                    left = 2;
                }



                inline
                .AddTextRow("⬅️", ch, "Встреча", "➡️")
                .AddCallbackRow($"change-{left - 1}", $"contact-{us.TelegramId}", $"meet-{us.TelegramId}",
                                $"change-{changeId + 1}");


                await client.EditMessageTextAsync(query.From.Id, query.Message.MessageId, builder.ToString(),
                                                  ParseMode.Markdown);

                await client.EditMessageReplyMarkupAsync(query.From.Id, query.Message.MessageId, inline.Markup);
            }
        }