~ruther/NosSmooth.Local

ref: e17f06759be04b9bf33005d654a2305eca11d7ac NosSmooth.Local/src/Extensions/NosSmooth.ChatCommands/FeedbackService.cs -rw-r--r-- 2.6 KiB
e17f0675 — Rutherther chore: update to .net 7 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
//  FeedbackService.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.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Server.Chat;
using Remora.Results;

namespace NosSmooth.ChatCommands;

/// <summary>
/// Feedback for chat commands.
/// </summary>
public class FeedbackService
{
    private readonly INostaleClient _client;

    /// <summary>
    /// Initializes a new instance of the <see cref="FeedbackService"/> class.
    /// </summary>
    /// <param name="client">The nostale client.</param>
    public FeedbackService(INostaleClient client)
    {
        _client = client;

    }

    /// <summary>
    /// Send message error.
    /// </summary>
    /// <param name="message">The message to send.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> SendErrorMessageAsync(string message, CancellationToken ct = default)
        => SendMessageAsync(message, SayColor.Red, ct);

    /// <summary>
    /// Send message success.
    /// </summary>
    /// <param name="message">The message to send.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> SendSuccessMessageAsync(string message, CancellationToken ct = default)
        => SendMessageAsync(message, SayColor.Green, ct);

    /// <summary>
    /// Send message info.
    /// </summary>
    /// <param name="message">The message to send.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> SendInfoMessageAsync(string message, CancellationToken ct = default)
        => SendMessageAsync(message, SayColor.Default, ct);

    /// <summary>
    /// Send message with the given color.
    /// </summary>
    /// <param name="message">The message to send.</param>
    /// <param name="color">The color.</param>
    /// <param name="ct">The cancellation token for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> SendMessageAsync(string message, SayColor color, CancellationToken ct = default)
        => _client.ReceivePacketAsync(new SayPacket(EntityType.Map, 0, color, message), ct);
}
Do not follow this link