Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
build/
**/bin/
**/obj/
20 changes: 10 additions & 10 deletions src/NosCoreBot/NosCoreBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.S3" Version="4.0.21.2" />
<PackageReference Include="AWSSDK.S3" Version="4.0.102.1" />
<PackageReference Include="ConsoleTableExt" Version="3.3.0" />
<PackageReference Include="Discord.Net" Version="3.19.1" />
<PackageReference Include="Discord.Net" Version="3.20.1" />
<PackageReference Include="Humanizer.Core" Version="3.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.6" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.6" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.17.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.17.0" />
<PackageReference Include="NosCore.ParserInputGenerator" Version="3.0.0" />
<PackageReference Include="NosCore.Shared" Version="5.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.11" />
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="10.0.11" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.22.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.22.0" />
<PackageReference Include="NosCore.ParserInputGenerator" Version="4.1.0" />
<PackageReference Include="NosCore.Shared" Version="6.0.0" />
</ItemGroup>

</Project>
</Project>
5 changes: 3 additions & 2 deletions src/NosCoreBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ public static IHostBuilder CreateHostBuilder(string[] args)
.UseWindowsService()
.ConfigureServices((hostContext, services) =>
{
var runOnce = Environment.GetEnvironmentVariable("RUN_ONCE") == "true";
services.AddSingleton(new DiscordSocketClient(new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
GatewayIntents = GatewayIntents.All
AlwaysDownloadUsers = !runOnce,
GatewayIntents = runOnce ? GatewayIntents.Guilds : GatewayIntents.All
}))
.AddHttpClient()
.AddTransient<IExtractor, Extractor>()
Expand Down
2 changes: 1 addition & 1 deletion src/NosCoreBot/Services/TimeHandlingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ await Task.WhenAll(fileslist.Select(file =>
if (_discord.GetChannel(719772084968095775) is SocketTextChannel channel)
{
var file = new FileInfo(archiveName);
if (file.Length > 8388119)
if ((ulong)file.Length > channel.Guild.MaxUploadLimit)
{
var send = await channel.SendMessageAsync($"<:altz:699420721088168036><:altz:699420721088168036><:altz:699420721088168036>Parser Too Heavy<:altz:699420721088168036><:altz:699420721088168036><:altz:699420721088168036>\n - Size : {file.Length}");
}
Expand Down
28 changes: 26 additions & 2 deletions src/NosCoreBot/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,53 @@ public class Worker : BackgroundService
private readonly CommandService _cmservice;
private readonly CommandHandlingService _chservice;
private readonly TimeHandlingService _thservice;
private readonly IHostApplicationLifetime _lifetime;

public Worker(DiscordSocketClient client, CommandService cmservice, CommandHandlingService chservice,
TimeHandlingService thservice)
TimeHandlingService thservice, IHostApplicationLifetime lifetime)
{
_client = client;
_cmservice = cmservice;
_chservice = chservice;
_thservice = thservice;
_lifetime = lifetime;
}

protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
_client.Log += LogAsync;
_cmservice.Log += LogAsync;

var ready = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
_client.Ready += () =>
{
ready.TrySetResult();
return Task.CompletedTask;
};

// Tokens should be considered secret data, and never hard-coded.
await _client.LoginAsync(TokenType.Bot, Environment.GetEnvironmentVariable("token"));
await _client.StartAsync();
await ready.Task.WaitAsync(TimeSpan.FromMinutes(2), stoppingToken);

if (Environment.GetEnvironmentVariable("RUN_ONCE") == "true")
{
try
{
await _thservice.UploadInputFilesAsync();
}
finally
{
await _client.StopAsync();
_lifetime.StopApplication();
}
return;
}

await _chservice.InitializeAsync();
await _thservice.UploadInputFilesAsync();

await Task.Delay(-1);
await Task.Delay(-1, stoppingToken);
}

private Task LogAsync(LogMessage log)
Expand Down
12 changes: 7 additions & 5 deletions src/NosCoreBot/dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /dotnetapp

COPY . /app
WORKDIR /app/build/net7.0
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
WORKDIR /src
COPY . .
RUN dotnet publish src/NosCoreBot/NosCoreBot.csproj -c Release -o /app/publish

FROM mcr.microsoft.com/dotnet/aspnet:10.0
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "NosCoreBot.dll"]
6 changes: 3 additions & 3 deletions tests/NosCoreBot.Tests/NosCoreBot.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="4.2.1" />
<PackageReference Include="MSTest.TestFramework" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.8.1" />
<PackageReference Include="MSTest.TestAdapter" Version="4.3.3" />
<PackageReference Include="MSTest.TestFramework" Version="4.3.3" />
</ItemGroup>

</Project>
Loading