Repository: opsdroid/opsdroid

Issue:
Default connector and default room
When writing a skill which originates from something other than a message (e.g cron #26) the response may need to know which room to post into. 

Most chat clients have a default room, like `#general` in Slack. This could be available as a property in the connector so that skills can easily access it. 

e.g

``` python
@non_message_decorator()
def myskill(opsdroid):
    for connector in opsdroid.connectors:
        message = Message("Message text", connector.default_room, None, connector)
        connector.respond(message)
```

It should also be possible to override the default room in the connector config.

``` yaml
connectors:
  slack:
    default-room: "#random"
```



Discussion:
It would also be good to have a default connector. This could either be the first specified or the one tagged with `default: true` (or the first one tagged in case of error).

e.g

``` yaml
connectors:
  slack:
  shell:
  campfire:
    default: True
```

This could be accessed like:

``` python
@non_message_decorator()
def myskill(opsdroid):
    connector = opsdroid.default_connector
    message = Message("Message text", connector.default_room, None, connector)
    connector.respond(message)
```


Resolving patch:
diff --git a/opsdroid/connector.py b/opsdroid/connector.py
--- a/opsdroid/connector.py
+++ b/opsdroid/connector.py
@@ -24,6 +24,7 @@ def __init__(self, config):
         """
         self.name = ""
         self.config = config
+        self.default_room = None
 
     async def connect(self, opsdroid):
         """Connect to chat service.
diff --git a/opsdroid/core.py b/opsdroid/core.py
--- a/opsdroid/core.py
+++ b/opsdroid/core.py
@@ -46,6 +46,18 @@ def __exit__(self, exc_type, exc_value, traceback):
         """Remove self from existing instances."""
         self.__class__.instances = []
 
+    @property
+    def default_connector(self):
+        """Return the default connector."""
+        default_connector = None
+        for connector in self.connectors:
+            if "default" in connector.config and connector.config["default"]:
+                default_connector = connector
+                break
+        if default_connector is None:
+            default_connector = self.connectors[0]
+        return default_connector
+
     def exit(self):
         """Exit application."""
         logging.info("Exiting application with return code " +


Test patch:
diff --git a/tests/test_connector.py b/tests/test_connector.py
--- a/tests/test_connector.py
+++ b/tests/test_connector.py
@@ -14,6 +14,7 @@ def setUp(self):
     def test_init(self):
         config = {"example_item": "test"}
         connector = Connector(config)
+        self.assertEqual(None, connector.default_room)
         self.assertEqual("", connector.name)
         self.assertEqual("test", connector.config["example_item"])
 
diff --git a/tests/test_core.py b/tests/test_core.py
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -104,6 +104,21 @@ def test_setup_modules(self):
             opsdroid.setup_skills(example_modules)
             self.assertEqual(len(example_modules[0]["module"].mock_calls), 1)
 
+    def test_default_connector(self):
+        with OpsDroid() as opsdroid:
+            mock_connector = Connector({})
+            opsdroid.connectors.append(mock_connector)
+            self.assertEqual(opsdroid.default_connector, mock_connector)
+
+            mock_default_connector = Connector({"default": True})
+            opsdroid.connectors.append(mock_default_connector)
+            self.assertEqual(opsdroid.default_connector,
+                             mock_default_connector)
+
+    def test_default_room(self):
+        mock_connector = Connector({})
+        self.assertEqual(None, mock_connector.default_room)
+
 
 class TestCoreAsync(asynctest.TestCase):
     """Test the async methods of the opsdroid core class."""