// // DialogHandler.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using NosSmooth.Core.Client; using NosSmooth.Game.Data.Dialogs; using Remora.Results; namespace NosSmooth.Game.Apis; /// /// Handles accepting and denying of dialogs. /// public class DialogHandler { private readonly INostaleClient _client; /// /// Initializes a new instance of the class. /// /// The client. public DialogHandler(INostaleClient client) { _client = client; } /// /// Accept the operation the dialog does. /// /// The opened dialog. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public Task AcceptAsync(Dialog dialog, CancellationToken ct = default) => _client.SendPacketAsync(dialog.AcceptCommand, ct); /// /// Try to deny the operation the dialog does. /// /// /// Some dialogs do not allow denying, they are just ignored instead. /// /// The opened dialog. /// The cancellation token used for cancelling the operation. /// A result that may or may not have succeeded. public Task DenyAsync(Dialog dialog, CancellationToken ct = default) { if (dialog.DenyCommand is null) { return Task.FromResult(Result.FromSuccess()); } return _client.SendPacketAsync(dialog.DenyCommand, ct); } }