private void DoParameterSuggestions(int termIdx) { // TODO - null ptr checks for suggestion text box CommandDef commandDef = CommandRegistry.GetCommand(UserInputTerms[0]); if (!commandDef.IsValid()) { SuggestionText.text = "No Matching Commands!"; return; } Assert.IsTrue(commandDef.IsValid()); if (termIdx < 0 || termIdx >= commandDef.Command.GetNumExpectedTerms()) { return; } string[] terms = commandDef.GetCommandFormatAsTerms(); if (termIdx < terms.Length) { terms[termIdx] = "<b><color=#ffffffff>" + terms[termIdx] + "</color></b>"; } SuggestionText.text += Utils.GetCommand(terms) + "\n"; string searchTerm = termIdx < UserInputTerms.Length ? UserInputTerms[termIdx] : ""; int paramIdx = termIdx - 1; var cmd = commandDef.Command; var paramSuggestions = ParameterProcessorRegistry.FindSuggestionsFor(cmd.GetParamType(paramIdx), cmd.GetParameterAttributes(paramIdx), searchTerm, 20); if (paramSuggestions != null) { string suggestionDisplayPrefix = ""; for (int i = 0; i < Mathf.Min(terms.Length, termIdx); i++) { suggestionDisplayPrefix += terms[i] + " "; } suggestionDisplayPrefix = "<color=#ffffff00>" + suggestionDisplayPrefix + "</color>"; for (int i = 0, num = paramSuggestions.Count; i < num; i++) { var paramSuggestion = paramSuggestions[i]; Suggestions.Add(paramSuggestion); SuggestionText.text += suggestionDisplayPrefix + paramSuggestion.Display + "\n"; } } }
private async Task _socket_MessageReceived(SocketMessage arg) { if (_discordClient == null || _reg == null) { return; } if (arg.Channel.Id == _config.CmdChannel) { arg.Content.StartsWith("!"); var args = arg.Content.Split(" "); var cmd = _reg.GetCommand(args[0].Substring(1)); if (cmd == null) { return; } var response = cmd.Execute(_discordClient, _cmdChannel, arg.Content, args); if (response != null) { await _cmdChannel.SendMessageAsync(response); } } }