Skip to content

Commit

Permalink
Discord updates (#545)
Browse files Browse the repository at this point in the history
* chore(deps): update dependencies

* fix(deps-ci): use .x versioning for net

* chore(deps-ci): bump net9 preview to 7

* feat: add with_response to interaction create to return created message

This will be enforced by discord at some point, so we enforce it internally already.
DiscordMessage might be null in some cases, but shouldn't normally.
```cs
public async Task<DiscordMessage> CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder? builder = null)
		=> await this.Discord.ApiClient.CreateInteractionResponseAsync(this.Id, this.Token, type, builder);
```

* feat: get user voice states

* feat: get discord sticker pack

* feat: approx user install count

* fix: poll max duration 7 days > 32 days

* fix: 7090

* feat: attachment title

* chore(deps): update dependencies

* fix(deps): bump deps
  • Loading branch information
Lulalaby authored Aug 21, 2024
1 parent 8534cd4 commit 3c6a4bf
Show file tree
Hide file tree
Showing 32 changed files with 198 additions and 67 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore dependencies
run: |
dotnet restore --no-cache -f -v minimal DisCatSharp.sln
Expand All @@ -62,9 +62,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore Packages
run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln
- name: Build library
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore dependencies
run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln
- name: Build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.403
9.0.100-preview.7.24407.12
8.x
7.x
- name: Git fetch unshallow
run: git fetch --unshallow
- name: Install DocFX
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/documentation_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.403
9.0.100-preview.7.24407.12
8.x
7.x
- name: Install DocFX
run: dotnet tool update -g docfx
continue-on-error: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/internal-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore dependencies
run: |
dotnet restore --no-cache -f -v minimal DisCatSharp.sln
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/public-dev-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore dependencies
run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln
- name: Set outputs
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ jobs:
uses: actions/[email protected]
with:
dotnet-version: |
9.0.100-preview.6.24328.19
8.0.301
7.0.404
9.0.100-preview.7.24407.12
8.x
7.x
- name: Restore dependencies (DisCatSharp)
if: ${{ github.event.inputs.packages_to_release == 'DisCatSharp' }}
run: dotnet restore --no-cache -f -v minimal DisCatSharp.sln
Expand Down
4 changes: 2 additions & 2 deletions DisCatSharp.ApplicationCommands/Context/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ internal BaseContext(DisCatSharpCommandType type)
/// <param name="type">The type of the response.</param>
/// <param name="builder">The data to be sent, if any.</param>
/// <returns></returns>
public Task CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder builder = null)
=> this.Interaction.CreateResponseAsync(type, builder);
public async Task<DiscordMessage> CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder? builder = null)
=> await this.Interaction.CreateResponseAsync(type, builder);

/// <summary>
/// Creates a modal response to this interaction.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using ConcurrentCollections;
Expand Down Expand Up @@ -105,17 +106,16 @@ private async Task Handle(DiscordClient _, ComponentInteractionCreateEventArgs a
else if (this._config.ResponseBehavior is InteractionResponseBehavior.Respond)
await args.Interaction.CreateFollowupMessageAsync(this._message).ConfigureAwait(false);

foreach (var creq in this._collectRequests)
if (creq.Message == args.Message && creq.IsMatch(args))
{
await args.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);
foreach (var creq in this._collectRequests.Where(creq => creq.Message == args.Message && creq.IsMatch(args)))
{
await args.Interaction.CreateResponseAsync(InteractionResponseType.DeferredMessageUpdate).ConfigureAwait(false);

if (creq.IsMatch(args))
creq.Collected.Add(args);
if (creq.IsMatch(args))
creq.Collected.Add(args);

else if (this._config.ResponseBehavior is InteractionResponseBehavior.Respond)
await args.Interaction.CreateFollowupMessageAsync(this._message).ConfigureAwait(false);
}
else if (this._config.ResponseBehavior is InteractionResponseBehavior.Respond)
await args.Interaction.CreateFollowupMessageAsync(this._message).ConfigureAwait(false);
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public static async Task<PaginatedModalResponse> CreatePaginatedModalResponseAsy

if (previousInteraction.Type is InteractionType.Ping or InteractionType.ModalSubmit)
{
await previousInteraction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, b.OpenMessage.AddComponents(b.OpenButton)).ConfigureAwait(false);
var originalResponse = await previousInteraction.GetOriginalResponseAsync().ConfigureAwait(false);
var originalResponse = await previousInteraction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, b.OpenMessage.AddComponents(b.OpenButton)).ConfigureAwait(false);
var modalOpen = await interactivity.WaitForButtonAsync(originalResponse, new List<DiscordButtonComponent>
{
b.OpenButton
Expand Down
3 changes: 1 addition & 2 deletions DisCatSharp.Interactivity/InteractivityExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,7 @@ public async Task SendPaginatedResponseAsync(DiscordInteraction interaction, boo
.AddComponents(bts.ButtonArray);
if (ephemeral)
builder = builder.AsEphemeral();
await interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder).ConfigureAwait(false);
message = await interaction.GetOriginalResponseAsync().ConfigureAwait(false);
message = await interaction.CreateResponseAsync(InteractionResponseType.ChannelMessageWithSource, builder).ConfigureAwait(false);
}

var req = new InteractionPaginationRequest(interaction, message, user, bhv, del, bts, pages, token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="../../DisCatSharp.Targets/InternalsVisibleTo.targets" />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="../../DisCatSharp.Targets/InternalsVisibleTo.targets" />

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PackageReference Include="Microsoft.DependencyValidation.Analyzers" Version="0.11.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
6 changes: 3 additions & 3 deletions DisCatSharp.Tests/SafetyTests/DisCatSharp.SafetyTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.10.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="4.11.0" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

<PropertyGroup>
<PackageId>DisCatSharp.Analyzer.Roselyn</PackageId>
<Version>6.2.4</Version>
<PackageVersion>6.2.4</PackageVersion>
<Version>6.2.5</Version>
<PackageVersion>6.2.5</PackageVersion>
<Authors>AITSYS</Authors>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>DisCatSharp Analyzer</Description>
Expand Down Expand Up @@ -71,7 +71,7 @@
<ItemGroup>
<ProjectReference Include="..\DisCatSharp.Analyzer\DisCatSharp.Analyzer.csproj" />
<PackageReference Include="DisCatSharp.Attributes" Version="10.6.3" PrivateAssets="all" GeneratePathProperty="true" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.10.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.11.0" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.7.37357" />
</ItemGroup>

Expand Down
1 change: 1 addition & 0 deletions DisCatSharp/Clients/BaseDiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public async Task<DiscordApplication> GetCurrentApplicationAsync()
app.CoverImageHash = tapp.CoverImageHash.ValueOrDefault();
app.Guild = tapp.Guild.ValueOrDefault();
app.ApproximateGuildCount = tapp.ApproximateGuildCount.ValueOrDefault();
app.ApproximateUserInstallCount = tapp.ApproximateUserInstallCount.ValueOrDefault();
app.RequiresCodeGrant = tapp.BotRequiresCodeGrant.ValueOrDefault();
app.IsPublic = tapp.IsPublicBot.ValueOrDefault();
app.RedirectUris = tapp.RedirectUris.ValueOrDefault();
Expand Down
10 changes: 10 additions & 0 deletions DisCatSharp/Clients/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,16 @@ public bool TryGetSticker(ulong id, [NotNullWhen(true)] out DiscordSticker? stic
}
}

/// <summary>
/// Gets a sticker pack.
/// </summary>
/// <param name="id">The sticker pack's id.</param>
/// <returns>The sticker pack.</returns>
/// <exception cref="BadRequestException">Thrown when an invalid parameter was provided.</exception>
/// <exception cref="ServerErrorException">Thrown when Discord is unable to process the request.</exception>
public Task<DiscordStickerPack> GetStickerPackAsync(ulong id)
=> this.ApiClient.GetStickerPackAsync(id);

/// <summary>
/// Gets all nitro sticker packs.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions DisCatSharp/DisCatSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Protocol" Version="6.11.0" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="Sentry" Version="4.10.1" />
<PackageReference Include="Sentry.Extensions.Logging" Version="4.10.1" />
<PackageReference Include="Sentry" Version="4.10.2" />
<PackageReference Include="Sentry.Extensions.Logging" Version="4.10.2" />
<PackageReference Include="System.Memory" Version="4.5.5" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Net.WebSockets" Version="4.3.0" />
Expand Down
5 changes: 5 additions & 0 deletions DisCatSharp/Entities/Application/DiscordApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ public override string CoverImageUrl
/// </summary>
public int? ApproximateGuildCount { get; internal set; }

/// <summary>
/// Gets the approximate user install count
/// </summary>
public int? ApproximateUserInstallCount { get; internal set; }

/// <summary>
/// Gets the interactions endpoint url.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions DisCatSharp/Entities/Guild/DiscordGuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,13 @@ public DiscordMember CurrentMember
[JsonIgnore]
private readonly Lazy<DiscordMember> _currentMemberLazy;

/// <summary>
/// Gets the current guild member's voice state.
/// </summary>
/// <returns></returns>
public async Task<DiscordVoiceState?> GetCurrentMemberVoiceStateAsync()
=> await this.Discord.ApiClient.GetCurrentUserVoiceStateAsync(this.Id);

/// <summary>
/// Gets the @everyone role for this guild.
/// </summary>
Expand Down
7 changes: 7 additions & 0 deletions DisCatSharp/Entities/Guild/DiscordMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,13 @@ public Task RemoveAsync(string? reason = null)
public Task PlaceInAsync(DiscordChannel channel)
=> channel.PlaceMemberAsync(this);

/// <summary>
/// Gets the member's voice state.
/// </summary>
/// <returns></returns>
public async Task<DiscordVoiceState?> GetVoiceStateAsync()
=> await this.Discord.ApiClient.GetUserVoiceStateAsync(this.Guild.Id, this.Id);

/// <summary>
/// Updates the member's suppress state in a stage channel.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ internal void Validate()
{
if (this.Files?.Count == 0 && string.IsNullOrEmpty(this.Content) && !this.Embeds.Any() && !this.Components.Any() && this.Poll is null)
throw new ArgumentException("You must specify content, an embed, a component, a poll, or at least one file.");

this.Poll?.Validate();
}
}
4 changes: 2 additions & 2 deletions DisCatSharp/Entities/Interaction/DiscordInteraction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ public DiscordChannel Channel
/// </summary>
/// <param name="type">The type of the response.</param>
/// <param name="builder">The data, if any, to send.</param>
public Task CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder builder = null)
=> this.Discord.ApiClient.CreateInteractionResponseAsync(this.Id, this.Token, type, builder);
public async Task<DiscordMessage> CreateResponseAsync(InteractionResponseType type, DiscordInteractionResponseBuilder? builder = null)
=> await this.Discord.ApiClient.CreateInteractionResponseAsync(this.Id, this.Token, type, builder);

/// <summary>
/// Creates a modal response to this interaction.
Expand Down
6 changes: 6 additions & 0 deletions DisCatSharp/Entities/Message/DiscordAttachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public class DiscordAttachment : NullableSnowflakeObject
[JsonProperty("filename", NullValueHandling = NullValueHandling.Ignore)]
public string Filename { get; internal set; }

/// <summary>
/// Gets the title of the file.
/// </summary>
[JsonProperty("title", NullValueHandling = NullValueHandling.Ignore)]
public string? Title { get; set; }

/// <summary>
/// Gets the description of the file.
/// </summary>
Expand Down
5 changes: 3 additions & 2 deletions DisCatSharp/Entities/Message/Polls/DiscordPollBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public string Question
public PollLayoutType LayoutType { get; internal set; } = PollLayoutType.Default;

/// <summary>
/// Gets or sets the number of hours the poll should be open for, up to 7 days.
/// Gets or sets the number of hours the poll should be open for, up to 32 days.
/// Defaults to <c>24</c> hours.
/// </summary>
public int Duration { get; set; } = 24;
Expand Down Expand Up @@ -127,6 +127,7 @@ public DiscordPollBuilder AddAnswers(IEnumerable<DiscordPollAnswer> answers)
{
if (answer.PollMedia.Text.Length > 55)
throw new ArgumentException($"Answers text cannot exceed 55 characters. Thrown in answer {answerId}");

answerId++;
}

Expand Down Expand Up @@ -173,7 +174,7 @@ internal void Validate()
throw new ArgumentException("You must specify a question.");

if (this.Duration > 168)
throw new ArgumentException("Polls can only be open for up to 7 days or 168 hours.");
throw new ArgumentException("Polls can only be open for up to 32 days or 768 hours.");
}

/// <summary>
Expand Down
6 changes: 6 additions & 0 deletions DisCatSharp/Entities/Sticker/DiscordStickerPack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public sealed class DiscordStickerPack : SnowflakeObject
[JsonProperty("banner_asset_id")]
public ulong BannerAssetId { get; internal set; }

/// <summary>
/// Gets the descriptions of this pack.
/// </summary>
[JsonProperty("description")]
public string Description { get; internal set; }

/// <summary>
/// Gets the pack's banner url.
/// </summary>
Expand Down
Loading

0 comments on commit 3c6a4bf

Please sign in to comment.