Allow user parameter to be string

This commit is contained in:
Deukhoofd 2018-10-09 17:28:06 +02:00
parent 771a825d9f
commit adc0443dbd
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
2 changed files with 10 additions and 2 deletions

View File

@ -45,7 +45,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
case ParameterType.Remainder: case ParameterType.Remainder:
return $" *(?<{index}>.*)"; return $" *(?<{index}>.*)";
case ParameterType.User: case ParameterType.User:
return $" *(?:<@!*(?<{index}>\\d+)>|(?<{index}>\\d+)(?:$| |\n))"; return $" *(?:<@!*(?<{index}>\\d+)>|(?<{index}>\\d+)|(?<{index}>\\w+)(?:$| |\n))";
case ParameterType.Timespan: case ParameterType.Timespan:
return $" *(?<{index}>\\d+\\.*\\d*[smhd])"; return $" *(?<{index}>\\d+\\.*\\d*[smhd])";
default: default:

View File

@ -45,7 +45,15 @@ namespace DeukBot4.MessageHandlers.CommandHandler.RequestStructure
{ {
return await guild.GetUserAsync(i); return await guild.GetUserAsync(i);
} }
return null; else
{
var t1 = DateTime.UtcNow;
var users = await guild.GetUsersAsync();
var user = users.FirstOrDefault(x =>
x.Username.IndexOf(_value, StringComparison.InvariantCultureIgnoreCase) != -1);
Logger.Main.LogWarning($"Finding user on server took {(DateTime.UtcNow - t1).TotalMilliseconds} ms");
return user;
}
} }
} }
} }