private static String FindCommand(String message, IDBController controller) { // Try and find our plugin at the start List<PluginDAO> plugins = controller.RetrieveEnabledPlugins(); foreach (PluginDAO plugin in plugins) { if (message.StartsWith(plugin.Name, StringComparison.OrdinalIgnoreCase)) { return plugin.Name; } } // Get our best guess by seeing if there is the first delimeter int delimiter1Index = message.IndexOf(MessageParser.delimiter); if (delimiter1Index < 0) { // No group specified, so take up until second delimeter int delimiter2Index = message.IndexOf(MessageParser.secondDelimiter); if (delimiter2Index < 0) { // No group stuff so just return the whole message return message; } else { return message.Substring(0, delimiter2Index).Trim(); } } else { // Do we have spaces? (Plugins shouldn't have spaces) string pluginMaybe = message.Substring(0, delimiter1Index).Trim(); if (pluginMaybe.Contains(' ')) { return ""; } else { // We found an plugin! (Hopefully) return pluginMaybe.Trim(); } } }