feat: add command control

This commit is contained in:
Anna 2021-09-24 14:35:59 -04:00
parent 600ad5af3d
commit 18d9039a68
1 changed files with 72 additions and 1 deletions

View File

@ -18,7 +18,78 @@ namespace NominaOcculta {
}
private void OnCommand(string command, string arguments) {
this.Plugin.Ui.Visible ^= true;
arguments = arguments.Trim();
if (arguments.Length == 0) {
this.Plugin.Ui.Visible ^= true;
return;
}
var first = arguments.Split(' ', 2);
bool? enable;
switch (first[0]) {
case "enable":
enable = true;
break;
case "disable":
enable = false;
break;
case "toggle":
enable = null;
break;
case "reset":
this.Plugin.NameRepository.Reset();
return;
default:
this.Plugin.ChatGui.PrintError($"Invalid operation \"{first[0]}\", was expecting enable, disable, toggle, or reset.");
return;
}
string? rest = null;
if (first.Length > 1) {
rest = first[1];
}
void Set(ref bool setting) {
if (enable == null) {
setting ^= true;
} else {
setting = enable.Value;
}
}
switch (rest) {
case null:
Set(ref this.Plugin.Config.Enabled);
break;
case "self":
Set(ref this.Plugin.Config.SelfFull);
Set(ref this.Plugin.Config.SelfFirst);
Set(ref this.Plugin.Config.SelfLast);
break;
case "self full":
Set(ref this.Plugin.Config.SelfFull);
break;
case "self first":
Set(ref this.Plugin.Config.SelfFirst);
break;
case "self last":
Set(ref this.Plugin.Config.SelfLast);
break;
case "party":
Set(ref this.Plugin.Config.Party);
break;
case "others":
Set(ref this.Plugin.Config.Others);
break;
case "exclude friends":
Set(ref this.Plugin.Config.ExcludeFriends);
break;
default:
this.Plugin.ChatGui.PrintError($"Invalid option \"{rest}\".");
return;
}
this.Plugin.SaveConfig();
}
}
}