using Content.Server.Chat.Managers;
using Content.Shared.CCVar;
using Content.Shared.Chat;
+using NetCord;
using NetCord.Gateway;
using Robust.Shared.Asynchronous;
using Robust.Shared.Configuration;
{
_discordLink.OnMessageReceived += OnMessageReceived;
+ #if DEBUG
+ _discordLink.RegisterCommandCallback(OnDebugCommandRun, "debug");
+ #endif
+
_configurationManager.OnValueChanged(CCVars.OocDiscordChannelId, OnOocChannelIdChanged, true);
_configurationManager.OnValueChanged(CCVars.AdminChatDiscordChannelId, OnAdminChannelIdChanged, true);
}
_configurationManager.UnsubValueChanged(CCVars.AdminChatDiscordChannelId, OnAdminChannelIdChanged);
}
+ #if DEBUG
+ private void OnDebugCommandRun(CommandReceivedEventArgs ev)
+ {
+ var args = string.Join('\n', ev.Arguments);
+ _sawmill.Info($"Provided arguments: \n{args}");
+ }
+ #endif
+
private void OnOocChannelIdChanged(string channelId)
{
if (string.IsNullOrEmpty(channelId))
-using System.Threading.Tasks;
+using System.Collections.ObjectModel;
+using System.Threading.Tasks;
using Content.Shared.CCVar;
using NetCord;
using NetCord.Gateway;
using NetCord.Rest;
using Robust.Shared.Configuration;
+using Robust.Shared.Utility;
namespace Content.Server.Discord.DiscordLink;
public string Command { get; init; } = string.Empty;
/// <summary>
- /// The arguments to the command. This is everything after the command
+ /// The raw arguments to the command. This is everything after the command
/// </summary>
- public string Arguments { get; init; } = string.Empty;
+ public string RawArguments { get; init; } = string.Empty;
+
+ /// <summary>
+ /// A list of arguments to the command.
+ /// This uses <see cref="CommandParsing.ParseArguments"/> mostly for maintainability.
+ /// </summary>
+ public List<string> Arguments { get; init; } = [];
+
/// <summary>
/// Information about the message that the command was received from. This includes the message content, author, etc.
/// Use this to reply to the message, delete it, etc.
/// </summary>
public event Action<Message>? OnMessageReceived;
+ // TODO: consider implementing this in a way where we can unregister it in a similar way
public void RegisterCommandCallback(Action<CommandReceivedEventArgs> callback, string command)
{
OnCommandReceived += args =>
var trimmedInput = content[BotPrefix.Length..].Trim();
var firstSpaceIndex = trimmedInput.IndexOf(' ');
- string command, arguments;
+ string command, rawArguments;
if (firstSpaceIndex == -1)
{
command = trimmedInput;
- arguments = string.Empty;
+ rawArguments = string.Empty;
}
else
{
command = trimmedInput[..firstSpaceIndex];
- arguments = trimmedInput[(firstSpaceIndex + 1)..].Trim();
+ rawArguments = trimmedInput[(firstSpaceIndex + 1)..].Trim();
}
+ var argumentList = new List<string>();
+ CommandParsing.ParseArguments(rawArguments, argumentList);
+
// Raise the event!
OnCommandReceived?.Invoke(new CommandReceivedEventArgs
{
Command = command,
- Arguments = arguments,
+ Arguments = argumentList,
+ RawArguments = rawArguments,
Message = message,
});
return ValueTask.CompletedTask;