Merge pull request #22 from imomaliev/joke

add !joke command
This commit is contained in:
Anthony Sottile 2020-05-11 10:20:24 -07:00 committed by GitHub
commit f62375eaed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 some_user: !followage another_user
anthonywritescodebot: another_user has been following for 5 years! 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 aiohttp
import aiosqlite import aiosqlite
import async_lru import async_lru
import pyjokes
from humanize import naturaldelta from humanize import naturaldelta
# TODO: allow host / port to be configurable # 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}/') 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+') COMMAND_RE = re.compile(r'!\w+')
SECRET_CMDS = frozenset(('!settoday',)) SECRET_CMDS = frozenset(('!settoday',))

View File

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