diff --git a/Program.cs b/Program.cs index 9544d44..9521d41 100644 --- a/Program.cs +++ b/Program.cs @@ -4,17 +4,18 @@ using Telegram.Bot.Types.Enums; var token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN")!; -var bot = new TelegramBotClient(token); -var me = await bot.GetMeAsync(); using var cts = new CancellationTokenSource(); +var bot = new TelegramBotClient(token); +var me = await bot.GetMeAsync(); + await bot.SetMyCommandsAsync(new[] { - new BotCommand { Command = "help", Description = "Lists all commands" }, new BotCommand { Command = "coinflip", Description = "Flips a coin" }, new BotCommand { Command = "shouldi", Description = "Tells you if you should or shouldn't do something" }, new BotCommand { Command = "yesno", Description = "Answes binary questions" }, new BotCommand { Command = "makedecision", Description = "Makes a decision. Expects a list of comma separated options." }, new BotCommand { Command = "choose", Description = "Chooses an item. Expects a list of comma separated options." }, + new BotCommand { Command = "help", Description = "Lists all commands" }, }); var iBotCommands = new List { @@ -39,10 +40,10 @@ Task PollingErrorHandler(ITelegramBotClient ibot, Exception ex, CancellationToke async Task HandleUpdateAsync(ITelegramBotClient ibot, Update update, CancellationToken ct) { try { - await (update.Type switch { - UpdateType.Message => BotOnMessageReceived(ibot, update.Message!), - _ => Task.CompletedTask - }); + if (update.Type != UpdateType.Message) + return; + + await BotOnMessageReceived(ibot, update.Message!); } catch (Exception ex) { Console.WriteLine($"Exception while handling {update.Type}: {ex}"); @@ -116,7 +117,7 @@ async Task BotOnMessageReceived(ITelegramBotClient botClient, Message message) { await botClient.SendTextMessageAsync(message.Chat.Id, RandomOption(options).Trim(), replyToMessageId: message.MessageId); break; case "help": - case "start": + case "start": await botClient.SendTextMessageAsync(message.Chat.Id, """ Heya, I am a bot that can help you make decisions! Here's a list of things I can do: