Exemplo n.º 1
0
        public override async Task Execute(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database

            // If user not registered
            if (user == null)
            {
                return;
            }

            var subscribedTo = (await context.Lines.FindAsync("subscribedTo"))
                               .GetTranslate(user.Lang);

            user.SubPikabu = UserSub.Yes;
            context.Users.Update(user);

            await client.SendTextMessageAsync(user.TelegramId, string.Format(subscribedTo, "Pikabu"),
                                              replyMarkup : markups.GetSettingsMarkup(user));

            await context.SaveChangesAsync();
        }
Exemplo n.º 2
0
        private async Task SetLanguage(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database

            // If user not registered
            if (user == null)
            {
                return;
            }

            Enum.TryParse(message.Text, out UserLang lang);
            user.Lang = lang;
            context.Users.Update(user);

            if (LangChanged == null)
            {
                LangChanged = await context.Lines.FindAsync("langChanged");
            }
            var langChanged = LangChanged.GetTranslate(user.Lang);

            await client.SendTextMessageAsync(user.TelegramId, langChanged, replyMarkup : markups.GetSettingsMarkup(user));

            await context.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public override async Task Execute(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database

            // If user not registered
            if (user == null)
            {
                return;
            }

            if (Name == null)
            {
                Name = await context.Lines.FindAsync("settings");
            }
            var settings = Name.GetTranslate(user.Lang);

            await client.SendTextMessageAsync(user.TelegramId, settings, replyMarkup : markups.GetSettingsMarkup(user));
        }
Exemplo n.º 4
0
        public override async Task Execute(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            var chat = message.Chat;
            var user = context.Users.FirstOrDefault(usr => usr.TelegramId == chat.Id); // Finding user in database

            // If user not registered
            if (user == null)
            {
                return;
            }

            if (NewFreebie == null)
            {
                NewFreebie = await context.Lines.FindAsync("newFreebie");
            }
            var newFreebie = NewFreebie.GetTranslate(user.Lang);

            var post = await context.Posts
                       .Where(pst => pst.Type == PostType.Pikabu).
                       OrderByDescending(x => x.Id)
                       .FirstOrDefaultAsync();

            newFreebie = string.Format(newFreebie, post.Type, post.Name, post.Url);

            await client.SendTextMessageAsync(user.TelegramId, newFreebie, replyMarkup : markups.GetSettingsMarkup(user));
        }