Skip to content

Commit

Permalink
Develop (#45)
Browse files Browse the repository at this point in the history
* Refactoring

* Add EntityFramework

* Add Command handling

* Add Command handling

* Fix command handling

* Improve status check

* Add json property names to models

* Add Dockerfile

* Add webhook

* Update webhook system

* Refactoring

* Fix webhook message

* Remove unused file

* Add Discord logger

* Update status check service to order the results

* Refactoring

* Fix error handling in DiscordService

* Added authentication

* Update Discord logging

* Fix Discord logging

* Fix logging

* Update README.md

* Delete dotnet-build.yml

* Fix and improve status check (#8)

* Fix and improve status check

* Re-enabled Discord logging

* Update MacroBotApp.csproj

* Fix/fix member screening (#10)

* Update docker-deploy-production.yml

* Develop (#9)

* Refactoring

* Add EntityFramework

* Add Command handling

* Add Command handling

* Fix command handling

* Improve status check

* Add json property names to models

* Add Dockerfile

* Add webhook

* Update webhook system

* Refactoring

* Fix webhook message

* Remove unused file

* Add Discord logger

* Update status check service to order the results

* Refactoring

* Fix error handling in DiscordService

* Added authentication

* Update Discord logging

* Fix Discord logging

* Fix logging

* Update README.md

* Delete dotnet-build.yml

* Fix and improve status check (#8)

* Fix and improve status check

* Re-enabled Discord logging

* Update MacroBotApp.csproj

* Update docker-deploy-production.yml

* Fix Member-screening

* Minor improvements

* Merge main into develop (#13)

* Update docker-deploy-develop.yml

* Update docker-deploy-production.yml

* Develop (#11)

* Refactoring

* Add EntityFramework

* Add Command handling

* Add Command handling

* Fix command handling

* Improve status check

* Add json property names to models

* Add Dockerfile

* Add webhook

* Update webhook system

* Refactoring

* Fix webhook message

* Remove unused file

* Add Discord logger

* Update status check service to order the results

* Refactoring

* Fix error handling in DiscordService

* Added authentication

* Update Discord logging

* Fix Discord logging

* Fix logging

* Update README.md

* Delete dotnet-build.yml

* Fix and improve status check (#8)

* Fix and improve status check

* Re-enabled Discord logging

* Update MacroBotApp.csproj

* Fix/fix member screening (#10)

* Update docker-deploy-production.yml

* Develop (#9)

* Refactoring

* Add EntityFramework

* Add Command handling

* Add Command handling

* Fix command handling

* Improve status check

* Add json property names to models

* Add Dockerfile

* Add webhook

* Update webhook system

* Refactoring

* Fix webhook message

* Remove unused file

* Add Discord logger

* Update status check service to order the results

* Refactoring

* Fix error handling in DiscordService

* Added authentication

* Update Discord logging

* Fix Discord logging

* Fix logging

* Update README.md

* Delete dotnet-build.yml

* Fix and improve status check (#8)

* Fix and improve status check

* Re-enabled Discord logging

* Update MacroBotApp.csproj

* Update docker-deploy-production.yml

* Fix Member-screening

* Minor improvements

* Update MacroBotApp.csproj

* Update build.yml

* Update docker-deploy-production.yml

* Update build.yml

* Update docker-deploy-develop.yml

* Minor changes

* Remove glitched character

* Delete test.yml

* Fix message filter: replies can contain mentions now

* Minor improvements

* Changed loglevel of log messages in the BroadcastWebhookAsync method

* Implement old extension store API (and some other changes) (#7)

* Implement old extension store API

* Modified no mentions system, also created the starting point of the reports system

* Delete launch.json

* Delete tasks.json

* Delete launchSettings.json

* Update on Plugin Commands (and some extensions)

* Remove .gitignore

* Modify Plugin and PluginUtils

* PingBlocker improvments

* forgot to remove the logger thing

* removed reports

* Delete launchSettings.json

Co-authored-by: Manuel Mayer <[email protected]>

* Update docker-deploy-develop.yml (#17)

* Removed errors

* update plugin commands

* changes to the gitignore

* Update docker-deploy-develop.yml

* Update MacroBotApp.csproj

* Update dependency Serilog.Extensions.Hosting to v4.2.0 (#33)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency System.Data.SQLite to v1.0.117 (#32)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Octokit to v4.0.4 (#31)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update docker/login-action digest to 3da7dc6 (#28)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency AutoMapper to v12.0.1 (#29)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Newtonsoft.Json to v13.0.2 (#30)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dotnet monorepo (#38)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Serilog.Extensions.Hosting to v5 (#37)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Octokit to v5 (#36)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update microsoft/setup-msbuild action to v1.3.1 (#35)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Serilog.Sinks.Console to v4.1.0 (#34)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dotnet monorepo to v7.0.4 (#43)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update docker/login-action digest to 219c305 (#39)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update appleboy/ssh-action action to v0.1.8 (#40)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Update dependency Newtonsoft.Json to v13.0.3 (#41)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* Improve status check (#44)

* Update dependency Octokit to v5.0.2 (#42)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

---------

Co-authored-by: JB Carreon <[email protected]>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 19, 2023
1 parent ee2b48d commit d1463f8
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:

# Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild
- name: Setup MSBuild.exe
uses: microsoft/setup-msbuild@v1.0.2
uses: microsoft/setup-msbuild@v1.3.1

# Execute all unit tests in the solution
- name: Execute unit tests
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-deploy-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build the Docker image
run: docker build . --file MacroBotApp/Dockerfile --tag suchbyte/macro-bot:dev_${{ github.sha }}
- name: Log into registry
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@219c305e1ce92a755f3aa4ba17387c95df31e987
with:
registry: docker.io
username: suchbyte
Expand All @@ -40,7 +40,7 @@ jobs:
customHeaders: '{"Content-Type": "application/json" }'
data: '{"toEveryone":false,"embed":{"color":{"r":0,"g":1,"b":0},"description":"Push successful, updating the container now...","fields":[{"name":"SHA","value":"${{ github.sha }}","inline":false}]}}'
- name: Updating the image on the server
uses: appleboy/[email protected].7
uses: appleboy/[email protected].8
with:
host: ${{ secrets.DOCKER_HOST }}
username: ${{ secrets.GITHUBWORKFLOWS_USER }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/docker-deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ jobs:
- name: Build the Docker image
run: docker build . --file MacroBotApp/Dockerfile --tag suchbyte/macro-bot:${{steps.get-version.outputs.version}}
- name: Log into registry ${{ env.REGISTRY }}
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
uses: docker/login-action@219c305e1ce92a755f3aa4ba17387c95df31e987
with:
registry: docker.io
username: suchbyte
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push the Docker image
run: docker push suchbyte/macro-bot:${{steps.get-version.outputs.version}}
- name: Updating the image on the server
uses: appleboy/[email protected].7
uses: appleboy/[email protected].8
with:
host: ${{ secrets.DOCKER_HOST }}
username: ${{ secrets.GITHUBWORKFLOWS_USER }}
Expand Down
20 changes: 10 additions & 10 deletions MacroBotApp/MacroBotApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.0" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="Discord.Net" Version="3.9.0" />
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.2">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Octokit" Version="4.0.3" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Octokit" Version="5.0.2" />
<PackageReference Include="Serilog" Version="2.12.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.2" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="6.5.0" />
<PackageReference Include="System.Data.SQLite" Version="1.0.116" />
<PackageReference Include="System.Data.SQLite" Version="1.0.117" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions MacroBotApp/ServiceInterfaces/ITimerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public interface ITimerService
public event EventHandler DailyTimerElapsed;
public event EventHandler HourTimerElapsed;
public event EventHandler MinuteTimerElapsed;
public event EventHandler FiveMinuteTimerElapsed;
}
1 change: 0 additions & 1 deletion MacroBotApp/Services/DiscordService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ private async Task DiscordSocketClientOnButtonExecuted(SocketMessageComponent co

private async Task Ready () {
DiscordReady = true;
_logger.Information("Bot ready");
await _interactionService.RegisterCommandsGloballyAsync();
var guild = _discordSocketClient.GetGuild(_botConfig.GuildId);
if (guild?.GetChannel(_botConfig.Channels.MemberScreeningChannelId) is ITextChannel channel)
Expand Down
33 changes: 14 additions & 19 deletions MacroBotApp/Services/StatusCheckService.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Concurrent;
using System.Net;
using System.Text.Json;
using Discord.WebSocket;
Expand Down Expand Up @@ -41,14 +42,14 @@ public StatusCheckService(IHttpClientFactory httpClientFactory,

public Task StartAsync(CancellationToken cancellationToken)
{
_timerService.MinuteTimerElapsed += TimerServiceOnMinuteTimerElapsed;
_timerService.FiveMinuteTimerElapsed += TimerServiceOnTimerElapsed;
_discordSocketClient.Ready += DiscordSocketClientOnReady;
return Task.CompletedTask;
}

public Task StopAsync(CancellationToken cancellationToken)
{
_timerService.MinuteTimerElapsed -= TimerServiceOnMinuteTimerElapsed;
_timerService.FiveMinuteTimerElapsed -= TimerServiceOnTimerElapsed;
return Task.CompletedTask;
}

Expand All @@ -57,7 +58,7 @@ private async Task DiscordSocketClientOnReady()
await CheckAllAsync();
}

private async void TimerServiceOnMinuteTimerElapsed(object? sender, EventArgs e)
private async void TimerServiceOnTimerElapsed(object? sender, EventArgs e)
{
await CheckAllAsync();
}
Expand All @@ -70,27 +71,21 @@ private async Task CheckAllAsync()
}
_lastCheckDone = false;
_logger.Verbose("Starting status check...");
var results = new List<StatusCheckResult>();
var results = new ConcurrentBag<StatusCheckResult>();
var lastResults = LastStatusCheckResults?.ToArray();
foreach (var statusCheckItem in _statusCheckConfig.StatusCheckItems)
ParallelOptions parallelOptions = new()
{
MaxDegreeOfParallelism = 3
};
await Parallel.ForEachAsync(_statusCheckConfig.StatusCheckItems, parallelOptions, async (statusCheckItem, token) =>
{
var lastResult = lastResults?.FirstOrDefault(x => x.Name.Equals(statusCheckItem.Name));
var result = await CheckAsync(statusCheckItem, lastResult);
if (result.StateChanged)
{
StatusOfItemChanged?.Invoke(result, EventArgs.Empty);
if (!result.Online)
{
_logger.Fatal("{Url} is offline! StatusCode: {StatusCode}", statusCheckItem.Url, result.StatusCode);
} else if (result.OnlineWithWarnings)
{
_logger.Error("{Url} is online with warnings! StatusCode: {StatusCode}", statusCheckItem.Url, result.StatusCode);
}
}

results.Add(result);
}
});

results = new List<StatusCheckResult>(results.OrderByDescending(x => x.Name));
results = new ConcurrentBag<StatusCheckResult>(results.OrderByDescending(x => x.Name));

_logger.Verbose(
"Status check done. {NoOnline}/{Total} online {NoWarnings} with warnings",
Expand Down Expand Up @@ -121,7 +116,7 @@ private async Task<StatusCheckResult> CheckAsync(StatusCheckConfig.StatusCheckIt
statusCheckItem.Name,
statusCheckItem.Url);
using var httpClient = _httpClientFactory.CreateClient();
httpClient.Timeout = TimeSpan.FromSeconds(20);
httpClient.Timeout = TimeSpan.FromSeconds(60);
var onlineWithWarnings = false;
bool online;
HttpResponseMessage? request = null;
Expand Down
10 changes: 9 additions & 1 deletion MacroBotApp/Services/TimerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public class TimerService : ITimerService, IHostedService
public event EventHandler? DailyTimerElapsed;
public event EventHandler? HourTimerElapsed;
public event EventHandler? MinuteTimerElapsed;
public event EventHandler? FiveMinuteTimerElapsed;


private DateTime _hourTimerLastElapsed = default;
private DateTime _dailyTimerLastElapsed = default;
Expand Down Expand Up @@ -44,7 +46,13 @@ private void TimerOnElapsed(object? sender, ElapsedEventArgs e)
{
_logger.Verbose("Minute timer elapsed");
MinuteTimerElapsed?.Invoke(this, EventArgs.Empty);
if (DateTime.Now - _hourTimerLastElapsed >= TimeSpan.FromMinutes(1))
if (DateTime.Now - _hourTimerLastElapsed >= TimeSpan.FromMinutes(5))
{
_logger.Verbose("5 Minute timer elapsed");
HourTimerElapsed?.Invoke(this, EventArgs.Empty);
_hourTimerLastElapsed = DateTime.Now;
}
if (DateTime.Now - _hourTimerLastElapsed >= TimeSpan.FromHours(1))
{
_logger.Verbose("Hour timer elapsed");
HourTimerElapsed?.Invoke(this, EventArgs.Empty);
Expand Down

0 comments on commit d1463f8

Please sign in to comment.