Change reply to accept body argument first

This commit is contained in:
Luke Murphy 2021-01-10 19:41:56 +01:00
parent 9709971b7c
commit bca6e6c90a
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
5 changed files with 12 additions and 8 deletions

View File

@ -1,6 +1,9 @@
# xbotlib x.x.x (UNRELEASED)
# xbotlib 0.3.0 (2021-01-10)
- Error out if you don't provide a `react` implementation
- Change `reply` to accept `body` as the first argument
# xbotlib 0.2.0 (2021-01-10)

View File

@ -30,7 +30,7 @@ from xbotlib import Bot
class EchoBot(Bot):
def react(self, message):
if message.type == "chat":
self.reply(to=message.sender, body=message.body)
self.reply(message.body, to=message.sender)
MyBot()
```
@ -54,7 +54,7 @@ underling functions can be extended. For example, if you want to enable more
plugins or add different functionality. If something feels awkward then please
raise a ticket for that. Seamlessness is still a bitch but we're trying anyway.
### Bot.react
> Bot.react(message)
A function which you define in your bot implementation in order to respond to
chat messages. You can respond to both direct messages and group chat messages
@ -65,7 +65,7 @@ Arguments:
- **message**: sent message and metadata (see [message](#message) reference below)
### Bot.reply
> Bot.reply(body, to=None, room=None)
Send back a response to a direct chat message.
@ -75,9 +75,10 @@ Arguments:
- **room**: which room to reply to (group chat)
- **body**: the message to send
### Message
> EasyMessage
A simple message format.
A simple message format. This is the type that you work with when your function
accepts a `message` argument.
Attributes:

View File

@ -11,7 +11,7 @@ class EchoBot(Bot):
def react(self, message):
"""Send back what we get."""
if message.type == "chat":
self.reply(to=message.sender, body=message.body)
self.reply(message.body, to=message.sender)
EchoBot()

View File

@ -24,7 +24,7 @@ class WhisperBot(Bot):
"""Receive direct messages and pass them to group chats."""
if message.type == "chat" and "whisper" in message.body:
_, room, whisper = message.body.split(":")
self.reply(room=room, body=f"*whispers* {whisper}")
self.reply(f"*whispers* {whisper}", room=room)
WhisperBot()

View File

@ -124,7 +124,7 @@ class Bot(ClientXMPP):
except KeyboardInterrupt:
pass
def reply(self, to=None, room=None, body=None):
def reply(self, body, to=None, room=None):
"""Send back a reply."""
if to is None and room is None:
message = "`to` or `room` arguments required for `reply`"