Skip to content

Commit bcdc043

Browse files
feat: Add aliases support for chat commands and update related tests and views
1 parent 5c230a6 commit bcdc043

7 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/XtremeIdiots.Portal.Web.Tests/Controllers/GameServersControllerTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ public void PopulateConfigFromNamespace_ChatCommandsNamespace_MapsServerOverride
213213
Assert.Equal("tag-fu", fu.RequiredTags);
214214
Assert.Single(fu.Messages);
215215
Assert.Equal("server-fu-{name}", fu.Messages[0].Message);
216+
217+
var commands = model.ChatCommands.Commands.Single(x => x.Name == "commands");
218+
Assert.Equal(["!help"], commands.Aliases);
216219
}
217220

218221
[Fact]

src/XtremeIdiots.Portal.Web.Tests/Controllers/GlobalSettingsControllerTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
using MX.Api.Abstractions;
1010
using MX.Observability.ApplicationInsights.Auditing;
1111
using Newtonsoft.Json;
12+
using System.Net;
1213
using System.Reflection;
1314
using System.Security.Claims;
14-
using System.Net;
1515
using XtremeIdiots.Portal.Repository.Abstractions.Models.V1.Configurations;
1616
using XtremeIdiots.Portal.Repository.Api.Client.V1;
1717
using XtremeIdiots.Portal.Web.Controllers;
@@ -138,6 +138,9 @@ public void PopulateModelFromNamespace_ChatCommandsNamespace_MapsDefaultsAndFuMe
138138
Assert.Single(fu.Messages);
139139
Assert.Equal("fu-{name}", fu.Messages[0].Message);
140140
Assert.True(fu.Messages[0].Enabled);
141+
142+
var commands = model.ChatCommands.Commands.Single(x => x.Name == "commands");
143+
Assert.Equal(["!help"], commands.Aliases);
141144
}
142145

143146
[Fact]

src/XtremeIdiots.Portal.Web.Tests/ViewModels/GlobalSettingsViewModelTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel.DataAnnotations;
2+
using System.Linq;
23
using XtremeIdiots.Portal.Web.ViewModels;
34

45
namespace XtremeIdiots.Portal.Web.Tests.ViewModels;
@@ -44,4 +45,14 @@ public void Validate_WhenFunnyMessageIs120Characters_IsValid()
4445

4546
Assert.True(isValid);
4647
}
48+
49+
[Fact]
50+
public void ChatCommands_DefaultCommandsIncludeAliases()
51+
{
52+
var model = new ChatCommandGlobalSettingsViewModel();
53+
54+
var commands = model.Commands.Single(x => x.Name == "commands");
55+
56+
Assert.Equal(["!help"], commands.Aliases);
57+
}
4758
}

src/XtremeIdiots.Portal.Web/ViewModels/ChatCommandSettingsViewModels.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public class ChatCommandGlobalSettingsViewModel : IValidatableObject
4444
Prefix = descriptor.Prefix,
4545
Usage = descriptor.Usage,
4646
Description = descriptor.Description,
47-
IsMutating = descriptor.IsMutating
47+
IsMutating = descriptor.IsMutating,
48+
Aliases = descriptor.Aliases?.ToList() ?? []
4849
})
4950
.ToList();
5051

@@ -67,7 +68,8 @@ public class ChatCommandServerSettingsViewModel : IValidatableObject
6768
Prefix = descriptor.Prefix,
6869
Usage = descriptor.Usage,
6970
Description = descriptor.Description,
70-
IsMutating = descriptor.IsMutating
71+
IsMutating = descriptor.IsMutating,
72+
Aliases = descriptor.Aliases?.ToList() ?? []
7173
})
7274
.ToList();
7375

@@ -92,6 +94,8 @@ public abstract class ChatCommandEntryViewModelBase
9294

9395
public bool IsMutating { get; set; }
9496

97+
public List<string> Aliases { get; set; } = [];
98+
9599
[DisplayName("Enabled")]
96100
public bool? Enabled { get; set; }
97101

src/XtremeIdiots.Portal.Web/Views/GameServers/ConfigurationSections/_ChatCommandsConfiguration.cshtml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ StringComparison.OrdinalIgnoreCase));
4646
<input type="hidden" asp-for="ChatCommands.Commands[i].Usage" />
4747
<input type="hidden" asp-for="ChatCommands.Commands[i].Description" />
4848
<input type="hidden" asp-for="ChatCommands.Commands[i].IsMutating" />
49+
@for (var aliasIndex = 0; aliasIndex < command.Aliases.Count; aliasIndex++)
50+
{
51+
<input type="hidden" asp-for="ChatCommands.Commands[i].Aliases[aliasIndex]" />
52+
}
4953

5054
<div class="mb-3">
5155
<div class="small text-muted">@command.Usage</div>
56+
@if (command.Aliases.Count > 0)
57+
{
58+
<div class="small text-muted">Aliases: @string.Join(", ", command.Aliases)</div>
59+
}
5260
<p class="text-muted mb-0">@command.Description</p>
5361
</div>
5462

src/XtremeIdiots.Portal.Web/Views/GlobalSettings/_ChatCommandsConfiguration.cshtml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@
100100
<input type="hidden" asp-for="ChatCommands.Commands[i].Usage" />
101101
<input type="hidden" asp-for="ChatCommands.Commands[i].Description" />
102102
<input type="hidden" asp-for="ChatCommands.Commands[i].IsMutating" />
103+
@for (var aliasIndex = 0; aliasIndex < command.Aliases.Count; aliasIndex++)
104+
{
105+
<input type="hidden" asp-for="ChatCommands.Commands[i].Aliases[aliasIndex]" />
106+
}
103107

104108
<div class="d-flex justify-content-between align-items-start mb-3">
105109
<div>
106110
<h6 class="mb-1">@command.Prefix</h6>
111+
@if (command.Aliases.Count > 0)
112+
{
113+
<div class="small text-muted mb-1">
114+
Aliases: @string.Join(", ", command.Aliases)
115+
</div>
116+
}
107117
<div class="small text-muted mb-1">@command.Usage</div>
108118
<p class="text-muted mb-0">@command.Description</p>
109119
</div>

src/XtremeIdiots.Portal.Web/XtremeIdiots.Portal.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<PackageReference Include="MX.Api.Abstractions" Version="2.3.31" />
4949
<PackageReference Include="MX.Api.Client" Version="2.3.31" />
5050
<PackageReference Include="XtremeIdiots.Portal.Integrations.Servers.Api.Client.V1" Version="2.1.180" />
51-
<PackageReference Include="XtremeIdiots.Portal.ChatCommands.Abstractions.V1" Version="1.1.74" />
51+
<PackageReference Include="XtremeIdiots.Portal.ChatCommands.Abstractions.V1" Version="1.1.77" />
5252
<PackageReference Include="XtremeIdiots.Portal.Repository.Api.Client.V1" Version="2.1.250" />
5353
<PackageReference Include="XtremeIdiots.Portal.Repository.Abstractions.V1" Version="2.1.250" />
5454
<PackageReference Include="MX.GeoLocation.Api.Client.V1" Version="1.2.39" />

0 commit comments

Comments
 (0)