Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Generic Host Implementation #32

Merged
merged 13 commits into from
Nov 16, 2024
Merged

.NET Generic Host Implementation #32

merged 13 commits into from
Nov 16, 2024

Conversation

HEJOK254
Copy link
Owner

@HEJOK254 HEJOK254 commented Sep 17, 2024

This PR introduces various features from the Microsoft.Extensions.Hosting NuGet package.

It also introduces a few minor bug fixes.

ToDo:

  • Handle config file errors (parse error, missing file) - done-ish
  • StopApplication on Authorization Error (wrong token etc.) - can't catch most of the exceptions in StartAsync(), as they're already being caught by the Discord .NET library, so only token validation and some other fatal exceptions are caught
  • Use IHostedService instead of a custom interface and singleton service for InteractionServiceHandler
    - [ ] Systemd integration
    - [ ] Check different host builders

Closes #28

Big commit, didn't really have the opportunity to break it up. It introduces various fixes, graceful shutdown, DI etc.

Probably going to get a few fixes/refactors

Implemented:
 - Dependency Injection
 - Generic Host
 - Configuration (Microsoft.Extensions.Configuration, switched from custom config)

Changed:
 - Split `Program.cs` into 2 files, `Program.cs` manages the program startup, while `Bot.cs` manages the bot's lifetime.
 - Removed the old configuration in favour of the Microsoft.Extensions.Configuration package
 - And more I think

Thanks to @Filip55561 for helping with the Host setup
@HEJOK254 HEJOK254 added the enhancement New feature or request label Sep 17, 2024
@HEJOK254 HEJOK254 added this to the 1.0 Release milestone Sep 17, 2024
@HEJOK254 HEJOK254 self-assigned this Sep 17, 2024
Copy link

deepsource-io bot commented Sep 17, 2024

Here's the code health analysis summary for commits c9e1603..7e06e1c. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource C# LogoC#✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

@HEJOK254 HEJOK254 marked this pull request as draft September 17, 2024 21:41
The program will now report an invalid token with a single log line and stop the application
@HEJOK254 HEJOK254 force-pushed the feature/generic-host branch from b4a9bd4 to 82aef8a Compare September 22, 2024 00:52
@HEJOK254 HEJOK254 marked this pull request as ready for review September 22, 2024 21:41
@HEJOK254
Copy link
Owner Author

Forgot to log in to my github account 💀

@HEJOK254 HEJOK254 force-pushed the feature/generic-host branch from 7d1aefe to c3ca7e1 Compare September 23, 2024 11:46
@HEJOK254
Copy link
Owner Author

HEJOK254 commented Sep 23, 2024

Not signed since I committed it from my phone

Gonna sign (by rebasing) when i get home

I just amended it instead lmao
No rebase 🥺

@HEJOK254 HEJOK254 force-pushed the feature/generic-host branch from c3ca7e1 to 498c0a4 Compare September 23, 2024 20:37
Copy link
Owner Author

@HEJOK254 HEJOK254 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good, only requiring a minor cleanup, though some testing should be done to confirm that everything works properly.

Commands/InteractionServiceHandler.cs Outdated Show resolved Hide resolved
Commands/InteractionServiceHandler.cs Outdated Show resolved Hide resolved
Logger/SerilogConfiguration.cs Show resolved Hide resolved
Config/ConfigManager.cs Outdated Show resolved Hide resolved
Config/DiscordConfig.cs Show resolved Hide resolved
InteractionServiceHandler now uses the IHostedService interface instead of a custom interface. This allows Bot.cs to not need to take care of the InteractionServiceHandler, as it can do it itself.
It now actually logs at least the type of error lol
Co-authored-by: Filip55561 <88946851+Filip55561@users.noreply.github.com>
@HEJOK254 HEJOK254 merged commit 32d8168 into dev Nov 16, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implement DI & Host Package
1 participant