Repository: opsdroid/opsdroid

Issue:
Setting typing delay to 0 means bot never responds
# Description
When a typing delay is defined it is an integer which states how many characters per second opsdroid should type. If you set this to `0` then it can type no characters per second and therefore never responds.


## Steps to Reproduce
- Configure a connector with a `typing-delay` of `0`. 
- Talk to the bot


## Experienced Functionality
The bot never responds.


## Expected Functionality
I would expect the bot to respond eventually. Perhaps even immediately and log an error stating `0` is an invalid response.

Thinking a little more about this I wonder if this functionality is the wrong way round. With `thinking-delay` that is the number of seconds that opsdroid should way before responding, so as the number gets bigger the longer opsdroid waits. But with `typing-delay` it is the number of characters per second that opsdroid can type, so the bigger the number the less opsdroid waits. The word `delay` suggests that the higher the number the longer the wait.

These opposites could be confusing (it confused me this evening). I think it would be good that both numbers represent time, rather than one representing characters per second. That would involve changing it to be seconds per character. This would result in a bigger number causing a bigger delay. 


## Versions
- **Opsdroid version:** master
- **Python version:** 3.5.4
- **OS/Docker version:** macOS 10.13

## Configuration File


```yaml
connectors:
  - name: shell
    typing-delay: 0

skills:
  - name: hello
```



Discussion:
@FabioRosado I would be interested in your thoughts as you implemented this
I agree that both should be measured in seconds to avoid confusion. I can't remember why I decided to go with characters per second to be honest, perhaps it was to divide these two functions because otherwise one would be enough (saying that should we refactor the code to just use one delaying function?)

 I also remember setting a default on that delay but for some reason I didn't added it in the final PR - my bad! I'm happy to fix this issue and change the code if we decide to go with just one function that can take input of the two configuration parameters.

I'm happy with two functions. It makes sense to break it down into thinking about a response and then typing the response.

It would just be good to flip the logic so that both config values represent ascending time.

Resolving patch:
diff --git a/opsdroid/message.py b/opsdroid/message.py
--- a/opsdroid/message.py
+++ b/opsdroid/message.py
@@ -33,13 +33,14 @@ async def _thinking_delay(self):
         await asyncio.sleep(seconds)
 
     async def _typing_delay(self, text):
-        """Simulate typing, takes an int(characters per second typed)."""
-        try:
-            char_per_sec = self.connector.configuration['typing-delay']
-            char_count = len(text)
-            await asyncio.sleep(char_count//char_per_sec)
-        except KeyError:
-            pass
+        """Simulate typing, takes an int or float to delay reply."""
+        seconds = self.connector.configuration.get('typing-delay', 0)
+        char_count = len(text)
+
+        if isinstance(seconds, list):
+            seconds = randrange(seconds[0], seconds[1])
+
+        await asyncio.sleep(char_count*seconds)
 
     async def respond(self, text, room=None):
         """Respond to this message using the connector it was created by."""


Test patch:
diff --git a/tests/test_message.py b/tests/test_message.py
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -94,7 +94,7 @@ async def test_thinking_sleep(self):
     async def test_typing_delay(self):
         mock_connector = Connector({
             'name': 'shell',
-            'typing-delay': 6,
+            'typing-delay': 0.3,
             'type': 'connector',
             'module_path': 'opsdroid-modules.connector.shell'
         })
@@ -108,6 +108,22 @@ async def test_typing_delay(self):
                 self.assertTrue(logmock.called)
                 self.assertTrue(mocksleep.called)
 
+        # Test thinking-delay with a list
+
+        mock_connector_list = Connector({
+            'name': 'shell',
+            'typing-delay': [1, 4],
+            'type': 'connector',
+            'module_path': 'opsdroid-modules.connector.shell'
+        })
+
+        with amock.patch('asyncio.sleep') as mocksleep_list:
+            message = Message("hi", "user", "default", mock_connector_list)
+            with self.assertRaises(NotImplementedError):
+                await message.respond("Hello there")
+
+            self.assertTrue(mocksleep_list.called)
+
     async def test_typing_sleep(self):
         mock_connector = Connector({
             'name': 'shell',