Skip to content

Commit

Permalink
Implement interfaces of new REST API endpoints.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nihlus committed Dec 17, 2020
1 parent 8615b2b commit e5efcad
Show file tree
Hide file tree
Showing 3 changed files with 355 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
//
// IDiscordRestApplicationAPI.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Results;
using Remora.Discord.Core;

namespace Remora.Discord.API.Abstractions.Rest
{
/// <summary>
/// Represents the Discord application API.
/// </summary>
[PublicAPI]
public interface IDiscordRestApplicationAPI
{
/// <summary>
/// Gets the global commands for the application.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A retrieval result which may or may not have succeeded.</returns>
Task<IRetrieveRestEntityResult<IReadOnlyList<IApplicationCommand>>> GetGlobalApplicationCommandsAsync
(
Snowflake applicationID,
CancellationToken ct
);

/// <summary>
/// Creates a new global command.
/// </summary>
/// <remarks>
/// Creating a new command with the same name as an existing command will overwrite the old command.
/// </remarks>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="name">The name of the command. 3-32 characters.</param>
/// <param name="description">The description of the command. 1-100 characters.</param>
/// <param name="options">The parameters for the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<ICreateRestEntityResult<IApplicationCommand>> CreateGlobalApplicationCommandAsync
(
Snowflake applicationID,
string name,
string description,
Optional<IReadOnlyList<IApplicationCommandOption>> options,
CancellationToken ct
);

/// <summary>
/// TODO: Check if name/description are actually optional. Docs say they aren't.
/// Edits a new global command.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="commandID">The ID of the command.</param>
/// <param name="name">The name of the command. 3-32 characters.</param>
/// <param name="description">The description of the command. 1-100 characters.</param>
/// <param name="options">The parameters for the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<IModifyRestEntityResult<IApplicationCommand>> EditGlobalApplicationCommandAsync
(
Snowflake applicationID,
Snowflake commandID,
Optional<string> name,
Optional<string> description,
Optional<IReadOnlyList<IApplicationCommandOption>> options,
CancellationToken ct
);

/// <summary>
/// Deletes the given global command.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="commandID">The ID of the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A deletion result which may or may not have succeeded.</returns>
Task<IDeleteRestEntityResult> DeleteGlobalApplicationCommandAsync
(
Snowflake applicationID,
Snowflake commandID,
CancellationToken ct
);

/// <summary>
/// Gets the guild commands for the application.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="guildID">The ID of the guild.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A retrieval result which may or may not have succeeded.</returns>
Task<IRetrieveRestEntityResult<IReadOnlyList<IApplicationCommand>>> GetGuildApplicationCommandsAsync
(
Snowflake applicationID,
Snowflake guildID,
CancellationToken ct
);

/// <summary>
/// Creates a new guild command.
/// </summary>
/// <remarks>
/// Creating a new command with the same name as an existing command will overwrite the old command.
/// </remarks>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="guildID">The ID of the guild.</param>
/// <param name="name">The name of the command. 3-32 characters.</param>
/// <param name="description">The description of the command. 1-100 characters.</param>
/// <param name="options">The parameters for the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<ICreateRestEntityResult<IApplicationCommand>> CreateGuildApplicationCommandAsync
(
Snowflake applicationID,
Snowflake guildID,
string name,
string description,
Optional<IReadOnlyList<IApplicationCommandOption>> options,
CancellationToken ct
);

/// <summary>
/// TODO: Check if name/description are actually optional. Docs say they aren't.
/// Edits a new guild command.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="guildID">The ID of the guild.</param>
/// <param name="commandID">The ID of the command.</param>
/// <param name="name">The name of the command. 3-32 characters.</param>
/// <param name="description">The description of the command. 1-100 characters.</param>
/// <param name="options">The parameters for the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<IModifyRestEntityResult<IApplicationCommand>> EditGuildApplicationCommandAsync
(
Snowflake applicationID,
Snowflake guildID,
Snowflake commandID,
Optional<string> name,
Optional<string> description,
Optional<IReadOnlyList<IApplicationCommandOption>> options,
CancellationToken ct
);

/// <summary>
/// Deletes the given guild command.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="guildID">The ID of the guild.</param>
/// <param name="commandID">The ID of the command.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A deletion result which may or may not have succeeded.</returns>
Task<IDeleteRestEntityResult> DeleteGuildApplicationCommandAsync
(
Snowflake applicationID,
Snowflake guildID,
Snowflake commandID,
CancellationToken ct
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// IDiscordRestInteractionAPI.cs
//
// Author:
// Jarl Gullberg <[email protected]>
//
// Copyright (c) 2017 Jarl Gullberg
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//

using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Abstractions.Results;
using Remora.Discord.Core;

namespace Remora.Discord.API.Abstractions.Rest
{
/// <summary>
/// Represents the Discord interaction API.
/// </summary>
[PublicAPI]
public interface IDiscordRestInteractionAPI
{
/// <summary>
/// TODO: Check if we actually get an IInteractionResponse back from this.
/// Creates a response to an interaction from the gateway.
/// </summary>
/// <param name="interactionID">The ID of the interaction.</param>
/// <param name="interactionToken">The interaction token.</param>
/// <param name="response">The response.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A creation result which may or may not have succeeded.</returns>
Task<ICreateRestEntityResult<IInteractionResponse>> CreateInteractionResponseAsync
(
Snowflake interactionID,
string interactionToken,
IInteractionResponse response,
CancellationToken ct
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -223,5 +223,122 @@ Task<IModifyRestEntityResult<IMessage>> EditWebhookMessageAsync
Optional<IAllowedMentions?> allowedMentions = default,
CancellationToken ct = default
);

/// <summary>
/// TODO: Is the interaction ID not involved here?
/// Edits the initial interaction response.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="token">The interaction token.</param>
/// <param name="content">The new content, if any.</param>
/// <param name="embeds">The new embeds, if any.</param>
/// <param name="allowedMentions">The new allowed mentions, if any.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result which may or may not have succeeded.</returns>
Task<IModifyRestEntityResult<IMessage>> EditOriginalInteractionResponseAsync
(
Snowflake applicationID,
string token,
Optional<string?> content = default,
Optional<IReadOnlyList<IEmbed>?> embeds = default,
Optional<IAllowedMentions?> allowedMentions = default,
CancellationToken ct = default
);

/// <summary>
/// Deletes the original interaction response.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="token">The interaction token.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A deletion result which may or may not have succeeded.</returns>
Task<IDeleteRestEntityResult> DeleteOriginalInteractionResponseAsync
(
Snowflake applicationID,
string token,
CancellationToken ct
);

/// <summary>
/// TODO: Is the interaction ID not involved here?
/// Creates a followup message.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="token">The interaction token.</param>
/// <param name="shouldWait">
/// Whether the call should block until the server has confirmed that the message was sent.
/// </param>
/// <param name="content">
/// The content of the message. At least one of <paramref name="content"/>, <paramref name="file"/>, or
/// <paramref name="embeds"/> is required.
/// </param>
/// <param name="username">The username to use for this message.</param>
/// <param name="avatarUrl">The avatar to use for this message.</param>
/// <param name="isTTS">Whether this message is a TTS message.</param>
/// <param name="file">
/// The file attached to message. At least one of <paramref name="content"/>, <paramref name="file"/>, or
/// <paramref name="embeds"/> is required.
/// </param>
/// <param name="embeds">
/// The embeds in the message. At least one of <paramref name="content"/>, <paramref name="file"/>, or
/// <paramref name="embeds"/> is required.
/// </param>
/// <param name="allowedMentions">The set of allowed mentions of the message.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A result which may or may not have succeeded.</returns>
Task<ICreateRestEntityResult<IMessage>> CreateFollowupMessageAsync
(
Snowflake applicationID,
string token,
Optional<bool> shouldWait = default,
Optional<string> content = default,
Optional<string> username = default,
Optional<string> avatarUrl = default,
Optional<bool> isTTS = default,
Optional<Stream> file = default,
Optional<IReadOnlyList<IEmbed>> embeds = default,
Optional<IAllowedMentions> allowedMentions = default,
CancellationToken ct = default
);

/// <summary>
/// TODO: Is the interaction ID not involved here?
/// Edits an interaction followup message.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="token">The interaction token.</param>
/// <param name="messageID">The ID of the message.</param>
/// <param name="content">The new content, if any.</param>
/// <param name="embeds">The new embeds, if any.</param>
/// <param name="allowedMentions">The new allowed mentions, if any.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result which may or may not have succeeded.</returns>
Task<IModifyRestEntityResult<IMessage>> EditFollowupMessageAsync
(
Snowflake applicationID,
string token,
Snowflake messageID,
Optional<string?> content = default,
Optional<IReadOnlyList<IEmbed>?> embeds = default,
Optional<IAllowedMentions?> allowedMentions = default,
CancellationToken ct = default
);

/// <summary>
/// TODO: Is the interaction ID not involved here?
/// Deletes an interaction followup message.
/// </summary>
/// <param name="applicationID">The ID of the bot application.</param>
/// <param name="token">The interaction token.</param>
/// <param name="messageID">The ID of the message.</param>
/// <param name="ct">The cancellation token for this operation.</param>
/// <returns>A modification result which may or may not have succeeded.</returns>
Task<IDeleteRestEntityResult> DeleteFollowupMessageAsync
(
Snowflake applicationID,
string token,
Snowflake messageID,
CancellationToken ct = default
);
}
}

0 comments on commit e5efcad

Please sign in to comment.