diff --git a/DisCatSharp.Hosting/DiscordHostedService.cs b/DisCatSharp.Hosting/DiscordHostedService.cs
index e063f22d3..16b5ff5f2 100644
--- a/DisCatSharp.Hosting/DiscordHostedService.cs
+++ b/DisCatSharp.Hosting/DiscordHostedService.cs
@@ -1,85 +1,79 @@
// This file is part of the DisCatSharp project, a fork of DSharpPlus.
//
// Copyright (c) 2021 AITSYS
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Threading.Tasks;
using DisCatSharp.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace DisCatSharp.Hosting
{
///
/// Simple implementation for to work as a
///
public abstract class DiscordHostedService : BaseHostedService, IDiscordHostedService
{
///
public DiscordClient Client { get; protected set; }
#pragma warning disable 8618
/// IConfiguration provided via Dependency Injection. Aggregate method to access configuration files
/// An ILogger to work with, provided via Dependency Injection
/// ServiceProvider reference which contains all items currently registered for Dependency Injection
/// Contains the appropriate methods for disposing / stopping BackgroundServices during runtime
/// The name of the JSON/Config Key which contains the configuration for this Discord Service
protected DiscordHostedService(IConfiguration config,
ILogger logger,
IServiceProvider serviceProvider,
IHostApplicationLifetime applicationLifetime,
string configBotSection = DisCatSharp.Configuration.ConfigurationExtensions.DefaultRootLib)
: base(config, logger, serviceProvider, applicationLifetime, configBotSection)
{
}
#pragma warning restore 8618
- ///
- /// When the bot fails to start, this method will be invoked. (Default behavior is to shutdown)
- ///
- /// The exception/reason the bot couldn't start
- protected virtual void OnInitializationError(Exception ex) => this.ApplicationLifetime.StopApplication();
-
protected override Task ConfigureAsync()
{
try
{
this.Client = this.Configuration.BuildClient(this.ServiceProvider, this.BotSection);
}
catch (Exception ex)
{
this.Logger.LogError($"Was unable to build {nameof(DiscordClient)} for {this.GetType().Name}");
this.OnInitializationError(ex);
}
return Task.CompletedTask;
}
protected sealed override async Task ConnectAsync() => await this.Client.ConnectAsync();
protected override Task ConfigureExtensionsAsync()
{
this.InitializeExtensions(this.Client);
return Task.CompletedTask;
}
}
}