1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-01-31 09:09:00 +03:00
Octobot/InteractionResponders.cs
Octol1ttle abbb58f801
Switch to Remora.Discord (#41)
result checks go brrr

this also involves switching to using Discord's modern stuff like embeds
and interactions

and using brand-new for me programming concepts (dependency injection,
results)

---------

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
Signed-off-by: mctaylors <95250141+mctaylors@users.noreply.github.com>
Co-authored-by: mctaylors <95250141+mctaylors@users.noreply.github.com>
Co-authored-by: nrdk <neroduck@vk.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-07-09 16:32:14 +03:00

36 lines
1.4 KiB
C#

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;
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable UnusedMember.Global
namespace Boyfriend;
/// <summary>
/// Handles responding to various interactions.
/// </summary>
public class InteractionResponders : InteractionGroup {
private readonly FeedbackService _feedbackService;
public InteractionResponders(FeedbackService feedbackService) {
_feedbackService = feedbackService;
}
/// <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")]
public async Task<Result> OnStatefulButtonClicked(string? state = null) {
if (state is null) return Result.FromError(new ArgumentNullError(nameof(state)));
var idArray = state.Split(':');
return (Result)await _feedbackService.SendContextualAsync(
$"https://discord.com/events/{idArray[0]}/{idArray[1]}",
options: new FeedbackMessageOptions(MessageFlags: MessageFlags.Ephemeral));
}
}