Code cleanup
This commit is contained in:
parent
b9c43550aa
commit
ada850dc05
17
Program.cs
17
Program.cs
|
@ -4,17 +4,18 @@ using Telegram.Bot.Types.Enums;
|
||||||
|
|
||||||
var token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN")!;
|
var token = Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN")!;
|
||||||
|
|
||||||
var bot = new TelegramBotClient(token);
|
|
||||||
var me = await bot.GetMeAsync();
|
|
||||||
using var cts = new CancellationTokenSource();
|
using var cts = new CancellationTokenSource();
|
||||||
|
|
||||||
|
var bot = new TelegramBotClient(token);
|
||||||
|
var me = await bot.GetMeAsync();
|
||||||
|
|
||||||
await bot.SetMyCommandsAsync(new[] {
|
await bot.SetMyCommandsAsync(new[] {
|
||||||
new BotCommand { Command = "help", Description = "Lists all commands" },
|
|
||||||
new BotCommand { Command = "coinflip", Description = "Flips a coin" },
|
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 = "shouldi", Description = "Tells you if you should or shouldn't do something" },
|
||||||
new BotCommand { Command = "yesno", Description = "Answes binary questions" },
|
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 = "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 = "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> {
|
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) {
|
async Task HandleUpdateAsync(ITelegramBotClient ibot, Update update, CancellationToken ct) {
|
||||||
try {
|
try {
|
||||||
await (update.Type switch {
|
if (update.Type != UpdateType.Message)
|
||||||
UpdateType.Message => BotOnMessageReceived(ibot, update.Message!),
|
return;
|
||||||
_ => Task.CompletedTask
|
|
||||||
});
|
await BotOnMessageReceived(ibot, update.Message!);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
Console.WriteLine($"Exception while handling {update.Type}: {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);
|
await botClient.SendTextMessageAsync(message.Chat.Id, RandomOption(options).Trim(), replyToMessageId: message.MessageId);
|
||||||
break;
|
break;
|
||||||
case "help":
|
case "help":
|
||||||
case "start":
|
case "start":
|
||||||
await botClient.SendTextMessageAsync(message.Chat.Id, """
|
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:
|
Heya, I am a bot that can help you make decisions! Here's a list of things I can do:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue