Ejemplo n.º 1
0
        private static async Task <Tuple <DateTimeSchedule, Exception, string> > AskDate2Async(int id, string lang,
                                                                                               TelegramBotAbstract sender,
                                                                                               string username)
        {
            var lang2 = new Language(new Dictionary <string, string>
            {
                { "it", "Inserisci una data (puoi scrivere anche 'fra un'ora')" },
                { "en", "Insert a date (you can also write 'in an hour')" }
            });

            var reply = await AskUser.AskAsync(id, lang2, sender, lang, username);

            try
            {
                var replyDatetime = GetDateTimeFromString(reply);
                if (replyDatetime.Item2 != null)
                {
                    return(new Tuple <DateTimeSchedule, Exception, string>(null, replyDatetime.Item2, reply));
                }

                return(new Tuple <DateTimeSchedule, Exception, string>(new DateTimeSchedule(replyDatetime.Item1, true),
                                                                       null, reply));
            }
            catch (Exception e1)
            {
                return(new Tuple <DateTimeSchedule, Exception, string>(null, e1, reply));
            }
        }
Ejemplo n.º 2
0
        private static async Task <DateTimeSchedule> AskDate2Async(int id, string lang, TelegramBotAbstract sender,
                                                                   string username)
        {
            var lang2 = new Language(new Dictionary <string, string>
            {
                { "it", "Inserisci una data (puoi scrivere anche 'fra un'ora')" },
                { "en", "Insert a date (you can also write 'in an hour'" }
            });

            var reply = await AskUser.AskAsync(id, lang2, sender, lang, username);

            var replyDatetime = GetDateTimeFromString(reply);

            return(new DateTimeSchedule(replyDatetime, true));
        }
Ejemplo n.º 3
0
        private static async Task <int?> GetIdEntityFromPersonAsync(int id, Language question,
                                                                    TelegramBotAbstract sender, string lang, string username)
        {
            const string q =
                "SELECT Entities.id, Entities.name FROM (SELECT * FROM PeopleInEntities WHERE id_person = @idp) AS T1, Entities WHERE T1.id_entity = Entities.id";
            var r = SqLite.ExecuteSelect(q, new Dictionary <string, object> {
                { "@idp", id }
            });

            if (r == null || r.Rows.Count == 0)
            {
                return(null);
            }

            if (r.Rows.Count == 1)
            {
                return(Convert.ToInt32(r.Rows[0].ItemArray[0]));
            }

            var l = new Dictionary <string, int>();

            foreach (DataRow dr in r.Rows)
            {
                var s = dr.ItemArray[1].ToString();
                if (!string.IsNullOrEmpty(s))
                {
                    l[s] = Convert.ToInt32(dr.ItemArray[0]);
                }
            }

            var l3 = l.Keys.Select(
                l2 => new Language(
                    new Dictionary <string, string>
            {
                { "en", l2 }
            })
                ).ToList();

            var options = KeyboardMarkup.ArrayToMatrixString(l3);
            var r2      = await AskUser.AskBetweenRangeAsync(id, question, sender, lang,
                                                             options, username);

            return(l[r2]);
        }