commit 0ba298b955b6a8f3f18647611b3a63372efea473 Author: Samuele Lorefice Date: Tue Dec 24 23:08:08 2024 +0100 Base commit diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..38bece4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,25 @@ +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.idea +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/azds.yaml +**/bin +**/charts +**/docker-compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..add57be --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +bin/ +obj/ +/packages/ +riderModule.iml +/_ReSharper.Caches/ \ No newline at end of file diff --git a/.idea/.idea.NemesisAI/.idea/.gitignore b/.idea/.idea.NemesisAI/.idea/.gitignore new file mode 100644 index 0000000..43d9b02 --- /dev/null +++ b/.idea/.idea.NemesisAI/.idea/.gitignore @@ -0,0 +1,13 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/contentModel.xml +/modules.xml +/projectSettingsUpdater.xml +/.idea.NemesisAI.iml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.idea.NemesisAI/.idea/encodings.xml b/.idea/.idea.NemesisAI/.idea/encodings.xml new file mode 100644 index 0000000..df87cf9 --- /dev/null +++ b/.idea/.idea.NemesisAI/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.NemesisAI/.idea/indexLayout.xml b/.idea/.idea.NemesisAI/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/.idea/.idea.NemesisAI/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NemesisAI/.idea/vcs.xml b/.idea/.idea.NemesisAI/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.NemesisAI/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.NemesisAI/Docker/compose.generated.override.yml b/.idea/.idea.NemesisAI/Docker/compose.generated.override.yml new file mode 100644 index 0000000..9450ecb --- /dev/null +++ b/.idea/.idea.NemesisAI/Docker/compose.generated.override.yml @@ -0,0 +1,37 @@ +# This is a generated file. Not intended for manual editing. +services: + telegrambot: + build: + context: "/home/redcode/dev/NemesisAI" + dockerfile: "TelegramBot/Dockerfile" + target: "base" + args: + BUILD_CONFIGURATION: "Debug" + command: [] + entrypoint: + - "/opt/JetBrains/RiderDebuggerTools/linux-x64/JetBrains.Debugger.Worker" + - "--runtimeconfig" + - "/opt/JetBrains/RiderDebuggerTools/JetBrains.Debugger.Worker.runtimeconfig.json" + - "--mode=server" + - "--frontend-port=57000" + - "--backend-port=57200" + - "--roslyn-worker-port=57400" + - "--timeout=60" + environment: + DOTNET_ENVIRONMENT: "Development" + DOTNET_USE_POLLING_FILE_WATCHER: "true" + RIDER_DEBUGGER_LOG_DIR: "/var/opt/JetBrains/RiderDebuggerTools" + RESHARPER_LOG_CONF: "/etc/opt/JetBrains/RiderDebuggerTools/backend-log.xml" + image: "telegrambot:dev" + ports: + - "127.0.0.1:57000:57000" + - "127.0.0.1:57200:57200" + - "127.0.0.1:57400:57400" + volumes: + - "/home/redcode/dev/NemesisAI/TelegramBot:/app:rw" + - "/home/redcode/dev/NemesisAI:/src:rw" + - "/home/redcode/.nuget/packages:/home/app/.nuget/packages" + - "/home/redcode/.local/share/JetBrains/RiderRemoteDebugger/2024.3.2/Linux64:/opt/JetBrains/RiderDebuggerTools" + - "/home/redcode/.local/share/JetBrains/Toolbox/apps/rider/bin/backend-log.xml:/etc/opt/JetBrains/RiderDebuggerTools/backend-log.xml" + - "/home/redcode/.cache/JetBrains/Rider2024.3/log/DebuggerWorker/JetBrains.Debugger.Worker.2024_12_24_23_05_14:/var/opt/JetBrains/RiderDebuggerTools:rw" + working_dir: "/app" diff --git a/NemesisAI.sln b/NemesisAI.sln new file mode 100644 index 0000000..b46483d --- /dev/null +++ b/NemesisAI.sln @@ -0,0 +1,21 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelegramBot", "TelegramBot\TelegramBot.csproj", "{CE233EFF-F841-40E5-94AB-0ADBE918E0BA}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C9A5F05-7CED-450F-9757-C641D75F8787}" + ProjectSection(SolutionItems) = preProject + compose.yaml = compose.yaml + EndProjectSection +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CE233EFF-F841-40E5-94AB-0ADBE918E0BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE233EFF-F841-40E5-94AB-0ADBE918E0BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE233EFF-F841-40E5-94AB-0ADBE918E0BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE233EFF-F841-40E5-94AB-0ADBE918E0BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/TelegramBot/.env b/TelegramBot/.env new file mode 100644 index 0000000..e13bb4b --- /dev/null +++ b/TelegramBot/.env @@ -0,0 +1 @@ +TELEGRAM_BOT_TOKEN=yourTokenHere \ No newline at end of file diff --git a/TelegramBot/Dockerfile b/TelegramBot/Dockerfile new file mode 100644 index 0000000..3b281c0 --- /dev/null +++ b/TelegramBot/Dockerfile @@ -0,0 +1,21 @@ +FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base +USER $APP_UID +WORKDIR /app + +FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build +ARG BUILD_CONFIGURATION=Release +WORKDIR /src +COPY ["TelegramBot/TelegramBot.csproj", "TelegramBot/"] +RUN dotnet restore "TelegramBot/TelegramBot.csproj" +COPY . . +WORKDIR "/src/TelegramBot" +RUN dotnet build "TelegramBot.csproj" -c $BUILD_CONFIGURATION -o /app/build + +FROM build AS publish +ARG BUILD_CONFIGURATION=Release +RUN dotnet publish "TelegramBot.csproj" -c $BUILD_CONFIGURATION -o /app/publish + +FROM base AS final +WORKDIR /app +COPY --from=publish /app/publish . +ENTRYPOINT ["dotnet", "TelegramBot.dll"] diff --git a/TelegramBot/Program.cs b/TelegramBot/Program.cs new file mode 100644 index 0000000..27732ed --- /dev/null +++ b/TelegramBot/Program.cs @@ -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 ""; +} \ No newline at end of file diff --git a/TelegramBot/TelegramBot.csproj b/TelegramBot/TelegramBot.csproj new file mode 100644 index 0000000..c7be57f --- /dev/null +++ b/TelegramBot/TelegramBot.csproj @@ -0,0 +1,21 @@ + + + + Exe + net8.0 + enable + enable + Linux + + + + + .dockerignore + + + + + + + + diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..7e86570 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,8 @@ +services: + telegrambot: + image: telegrambot + build: + context: . + dockerfile: TelegramBot/Dockerfile + env_file: + - TelegramBot/.env \ No newline at end of file