Add basic flag parsing support

This commit is contained in:
Ske
2020-02-06 17:47:37 +01:00
parent 2148e29f54
commit 7a1aaf6dbd
2 changed files with 109 additions and 25 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using App.Metrics;
@@ -61,9 +62,10 @@ namespace PluralKit.Bot
/// </summary>
public bool Match(ref string used, params string[] potentialMatches)
{
var arg = PeekArgument();
foreach (var match in potentialMatches)
{
if (PeekArgument().Equals(match, StringComparison.InvariantCultureIgnoreCase))
if (arg.Equals(match, StringComparison.InvariantCultureIgnoreCase))
{
used = PopArgument();
return true;
@@ -81,6 +83,15 @@ namespace PluralKit.Bot
string used = null; // Unused and unreturned, we just yeet it
return Match(ref used, potentialMatches);
}
public bool MatchFlag(params string[] potentialMatches)
{
// Flags are *ALWAYS PARSED LOWERCASE*. This means we skip out on a "ToLower" call here.
// Can assume the caller array only contains lowercase *and* the set below only contains lowercase
var flags = _parameters.Flags();
return potentialMatches.Any(potentialMatch => flags.Contains(potentialMatch));
}
public async Task Execute<T>(Command commandDef, Func<T, Task> handler)
{