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

25
.dockerignore Normal file
View File

@@ -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

5
.gitignore vendored Normal file
View File

@@ -0,0 +1,5 @@
bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/

13
.idea/.idea.NemesisAI/.idea/.gitignore generated vendored Normal file
View File

@@ -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

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

6
.idea/.idea.NemesisAI/.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

View File

@@ -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"

21
NemesisAI.sln Normal file
View File

@@ -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

1
TelegramBot/.env Normal file
View File

@@ -0,0 +1 @@
TELEGRAM_BOT_TOKEN=yourTokenHere

21
TelegramBot/Dockerfile Normal file
View File

@@ -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"]

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 "";
}

View File

@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>
<ItemGroup>
<Content Include="..\.dockerignore">
<Link>.dockerignore</Link>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
</ItemGroup>
</Project>

8
compose.yaml Normal file
View File

@@ -0,0 +1,8 @@
services:
telegrambot:
image: telegrambot
build:
context: .
dockerfile: TelegramBot/Dockerfile
env_file:
- TelegramBot/.env