Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
NyuwBot committed Jan 3, 2024
2 parents cb7bb1d + 3335871 commit 1c0f92a
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 45 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ on:
description: "Release as pre-release"
required: true
type: boolean
default: true
confirm_full_release:
description: "Confirm that you want to release as a full release"
required: false
type: boolean
default: false

env:
DOTNET_NOLOGO: true
Expand All @@ -29,6 +35,13 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check Intention
if: ${{!inputs.release_as_prerelease}}
run: |
if [ "${{ inputs.confirm_full_release }}" = "false" ]; then
echo "Full release not confirmed, exiting."
exit 1
fi
- name: Setup .NET
uses: actions/[email protected]
with:
Expand Down Expand Up @@ -64,7 +77,7 @@ jobs:
- name: Set outputs
id: vars
run: |
echo "version=10.5.0" >> $GITHUB_OUTPUT
echo "version=10.5.1" >> $GITHUB_OUTPUT
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: "Create Sentry prod release"
if: ${{!inputs.release_as_prerelease}}
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp.Attributes/DisCatSharp.Attributes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<OutputType>Library</OutputType>
<Version>10.5.0</Version>
<Version>10.5.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp.Docs/changelogs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ author: DisCatSharp Team

Please select the changelog you want to view from the left side.

Current: [v10.5.0](xref:changelogs_v10_10_5_0)
Current: [v10.5.1](xref:changelogs_v10_10_5_1)
4 changes: 2 additions & 2 deletions DisCatSharp.Docs/changelogs/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ items:
- name: Version 10.X
expanded: true
items:
- name: Version 10.5.0
href: v10/10_5_0.md
- name: Version 10.5.1
href: v10/10_5_1.md
- name: Version 10.4.0
href: v10/10_4_0.md
- name: Version 10.3.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
uid: changelogs_v10_10_5_0
title: Version 10.5.0
uid: changelogs_v10_10_5_1
title: Version 10.5.1
author: DisCatSharp Team
---

# Upgrade from **10.4.0** to **10.5.0**
# Upgrade from **10.4.0** to **10.5.1**

<br/>

Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp.Docs/dcs/_redirects
Original file line number Diff line number Diff line change
@@ -1 +1 @@
/changelogs/latest /changelogs/v10/10_5_0 303
/changelogs/latest /changelogs/v10/10_5_1 303
2 changes: 1 addition & 1 deletion DisCatSharp.Targets/Version.targets
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VersionPrefix>10.5.0</VersionPrefix>
<VersionPrefix>10.5.1</VersionPrefix>
</PropertyGroup>
<PropertyGroup Condition="'$(VersionSuffix)' != '' And '$(BuildNumber)' != ''">
<Version>$(VersionPrefix)-$(VersionSuffix)-$(BuildNumber)</Version>
Expand Down
3 changes: 1 addition & 2 deletions DisCatSharp/DisCatSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Protocol" Version="6.8.0" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="Octokit" Version="9.1.0" />
<PackageReference Include="Sentry" Version="3.41.3" />
<PackageReference Include="Sentry.Extensions.Logging" Version="3.41.3" />
<PackageReference Include="System.Memory" Version="4.5.5" />
Expand All @@ -57,7 +57,6 @@
<Folder Include="Entities\Interaction\Components\Attachment\" />
<Folder Include="Entities\Interaction\Components\DateTime\" />
<Folder Include="Entities\Interaction\Components\Radio\" />
<Folder Include="Ascii\" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 17 additions & 11 deletions DisCatSharp/Net/Rest/DiscordApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,14 +202,15 @@ private void PopulateMessage(TransportUser author, DiscordMessage ret)
/// <param name="headers">The headers.</param>
/// <param name="payload">The payload.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary<string, string>? headers = null, string? payload = null, double? ratelimitWaitOverride = null)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, IReadOnlyDictionary<string, string>? headers = null, string? payload = null, double? ratelimitWaitOverride = null, bool targetDebug = false)
{
var req = new RestRequest(client, bucket, url, method, route, headers, payload, ratelimitWaitOverride);

if (this.Discord is not null)
this.Rest.ExecuteRequestAsync(req).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}");
this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}");
else
_ = this.Rest.ExecuteRequestAsync(req);
_ = this.Rest.ExecuteRequestAsync(req, targetDebug);

return req.WaitForCompletionAsync();
}
Expand All @@ -225,11 +226,12 @@ internal Task<RestResponse> DoRequestAsync(BaseDiscordClient client, RateLimitBu
/// <param name="headers">The headers.</param>
/// <param name="formData">The form data.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary<string, string> formData, Dictionary<string, string>? headers = null, double? ratelimitWaitOverride = null)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateLimitBucket bucket, Uri url, RestRequestMethod method, string route, Dictionary<string, string> formData, Dictionary<string, string>? headers = null, double? ratelimitWaitOverride = null, bool targetDebug = false)
{
var req = new RestFormRequest(client, bucket, url, method, route, formData, headers, ratelimitWaitOverride);

this.Rest.ExecuteFormRequestAsync(req).LogTaskFault(this.OAuth2Client.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}");
this.Rest.ExecuteFormRequestAsync(req, targetDebug).LogTaskFault(this.OAuth2Client.Logger, LogLevel.Error, LoggerEvents.RestError, $"Error while executing request. Url: {url.AbsoluteUri}");

return req.WaitForCompletionAsync();
}
Expand All @@ -248,6 +250,7 @@ internal Task<RestResponse> DoFormRequestAsync(DiscordOAuth2Client client, RateL
/// <param name="headers">The headers.</param>
/// <param name="file">The file.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private Task<RestResponse> DoStickerMultipartAsync(
BaseDiscordClient client,
RateLimitBucket bucket,
Expand All @@ -259,15 +262,16 @@ private Task<RestResponse> DoStickerMultipartAsync(
string? description = null,
IReadOnlyDictionary<string, string>? headers = null,
DiscordMessageFile? file = null,
double? ratelimitWaitOverride = null
double? ratelimitWaitOverride = null,
bool targetDebug = false
)
{
var req = new MultipartStickerWebRequest(client, bucket, url, method, route, name, tags, description, headers, file, ratelimitWaitOverride);

if (this.Discord is not null)
this.Rest.ExecuteRequestAsync(req).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request");
this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request");
else
_ = this.Rest.ExecuteRequestAsync(req);
_ = this.Rest.ExecuteRequestAsync(req, targetDebug);

return req.WaitForCompletionAsync();
}
Expand All @@ -284,6 +288,7 @@ private Task<RestResponse> DoStickerMultipartAsync(
/// <param name="values">The values.</param>
/// <param name="files">The files.</param>
/// <param name="ratelimitWaitOverride">The ratelimit wait override.</param>
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private Task<RestResponse> DoMultipartAsync(
BaseDiscordClient client,
RateLimitBucket bucket,
Expand All @@ -293,15 +298,16 @@ private Task<RestResponse> DoMultipartAsync(
IReadOnlyDictionary<string, string>? headers = null,
IReadOnlyDictionary<string, string>? values = null,
IEnumerable<DiscordMessageFile>? files = null,
double? ratelimitWaitOverride = null
double? ratelimitWaitOverride = null,
bool targetDebug = false
)
{
var req = new MultipartWebRequest(client, bucket, url, method, route, headers, values, files, ratelimitWaitOverride);

if (this.Discord is not null)
this.Rest.ExecuteRequestAsync(req).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request");
this.Rest.ExecuteRequestAsync(req, targetDebug).LogTaskFault(this.Discord.Logger, LogLevel.Error, LoggerEvents.RestError, "Error while executing request");
else
_ = this.Rest.ExecuteRequestAsync(req);
_ = this.Rest.ExecuteRequestAsync(req, targetDebug);

return req.WaitForCompletionAsync();
}
Expand Down
36 changes: 20 additions & 16 deletions DisCatSharp/Net/Rest/RestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,17 @@ public RateLimitBucket GetBucket(RestRequestMethod method, string route, object
/// Executes the request.
/// </summary>
/// <param name="request">The request to be executed.</param>
public Task ExecuteRequestAsync(BaseRestRequest request)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteRequestAsync(request, null, null);
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
public Task ExecuteRequestAsync(BaseRestRequest request, bool targetDebug = false)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteRequestAsync(request, null, null, targetDebug);

/// <summary>
/// Executes the form data request.
/// </summary>
/// <param name="request">The request to be executed.</param>
public Task ExecuteFormRequestAsync(BaseRestRequest request)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null);
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
public Task ExecuteFormRequestAsync(BaseRestRequest request, bool targetDebug = false)
=> request is null ? throw new ArgumentNullException(nameof(request)) : this.ExecuteFormRequestAsync(request, null, null, targetDebug);

/// <summary>
/// Executes the form data request.
Expand All @@ -261,7 +263,8 @@ public Task ExecuteFormRequestAsync(BaseRestRequest request)
/// <param name="request">The request to be executed.</param>
/// <param name="bucket">The bucket.</param>
/// <param name="ratelimitTcs">The ratelimit task completion source.</param>
private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs, bool targetDebug = false)
{
if (this._disposed)
return;
Expand Down Expand Up @@ -291,8 +294,7 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc

if (this._useResetAfter)
{
if (bucket.ResetAfter.HasValue)
delay = bucket.ResetAfter.Value;
delay = bucket.ResetAfter.Value;
resetDate = bucket.ResetAfterOffset;
}

Expand Down Expand Up @@ -321,7 +323,7 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc
var req = this.BuildFormRequest(request);

if (this.Debug && req.Content is not null)
this._logger.Log(this._discord?.Configuration.MinimumLogLevel ?? LogLevel.Trace, LoggerEvents.RestTx, "Rest Form Request Content:\n{Content}", await req.Content.ReadAsStringAsync()!);
this._logger.Log(LogLevel.Trace, LoggerEvents.RestTx, "Rest Form Request Content:\n{Content}", await req.Content.ReadAsStringAsync()!);

var response = new RestResponse();
try
Expand All @@ -335,7 +337,7 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc
var txt = Utilities.UTF8.GetString(bts, 0, bts.Length);

if (this.Debug)
this._logger.Log(this._discord?.Configuration.MinimumLogLevel ?? LogLevel.Trace, LoggerEvents.RestRx, "Rest Form Response Content: {Content}", txt);
this._logger.Log(LogLevel.Trace, LoggerEvents.RestRx, "Rest Form Response Content: {Content}", txt);

response.Headers = res.Headers?.ToDictionary(xh => xh.Key, xh => string.Join("\n", xh.Value), StringComparer.OrdinalIgnoreCase);
response.Response = txt;
Expand Down Expand Up @@ -462,10 +464,14 @@ private async Task ExecuteFormRequestAsync(BaseRestRequest request, RateLimitBuc
/// <param name="request">The request to be executed.</param>
/// <param name="bucket">The bucket.</param>
/// <param name="ratelimitTcs">The ratelimit task completion source.</param>
private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs)
/// <param name="targetDebug">Enables a possible breakpoint in the rest client for debugging purposes.</param>
private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket? bucket, TaskCompletionSource<bool>? ratelimitTcs, bool targetDebug = false)
{
ObjectDisposedException.ThrowIf(this._disposed, this);

if (targetDebug)
Console.WriteLine("Meow");

HttpResponseMessage? res = default;

try
Expand All @@ -491,8 +497,7 @@ private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket?

if (this._useResetAfter)
{
if (bucket.ResetAfter.HasValue)
delay = bucket.ResetAfter.Value;
delay = bucket.ResetAfter.Value;
resetDate = bucket.ResetAfterOffset;
}

Expand Down Expand Up @@ -521,21 +526,20 @@ private async Task ExecuteRequestAsync(BaseRestRequest request, RateLimitBucket?
var req = this.BuildRequest(request);

if (this.Debug && req.Content is not null)
this._logger.Log(this._discord?.Configuration.MinimumLogLevel ?? LogLevel.Trace, LoggerEvents.RestTx, "Rest Request Content:\n{Content}", await req.Content.ReadAsStringAsync());
this._logger.Log(LogLevel.Trace, LoggerEvents.RestTx, "Rest Request Content:\n{Content}", await req.Content.ReadAsStringAsync());

var response = new RestResponse();
try
{
if (this._disposed)
return;
ObjectDisposedException.ThrowIf(this._disposed, this);

res = await this.HttpClient.SendAsync(req, HttpCompletionOption.ResponseContentRead, CancellationToken.None).ConfigureAwait(false);

var bts = await res.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
var txt = Utilities.UTF8.GetString(bts, 0, bts.Length);

if (this.Debug)
this._logger.Log(this._discord?.Configuration.MinimumLogLevel ?? LogLevel.Trace, LoggerEvents.RestRx, "Rest Response Content: {Content}", txt);
this._logger.Log(LogLevel.Trace, LoggerEvents.RestRx, "Rest Response Content: {Content}", txt);

response.Headers = res.Headers?.ToDictionary(xh => xh.Key, xh => string.Join("\n", xh.Value), StringComparer.OrdinalIgnoreCase);
response.Response = txt;
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/Net/Rest/RestResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed class RestResponse
/// <summary>
/// Gets the contents of the response sent by the remote party.
/// </summary>
public string Response { get; internal set; } = null!;
public string Response { get; internal set; }

/// <summary>
/// Initializes a new instance of the <see cref="RestResponse"/> class.
Expand Down
12 changes: 8 additions & 4 deletions DisCatSharp/Net/Serialization/DiscordJson.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static string SerializeObject(object value)
/// <typeparam name="T">The type</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
public static T DeserializeObject<T>(string json, BaseDiscordClient? discord) where T : ObservableApiObject
public static T DeserializeObject<T>(string? json, BaseDiscordClient? discord) where T : ObservableApiObject
=> DeserializeObjectInternal<T>(json, discord);

/// <summary>
Expand All @@ -50,7 +50,7 @@ public static T DeserializeObject<T>(string json, BaseDiscordClient? discord) wh
/// <typeparam name="T">The enumerable type.</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
public static T DeserializeIEnumerableObject<T>(string json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
public static T DeserializeIEnumerableObject<T>(string? json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
=> DeserializeIEnumerableObjectInternal<T>(json, discord);

/// <summary>Populates an object with the values from a JSON node.</summary>
Expand Down Expand Up @@ -95,8 +95,10 @@ private static string SerializeObjectInternal(object value, Type type, JsonSeria
/// <typeparam name="T">The type</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
private static T DeserializeObjectInternal<T>(string json, BaseDiscordClient? discord) where T : ObservableApiObject
private static T DeserializeObjectInternal<T>(string? json, BaseDiscordClient? discord) where T : ObservableApiObject
{
ArgumentNullException.ThrowIfNull(json, nameof(json));

var obj = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings()
{
ContractResolver = new OptionalJsonContractResolver()
Expand Down Expand Up @@ -168,8 +170,10 @@ private static T DeserializeObjectInternal<T>(string json, BaseDiscordClient? di
/// <typeparam name="T">The enumerable type.</typeparam>
/// <param name="json">The received json.</param>
/// <param name="discord">The discord client.</param>
private static T DeserializeIEnumerableObjectInternal<T>(string json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
private static T DeserializeIEnumerableObjectInternal<T>(string? json, BaseDiscordClient? discord) where T : IEnumerable<ObservableApiObject>
{
ArgumentNullException.ThrowIfNull(json, nameof(json));

var obj = JsonConvert.DeserializeObject<T>(json, new JsonSerializerSettings()
{
ContractResolver = new OptionalJsonContractResolver()
Expand Down
2 changes: 1 addition & 1 deletion DisCatSharp/QueryUriBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public QueryUriBuilder AddParameter(string key, string value)
public Uri Build() =>
new UriBuilder(this.SourceUri)
{
Query = this._queryParams.Count is 0 ? string.Join("&", this._queryParams.Select(e => Uri.EscapeDataString(e.Key) + '=' + Uri.EscapeDataString(e.Value))) : string.Empty
Query = this._queryParams.Count is not 0 ? string.Join("&", this._queryParams.Select(e => Uri.EscapeDataString(e.Key) + '=' + Uri.EscapeDataString(e.Value))) : string.Empty
}.Uri;

/// <summary>
Expand Down

0 comments on commit 1c0f92a

Please sign in to comment.