1
0
mirror of https://github.com/oliverbooth/VpSharp synced 2024-11-23 00:28:48 +00:00
VpSharp/VpSharp.Commands/CommandContext.cs

75 lines
2.4 KiB
C#
Raw Normal View History

using System.Collections.ObjectModel;
using System.Drawing;
2022-11-27 20:43:21 +00:00
using VpSharp.Entities;
namespace VpSharp.Commands;
/// <summary>
/// Provides metadata about a command invocation.
/// </summary>
public sealed class CommandContext
{
internal CommandContext(VirtualParadiseClient client, VirtualParadiseAvatar avatar, string commandName, string alias,
string rawArguments)
{
2022-12-08 20:26:10 +00:00
Client = client;
2022-11-27 20:43:21 +00:00
Avatar = avatar;
CommandName = commandName;
Alias = alias;
RawArguments = rawArguments;
Arguments = new ReadOnlyCollection<string>(rawArguments.Split());
2022-11-27 20:43:21 +00:00
}
/// <summary>
/// Gets the alias that was used to invoke the command.
/// </summary>
/// <value>The alias used.</value>
public string Alias { get; }
/// <summary>
/// Gets the arguments of the command.
/// </summary>
/// <value>The arguments passed by the avatar.</value>
public IReadOnlyList<string> Arguments { get; }
2022-11-27 20:43:21 +00:00
/// <summary>
/// Gets the avatar who executed the command.
/// </summary>
/// <value>The executing avatar.</value>
public VirtualParadiseAvatar Avatar { get; }
2022-12-08 20:26:10 +00:00
/// <summary>
/// Gets the client which raised the event.
/// </summary>
/// <value>The Virtual Paradise client.</value>
public VirtualParadiseClient Client { get; }
2022-11-27 20:43:21 +00:00
/// <summary>
/// Gets the command name.
/// </summary>
/// <value>The name of the command being executed.</value>
public string CommandName { get; }
/// <summary>
/// Gets the raw argument string as sent by the avatar.
/// </summary>
/// <value>The raw argument string.</value>
public string RawArguments { get; }
/// <summary>
/// Sends a response message to the command.
/// </summary>
/// <param name="message">The message to send.</param>
/// <param name="ephemeral">
/// <see langword="true" /> to respond only to the avatar which sent the command; <see langword="false" /> to send a
/// regular chat message.
/// </param>
/// <returns>The message which was sent.</returns>
public Task<VirtualParadiseMessage> RespondAsync(string message, bool ephemeral = false)
{
return ephemeral
2022-12-08 20:26:10 +00:00
? Avatar.SendMessageAsync(Client.CurrentAvatar?.Name, message, FontStyle.Regular, Color.Black)
: Client.SendMessageAsync(message);
2022-11-27 20:43:21 +00:00
}
}