Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BrammyS committed Aug 11, 2021
2 parents f7f2da7 + 6124849 commit 2bdd487
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Color-Chan.Discord.Commands/Modules/SlashCommandModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public static Result<IDiscordInteractionResponse> FromSuccess(IDiscordEmbed embe
// Build the response with the embed.
var responseBuilder = new SlashCommandResponseBuilder().WithEmbed(embed);

if (isPrivate) responseBuilder.MakePrivate();

// Return the response to Discord.
return FromSuccess(responseBuilder.Build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ Task<Result<IReadOnlyList<IDiscordGuildApplicationCommandPermissions>>> BatchEdi
/// <returns>
/// The <see cref="Result{T}" /> of <see cref="IDiscordMessage" /> with the request results.
/// </returns>
Task<Result<IDiscordMessage>> EditOriginalInteractionResponse(ulong applicationId, string token, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default);
Task<Result<IDiscordMessage>> EditOriginalInteractionResponseAsync(ulong applicationId, string token, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default);

/// <summary>
/// Deletes the initial Interaction response.
/// </summary>
/// <param name="applicationId">The ID of the application.</param>
/// <param name="token">The token of the interaction.</param>
/// <param name="ct">The <see cref="CancellationToken" />.</param>
/// <returns>
/// The <see cref="Result" /> with the request results.
/// </returns>
Task<Result> DeleteOriginalInteractionResponseAsync(ulong applicationId, string token, CancellationToken ct = default);
}
}
22 changes: 22 additions & 0 deletions src/Color-Chan.Discord.Core/Extensions/DiscordChannelExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Color_Chan.Discord.Core.Common.Models;

namespace Color_Chan.Discord.Core.Extensions
{
/// <summary>
/// Contains all the extensions methods for <see cref="IDiscordChannel" />.
/// </summary>
public static class DiscordChannelExtensions
{
/// <summary>
/// Get a string mentioning a specific <paramref name="channel"/>.
/// </summary>
/// <param name="channel">The <see cref="IDiscordChannel"/> that will be mentioned.</param>
/// <returns>
/// A <see cref="string"/> containing the mentioned <paramref name="channel"/>.
/// </returns>
public static string Mention(this IDiscordChannel channel)
{
return $"<#{channel.Id.ToString()}>";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Color_Chan.Discord.Core.Common.Models.Guild;

namespace Color_Chan.Discord.Core.Extensions
{
/// <summary>
/// Contains all the extensions methods for <see cref="IDiscordGuildRole" />.
/// </summary>
public static class DiscordGuildRoleExtensions
{
/// <summary>
/// Get a string mentioning a specific <paramref name="role"/>.
/// </summary>
/// <param name="role">The <see cref="IDiscordGuildRole"/> that will be mentioned.</param>
/// <returns>
/// A <see cref="string"/> containing the mentioned <paramref name="role"/>.
/// </returns>
public static string Mention(IDiscordGuildRole role)
{
return $"<@&{role.Id.ToString()}>";
}
}
}
23 changes: 23 additions & 0 deletions src/Color-Chan.Discord.Core/Extensions/DiscordUserExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Color_Chan.Discord.Core.Common.Models;

namespace Color_Chan.Discord.Core.Extensions
{
/// <summary>
/// Contains all the extensions methods for <see cref="IDiscordUser" />.
/// </summary>
public static class DiscordUserExtensions
{
/// <summary>
/// Get a string mentioning a specific <paramref name="user"/>.
/// </summary>
/// <param name="user">The <see cref="IDiscordUser"/> that will be mentioned.</param>
/// <param name="useNickname">Whether or not the mention with the nickname of the user.</param>
/// <returns>
/// A <see cref="string"/> containing the mentioned <paramref name="user"/>.
/// </returns>
public static string Mention(this IDiscordUser user, bool useNickname = true)
{
return !useNickname ? $"<@{user.Id.ToString()}>" : $"<@!{user.Id.ToString()}>";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,20 @@ public virtual async Task<Result<IDiscordMessage>> GetOriginalInteractionRespons
}

/// <inheritdoc />
public virtual async Task<Result<IDiscordMessage>> EditOriginalInteractionResponse(ulong applicationId, string token, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default)
public virtual async Task<Result<IDiscordMessage>> EditOriginalInteractionResponseAsync(ulong applicationId, string token, DiscordEditWebhookMessage webhookMessage, CancellationToken ct = default)
{
string endpoint = $"webhooks/{applicationId.ToString()}/{token}/messages/@original";
var result = await HttpClient.PatchAsync<DiscordMessageData, DiscordEditWebhookMessage>(endpoint, webhookMessage, ct: ct).ConfigureAwait(false);
return ApiResultConverters.ConvertResult(result);
}

/// <inheritdoc />
public virtual async Task<Result> DeleteOriginalInteractionResponseAsync(ulong applicationId, string token, CancellationToken ct = default)
{
string endpoint = $"webhooks/{applicationId.ToString()}/{token}/messages/@original";
return await HttpClient.DeleteAsync(endpoint, ct: ct).ConfigureAwait(false);
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public record DiscordInteraction : IDiscordInteraction
{
public DiscordInteraction(DiscordInteractionData data)
{
Id = data.Id;
ApplicationId = data.ApplicationId;
RequestType = data.RequestType;
if (data.Data is not null) Data = new DiscordInteractionCommand(data.Data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public async Task<ActionResult> HandleInteractionRequestAsync()
AllowedMentions = responseData?.AllowedMentions
};

var responseResult = await _restApplication.EditOriginalInteractionResponse(_discordTokens.ApplicationId, interactionData.Token, editResponse).ConfigureAwait(false);
var responseResult = await _restApplication.EditOriginalInteractionResponseAsync(_discordTokens.ApplicationId, interactionData.Token, editResponse).ConfigureAwait(false);
if (responseResult.IsSuccessful) return Ok();

// Send an error response.
Expand Down

0 comments on commit 2bdd487

Please sign in to comment.