mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-01-31 09:09:00 +03:00
Use link button for created event message (#158)
Signed-off-by: Macintosh II <mctaylxrs@outlook.com>
This commit is contained in:
parent
8b659a6582
commit
e21cefd79d
3 changed files with 2 additions and 50 deletions
|
@ -1,42 +0,0 @@
|
|||
using JetBrains.Annotations;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.Commands.Feedback.Messages;
|
||||
using Remora.Discord.Commands.Feedback.Services;
|
||||
using Remora.Discord.Interactivity;
|
||||
using Remora.Results;
|
||||
|
||||
namespace Octobot;
|
||||
|
||||
/// <summary>
|
||||
/// Handles responding to various interactions.
|
||||
/// </summary>
|
||||
[UsedImplicitly]
|
||||
public class InteractionResponders : InteractionGroup
|
||||
{
|
||||
private readonly FeedbackService _feedback;
|
||||
|
||||
public InteractionResponders(FeedbackService feedback)
|
||||
{
|
||||
_feedback = feedback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A button that will output an ephemeral embed containing the information about a scheduled event.
|
||||
/// </summary>
|
||||
/// <param name="state">The ID of the guild and scheduled event, encoded as "guildId:eventId".</param>
|
||||
/// <returns>An ephemeral feedback sending result which may or may not have succeeded.</returns>
|
||||
[Button("scheduled-event-details")]
|
||||
[UsedImplicitly]
|
||||
public async Task<Result> OnStatefulButtonClicked(string? state = null)
|
||||
{
|
||||
if (state is null)
|
||||
{
|
||||
return new ArgumentNullError(nameof(state));
|
||||
}
|
||||
|
||||
var idArray = state.Split(':');
|
||||
return (Result)await _feedback.SendContextualAsync(
|
||||
$"https://discord.com/events/{idArray[0]}/{idArray[1]}",
|
||||
options: new FeedbackMessageOptions(MessageFlags: MessageFlags.Ephemeral), ct: CancellationToken);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,6 @@ using Remora.Discord.Commands.Services;
|
|||
using Remora.Discord.Gateway;
|
||||
using Remora.Discord.Gateway.Extensions;
|
||||
using Remora.Discord.Hosting.Extensions;
|
||||
using Remora.Discord.Interactivity.Extensions;
|
||||
using Remora.Rest.Core;
|
||||
using Serilog.Extensions.Logging;
|
||||
|
||||
|
@ -80,9 +79,6 @@ public sealed class Octobot
|
|||
// Init
|
||||
.AddDiscordCaching()
|
||||
.AddDiscordCommands(true)
|
||||
// Interactions
|
||||
.AddInteractivity()
|
||||
.AddInteractionGroup<InteractionResponders>()
|
||||
// Slash command event handlers
|
||||
.AddPreparationErrorEvent<LoggingPreparationErrorEvent>()
|
||||
.AddPostExecutionEvent<ErrorLoggingPostExecutionEvent>()
|
||||
|
|
|
@ -7,7 +7,6 @@ using Remora.Discord.API.Abstractions.Rest;
|
|||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Discord.Interactivity;
|
||||
using Remora.Rest.Core;
|
||||
using Remora.Results;
|
||||
|
||||
|
@ -217,11 +216,10 @@ public sealed class ScheduledEventUpdateService : BackgroundService
|
|||
: string.Empty;
|
||||
|
||||
var button = new ButtonComponent(
|
||||
ButtonComponentStyle.Primary,
|
||||
ButtonComponentStyle.Link,
|
||||
Messages.EventDetailsButton,
|
||||
new PartialEmoji(Name: "📋"),
|
||||
CustomIDHelpers.CreateButtonIDWithState(
|
||||
"scheduled-event-details", $"{scheduledEvent.GuildID}:{scheduledEvent.ID}")
|
||||
URL: $"https://discord.com/events/{scheduledEvent.GuildID}/{scheduledEvent.ID}"
|
||||
);
|
||||
|
||||
return (Result)await _channelApi.CreateMessageAsync(
|
||||
|
|
Loading…
Reference in a new issue