Make chat commands case-insensitive

Would be nice if I accidentally have caps lock enabled and write "/HELP" it still works.
This commit is contained in:
wooster0 2024-01-04 15:01:27 +09:00
parent 8b8f7953ec
commit cf5f0a2bdc
2 changed files with 19 additions and 2 deletions

View File

@ -112,7 +112,7 @@ namespace osu.Game.Tests.Chat
});
AddStep("post message", () => channelManager.PostMessage("Something interesting"));
AddUntilStep("message postesd", () => !channel.Messages.Any(m => m is LocalMessage));
AddUntilStep("message posted", () => !channel.Messages.Any(m => m is LocalMessage));
AddStep("post /help command", () => channelManager.PostCommand("help", channel));
AddStep("post /me command with no action", () => channelManager.PostCommand("me", channel));
@ -146,6 +146,23 @@ namespace osu.Game.Tests.Chat
AddAssert("channel has no more messages", () => channel.Messages, () => Is.Empty);
}
[Test]
public void TestCommandNameCaseInsensitivity()
{
Channel channel = null;
AddStep("join channel and select it", () =>
{
channelManager.JoinChannel(channel = createChannel(1, ChannelType.Public));
channelManager.CurrentChannel.Value = channel;
});
AddStep("post /me command", () => channelManager.PostCommand("ME DANCES"));
AddUntilStep("/me command received", () => channel.Messages.Last().Content.Contains("DANCES"));
AddStep("post /help command", () => channelManager.PostCommand("HeLp"));
AddUntilStep("/help command received", () => channel.Messages.Last().Content.Contains("Supported commands"));
}
private void handlePostMessageRequest(PostMessageRequest request)
{
var message = new Message(++currentMessageId)

View File

@ -247,7 +247,7 @@ namespace osu.Game.Online.Chat
string command = parameters[0];
string content = parameters.Length == 2 ? parameters[1] : string.Empty;
switch (command)
switch (command.ToLowerInvariant())
{
case "np":
AddInternal(new NowPlayingCommand(target));