Fixed adding quotes around Ambiguous for "user": , fixed showing correct casing of arguments.

This commit is contained in:
TheUbMunster 2022-07-27 14:48:18 -06:00 committed by Sanae
parent ba02c88b13
commit 5af8001398
1 changed files with 42 additions and 5 deletions

View File

@ -173,7 +173,7 @@ server.PacketHandler = (c, p) => {
IEnumerable<Client> search = server.Clients.Where(c => c.Connected &&
(c.Name.ToLower().StartsWith(arg.ToLower()) || (Guid.TryParse(arg, out Guid res) && res == c.Id)));
if (!search.Any())
failToFind.Add(arg.ToLower()); //none found
failToFind.Add(arg); //none found
else if (search.Count() > 1) {
Client? exact = search.FirstOrDefault(x => x.Name == arg);
if (!ReferenceEquals(exact, null)) {
@ -184,7 +184,7 @@ server.PacketHandler = (c, p) => {
toActUpon.Add(exact);
}
else {
ambig.Add((arg.ToLower(), search.Select(x => x.Name))); //more than one match
ambig.Add((arg, search.Select(x => x.Name))); //more than one match
foreach (var rem in search.ToList()) //need copy because can't remove from list while iterating over it
toActUpon.Remove(rem);
}
@ -213,7 +213,7 @@ CommandHandler.RegisterCommand("rejoin", args => {
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
if (res.ambig.Count > 0) {
res.ambig.ForEach(x => {
sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
});
sb.Remove(sb.Length - 1, 1); //remove extra nl
}
@ -237,7 +237,7 @@ CommandHandler.RegisterCommand("crash", args => {
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
if (res.ambig.Count > 0) {
res.ambig.ForEach(x => {
sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
});
sb.Remove(sb.Length - 1, 1); //remove extra nl
}
@ -262,6 +262,43 @@ CommandHandler.RegisterCommand("ban", args => {
return "Usage: ban <* | !* (usernames to not ban...) | (usernames to ban...)>";
}
#region Testing
//void TestAddClients()
//{
// Client c1 = new Client(null!);
// c1.Id = new Guid("00000000000000000000000000000000");
// c1.Connected = true;
// c1.Name = "Moo";
// server.Clients.Add(c1);
// Client c2 = new Client(null!);
// c2.Id = new Guid("00000000000000000000000000000001");
// c2.Connected = true;
// c2.Name = "Moomoss";
// server.Clients.Add(c2);
// Client c3 = new Client(null!);
// c3.Id = new Guid("00000000000000000000000000000002");
// c3.Connected = true;
// c3.Name = "mo";
// server.Clients.Add(c3);
// Client c4 = new Client(null!);
// c4.Id = new Guid("00000000000000000000000000000003");
// c4.Connected = true;
// c4.Name = "Bar";
// server.Clients.Add(c4);
// Client c5 = new Client(null!);
// c5.Id = new Guid("00000000000000000000000000000004");
// c5.Connected = true;
// c5.Name = "Foo";
// server.Clients.Add(c5);
//}
//TestAddClients();
#endregion
var res = MultiUserCommandHelper(args);
StringBuilder sb = new StringBuilder();
@ -269,7 +306,7 @@ CommandHandler.RegisterCommand("ban", args => {
sb.Append(res.failToFind.Count > 0 ? "Failed to find matches for: " + string.Join(", ", res.failToFind.Select(x => $"\"{x.ToLower()}\"")) + "\n" : "");
if (res.ambig.Count > 0) {
res.ambig.ForEach(x => {
sb.Append($"Ambiguous for {x.arg}: {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
sb.Append($"Ambiguous for \"{x.arg}\": {string.Join(", ", x.amb.Select(x => $"\"{x}\""))}\n");
});
sb.Remove(sb.Length - 1, 1); //remove extra nl
}