Provide a respond function
Closes https://git.autonomic.zone/decentral1se/xbotlib/issues/34.
This commit is contained in:
parent
73df47eb45
commit
e7adfeaa51
@ -3,6 +3,7 @@
|
|||||||
# xbotlib 0.13.1 (2021-01-19)
|
# xbotlib 0.13.1 (2021-01-19)
|
||||||
|
|
||||||
- Document `Bot` attributes/functions ([#35](https://git.autonomic.zone/decentral1se/xbotlib/issues/35))
|
- Document `Bot` attributes/functions ([#35](https://git.autonomic.zone/decentral1se/xbotlib/issues/35))
|
||||||
|
- Provide a `Bot.respond` function ([#34](https://git.autonomic.zone/decentral1se/xbotlib/issues/34))
|
||||||
|
|
||||||
# xbotlib 0.13.0 (2021-01-18)
|
# xbotlib 0.13.0 (2021-01-18)
|
||||||
|
|
||||||
|
12
README.md
12
README.md
@ -134,6 +134,15 @@ Arguments:
|
|||||||
- **to**: the user to send the reply to
|
- **to**: the user to send the reply to
|
||||||
- **room**: the room to send the reply to
|
- **room**: the room to send the reply to
|
||||||
|
|
||||||
|
> Bot.respond(response, content_type="text/html")
|
||||||
|
|
||||||
|
Return a response via the web server.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
|
||||||
|
- **response**: the text of the response
|
||||||
|
- **content_type**: the type of response
|
||||||
|
|
||||||
Other useful attributes on the `Bot` class are:
|
Other useful attributes on the `Bot` class are:
|
||||||
|
|
||||||
- **self.db**: The [Redis database](#redis-key-value-storage) if you're using it
|
- **self.db**: The [Redis database](#redis-key-value-storage) if you're using it
|
||||||
@ -318,12 +327,11 @@ Here's a small example that renders a random ASCII letter.
|
|||||||
|
|
||||||
```python
|
```python
|
||||||
from string import ascii_letters
|
from string import ascii_letters
|
||||||
from xbotlib import Response
|
|
||||||
|
|
||||||
def serve(self, request):
|
def serve(self, request):
|
||||||
letter = choice(ascii_letters)
|
letter = choice(ascii_letters)
|
||||||
rendered = self.template.render(letter=letter)
|
rendered = self.template.render(letter=letter)
|
||||||
return Response(body=rendered, content_type="text/html")
|
return self.respond(body=rendered)
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to pass data from your `direct`/`group` functions to the `serve`
|
If you want to pass data from your `direct`/`group` functions to the `serve`
|
||||||
|
@ -626,3 +626,7 @@ class Bot(ClientXMPP):
|
|||||||
return self.reply(cleandoc(self.help), **kwargs)
|
return self.reply(cleandoc(self.help), **kwargs)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return self.reply("No help found 🤔️", **kwargs)
|
return self.reply("No help found 🤔️", **kwargs)
|
||||||
|
|
||||||
|
def respond(self, response, content_type="text/html"):
|
||||||
|
"""Send this response back with the web server."""
|
||||||
|
return Response(response, content_type=content_type)
|
||||||
|
Reference in New Issue
Block a user