add !joke command

This commit is contained in:
Sardorbek Imomaliev 2020-05-11 11:21:11 +07:00 committed by Anthony Sottile
parent c7e953743d
commit 27eb77022b
3 changed files with 16 additions and 0 deletions

View File

@ -100,3 +100,12 @@ anthonywritescodebot: cool_user has been following for 3 hours!
some_user: !followage another_user
anthonywritescodebot: another_user has been following for 5 years!
```
### `!joke`
Get a joke
```
anthonywritescode: !joke
anthonywritescodebot: The best thing about a Boolean is even if you are wrong, you are only off by a bit.
```

6
bot.py
View File

@ -25,6 +25,7 @@ from typing import Tuple
import aiohttp
import aiosqlite
import async_lru
import pyjokes
from humanize import naturaldelta
# TODO: allow host / port to be configurable
@ -507,6 +508,11 @@ def cmd_pep(match: Match[str]) -> Response:
return MessageResponse(match, f'https://www.python.org/dev/peps/pep-{n}/')
@handle_message('!joke')
def cmd_joke(match: Match[str]) -> Response:
return MessageResponse(match, esc(pyjokes.get_joke()))
COMMAND_RE = re.compile(r'!\w+')
SECRET_CMDS = frozenset(('!settoday',))

View File

@ -2,3 +2,4 @@ aiohttp
aiosqlite
async-lru
humanize
pyjokes