Exemple #1
0
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            var gdocs = new GoogleDocsRecipeSource(File.ReadAllText(args[1]));

            cache = new RecipesCache(gdocs);

            baseUrl = $"https://api.telegram.org/bot{args[0]}";

            var updateId = 0;

            while (true)
            {
                var url          = $"{baseUrl}/getUpdates?offset={updateId + 1}&timeout=20";
                var answerString = httpClient.GetStringAsync(url).GetAwaiter().GetResult();
                var answer       = JsonConvert.DeserializeObject <Answer>(answerString, jsonSerializerSettings);

                if (answer.Result.Count == 0)
                {
                    Console.WriteLine("Nothing new");
                    continue;
                }

                updateId = answer.Result.Last().UpdateId;
                foreach (var update in answer.Result)
                {
                    try
                    {
                        ProcessUpdate(update);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Update {update.Message.Chat.Username}: {ex}");
                    }
                }
            }
        }
Exemple #2
0
 public RecipesCache(GoogleDocsRecipeSource source)
 {
     this.source = source;
     UpdateRoutine();
 }