Base commit

This commit is contained in:
Samuele Lorefice
2024-12-24 23:08:08 +01:00
commit 0ba298b955
13 changed files with 201 additions and 0 deletions

31
TelegramBot/Program.cs Normal file
View File

@@ -0,0 +1,31 @@
using Telegram.Bot;
using Telegram.Bot.Types;
using Telegram.Bot.Types.Enums;
using var cts = new CancellationTokenSource();
var bot = new TelegramBotClient(Environment.GetEnvironmentVariable("TELEGRAM_BOT_TOKEN"), cancellationToken:cts.Token);
var me = bot.GetMe();
bot.OnMessage += OnMessage;
Console.ReadLine();
cts.Cancel();
async Task OnMessage(Message msg, UpdateType type)
{
//Discard any message that is not a text message
if (msg.Type != MessageType.Text) return;
//Check if the message contains the bot's username
if (msg.Text!.Contains(me.Result.Username!, StringComparison.OrdinalIgnoreCase))
await bot.SendMessage(msg.Chat, "You mentioned me!");
//Check if the message is a reply to a message sent by the bot
else if(msg.ReplyToMessage != null && msg.ReplyToMessage.From!.Id == me.Result.Id){
await bot.SendMessage(msg.Chat, "You replied to a message!");
}
//We can safely return otherwise
}
HttpClient AiClient = new HttpClient();
string getNemesisMsg() {
//AiClient.GetAsync()
return "";
}