Skip to content

Commit

Permalink
v5.0.0 (#22)
Browse files Browse the repository at this point in the history
* InteractionService support + .NET 6 pass

* .NET 6 styling pass

* Update samples

* Fix github build

* Update README

* Minor typo

* Alpha release

* Improve InteractionHandler example

* Update README.md

* Fix wire-up typo

* Support passing shardids to the sharded client

* Version bump

* v3.0.0 Release

* Fix csproj formatting
  • Loading branch information
Hawxy authored Dec 19, 2021
1 parent 929cacd commit 249493c
Show file tree
Hide file tree
Showing 51 changed files with 1,619 additions and 1,088 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '5.0.x'
dotnet-version: '6.0.x'
- name: Install dependencies
run: dotnet restore
- name: Build
Expand Down
6 changes: 3 additions & 3 deletions Discord.Addons.Hosting.sln
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.28729.10
# Visual Studio Version 17
VisualStudioVersion = 17.1.31911.260
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Discord.Addons.Hosting", "Discord.Addons.Hosting\Discord.Addons.Hosting.csproj", "{03ED5619-5F9E-4CC6-8B8F-7D610C3169EB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Serilog", "Samples\SampleBotSerilog\Sample.Serilog.csproj", "{953BE7AC-019A-463C-900D-1346A384707E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Simple", "Samples\SampleBotSimple\Sample.Simple.csproj", "{E65C387F-9D99-4257-A458-1F6D5A4D80F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample.ShardedClient", "Samples\Sample.ShardedClient\Sample.ShardedClient.csproj", "{540A37B5-E304-49A4-B68E-08941C0D33F1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.ShardedClient", "Samples\Sample.ShardedClient\Sample.ShardedClient.csproj", "{540A37B5-E304-49A4-B68E-08941C0D33F1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
49 changes: 0 additions & 49 deletions Discord.Addons.Hosting/CommandServiceRegistrationHost.cs

This file was deleted.

25 changes: 10 additions & 15 deletions Discord.Addons.Hosting/Discord.Addons.Hosting.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.1;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<PackageId>Discord.Addons.Hosting</PackageId>
<Version>4.0.2</Version>
<Version>5.0.0</Version>
<Authors>Hawxy</Authors>
<Description>Simplifying Discord.Net hosting with .NET Generic Host (Microsoft.Extensions.Hosting)</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
Expand All @@ -12,27 +12,22 @@
<RepositoryUrl>https://github.com/Hawxy/Discord.Addons.Hosting</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageIcon>icon.png</PackageIcon>
<Copyright>Hawxy 2018-2021</Copyright>
<Copyright>Hawxy 2018-2022</Copyright>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>discord,discord.net,addon,hosting,microsoft.extensions.hosting</PackageTags>
<Nullable>Enable</Nullable>
<ImplicitUsings>Enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Discord.Net.Commands" Version="2.4.0" />
<PackageReference Include="Discord.Net.WebSocket" Version="2.4.0" />
<PackageReference Include="Discord.Net.Commands" Version="3.0.0" />
<PackageReference Include="Discord.Net.Interactions" Version="3.0.0" />
<PackageReference Include="Discord.Net.WebSocket" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.16" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net5.0' ">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Include="Images\icon.png" Pack="true" PackagePath="\" />
<ItemGroup>
<None Include="Images\icon.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
112 changes: 54 additions & 58 deletions Discord.Addons.Hosting/DiscordClientService.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#region License

/*
Copyright 2021 Hawxy
Copyright 2019-2022 Hawxy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -19,80 +19,76 @@ limitations under the License.
#endregion

using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;
using Discord.WebSocket;
using Microsoft.Extensions.Logging;

namespace Discord.Addons.Hosting
{
namespace Discord.Addons.Hosting;

/// <summary>
/// Base class for implementing an <see cref="DiscordClientService"/> with startup execution requirements. This class implements <see cref="BackgroundService"/>
/// </summary>
public abstract class DiscordServiceBase<T> : BackgroundService where T : BaseSocketClient
{
/// <summary>
/// Base class for implementing an <see cref="DiscordClientService"/> with startup execution requirements. This class implements <see cref="BackgroundService"/>
/// The running Discord.NET Client
/// </summary>
public abstract class DiscordServiceBase<T> : BackgroundService where T : BaseSocketClient
{
/// <summary>
/// The running Discord.NET Client
/// </summary>
protected T Client { get; }

/// <summary>
/// This service's logger
/// </summary>
protected ILogger Logger { get; }
protected T Client { get; }

/// <summary>
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordServiceBase(T client, ILogger logger)
{
Client = client;
Logger = logger;
}
/// <summary>
/// This service's logger
/// </summary>
protected ILogger Logger { get; }

/// <summary>
/// This method is called when the <see cref="IHostedService"/> starts. If the implementation is long-running, it should return a task that represents
/// the lifetime of the operation(s) being performed.
/// For more information, see <see href=" https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services#backgroundservice-base-class"/>
/// </summary>
/// <param name="stoppingToken">Triggered when <see cref="IHostedService.StopAsync(CancellationToken)"/> is called.</param>
/// <returns>A <see cref="Task"/> that represents the long running operations.</returns>
protected abstract override Task ExecuteAsync(CancellationToken stoppingToken);
/// <summary>
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordServiceBase(T client, ILogger logger)
{
Client = client;
Logger = logger;
}

/// <summary>
/// Base class for implementing an <see cref="DiscordClientService"/> for a <see cref="DiscordShardedClient"/> with startup execution requirements.
/// This class implements <see cref="BackgroundService"/> and should be registered in your service collection with `AddHostedService`
/// This method is called when the <see cref="IHostedService"/> starts. If the implementation is long-running, it should return a task that represents
/// the lifetime of the operation(s) being performed.
/// For more information, see <see href=" https://docs.microsoft.com/en-us/aspnet/core/fundamentals/host/hosted-services#backgroundservice-base-class"/>
/// </summary>
public abstract class DiscordClientService : DiscordServiceBase<DiscordSocketClient>
{
/// <summary>
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordClientService(DiscordSocketClient client, ILogger<DiscordClientService> logger) : base(client, logger)
{
}
/// <param name="stoppingToken">Triggered when <see cref="IHostedService.StopAsync(CancellationToken)"/> is called.</param>
/// <returns>A <see cref="Task"/> that represents the long running operations.</returns>
protected abstract override Task ExecuteAsync(CancellationToken stoppingToken);
}

/// <summary>
/// Base class for implementing an <see cref="DiscordClientService"/> for a <see cref="DiscordShardedClient"/> with startup execution requirements.
/// This class implements <see cref="BackgroundService"/> and should be registered in your service collection with `AddHostedService`
/// </summary>
public abstract class DiscordClientService : DiscordServiceBase<DiscordSocketClient>
{
/// <summary>
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordClientService(DiscordSocketClient client, ILogger<DiscordClientService> logger) : base(client, logger)
{
}

}

/// <summary>
/// Base class for implementing an <see cref="DiscordShardedClientService"/> for a <see cref="DiscordShardedClient"/> with startup execution requirements.
/// This class implements <see cref="BackgroundService"/> and should be registered in your service collection with `AddHostedService`
/// </summary>
public abstract class DiscordShardedClientService : DiscordServiceBase<DiscordShardedClient>
{
/// <summary>
/// Base class for implementing an <see cref="DiscordShardedClientService"/> for a <see cref="DiscordShardedClient"/> with startup execution requirements.
/// This class implements <see cref="BackgroundService"/> and should be registered in your service collection with `AddHostedService`
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
public abstract class DiscordShardedClientService : DiscordServiceBase<DiscordShardedClient>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordShardedClientService(DiscordShardedClient client, ILogger<DiscordShardedClientService> logger) : base(client, logger)
{
/// <summary>
/// Creates a new <see cref="DiscordClientService" />
/// </summary>
/// <param name="logger">The logger for this service</param>
/// <param name="client">The discord client</param>
protected DiscordShardedClientService(DiscordShardedClient client, ILogger<DiscordShardedClientService> logger) : base(client, logger)
{
}
}
}
Loading

0 comments on commit 249493c

Please sign in to comment.