Esempio n. 1
0
        public override async Task Execute(Message message, TelegramBotClient client, ApplicationContext context, TelegramMarkupsService markups)
        {
            if (Langs.Contains(message.Text))
            {
                await SetLanguage(message, client, context, markups);

                return;
            }

            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 (ChooseLang == null)
            {
                ChooseLang = await context.Lines.FindAsync("chooseLang");
            }
            var chooseLang = ChooseLang.GetTranslate(user.Lang);

            await client.SendTextMessageAsync(user.TelegramId, chooseLang, replyMarkup : markups.GetLanguageMarkup());
        }
Esempio n. 2
0
        public override async Task <bool> Contains(Message message, ApplicationContext context)
        {
            if (message.Type != MessageType.Text)
            {
                return(false);
            }

            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(false);
            }

            if (Name == null)
            {
                Name = await context.Lines.FindAsync("changeLanguage");
            }

            if (Langs.Count == 0)
            {
                foreach (UserLang lang in Enum.GetValues(typeof(UserLang)))
                {
                    Langs.Add(lang.ToString());
                }
            }
            return(Name.Contains(message.Text) || Langs.Contains(message.Text));
        }