Code cleanup
This commit is contained in:
parent
b9c43550aa
commit
ada850dc05
15
Program.cs
15
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<string> {
|
||||
|
@ -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}");
|
||||
|
|
Loading…
Reference in a new issue