2022-11-29 19:06:15 +00:00
|
|
|
|
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
|
|
|
|
|
{
|
2024-05-30 19:36:14 +01:00
|
|
|
|
internal CommandContext(VirtualParadiseClient client, VirtualParadiseAvatar avatar, string commandName, string alias,
|
2022-11-27 20:43:21 +00:00
|
|
|
|
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;
|
2022-11-29 19:06:15 +00:00
|
|
|
|
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>
|
2022-11-29 19:06:15 +00:00
|
|
|
|
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>
|
2024-05-30 19:36:14 +01:00
|
|
|
|
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>
|
2024-05-30 19:36:14 +01:00
|
|
|
|
public Task<VirtualParadiseMessage> RespondAsync(string message, bool ephemeral = false)
|
2022-11-27 20:43:21 +00:00
|
|
|
|
{
|
|
|
|
|
return ephemeral
|
2024-05-30 19:36:14 +01:00
|
|
|
|
? Avatar.SendMessageAsync(Client.CurrentAvatar?.Name, message, FontStyle.Regular, Color.Black)
|
|
|
|
|
: Client.SendMessageAsync(message);
|
2022-11-27 20:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
}
|