Created
February 24, 2019 14:40
-
-
Save MihaZupan/fe79943bf89597fb83ff2832560d70c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var updateReceiver = new QueuedUpdateReceiver(Bot); | |
updateReceiver.StartReceiving(new[] { UpdateType.Message }, errorHandler: HandleErrorAsync); | |
_ = Task.Run(async () => { | |
while (true) | |
{ | |
Console.WriteLine( | |
DateTime.Now.Second.ToString().PadLeft(2, '0') + | |
" Pending: " + updateReceiver.PendingUpdates + | |
" Status: " + (updateReceiver.IsReceiving ? "" : "NOT ") + "receiving"); | |
await Task.Delay(100); | |
} | |
}); | |
await foreach (Update update in updateReceiver.YieldUpdatesAsync()) | |
{ | |
if (update.Message is Message message && message.Text is string text) | |
{ | |
await Bot.SendTextMessageAsync(message.Chat, $"Pending: {updateReceiver.PendingUpdates} updates\nEcho:\n{text}"); | |
if (text.StartsWith("wait") && text.Length > 5 && int.TryParse(text.AsSpan(5), out int waitMs) && waitMs > 0) | |
await Task.Delay(waitMs); | |
if (text == "break") | |
break; | |
if (text == "stop") | |
updateReceiver.StopReceiving(); | |
} | |
} | |
Console.WriteLine("Exited the loop"); | |
Console.ReadLine(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment