Skip to content

Implement react for TerminalBotHandler #688

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 24, 2021
Merged

Conversation

PIG208
Copy link
Member

@PIG208 PIG208 commented May 13, 2021

Fixes #686.

Enter your message: j

Reply from the bot is printed between the dotted lines:
-------
beep boop
-------
The bot reacts to message #1: wave
Enter your message: p

Reply from the bot is printed between the dotted lines:
-------
beep boop
-------
The bot reacts to message #3: wave

@@ -39,15 +39,22 @@ def update(self, message):
def upload_file(self, file):
return dict(result='success', msg='', uri='https://server/user_uploads/{}'.format(uuid4()))

class TerminalBotHandler:
class TerminalBotHandler(BotHandler):
def __init__(self, bot_config_file):
Copy link
Contributor

@LoopThrough-i-j LoopThrough-i-j May 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think TerminalBotHandler needs to inherit BotHandler, by default all BotHandlers follow the protocol.
I think the subsequent changes made in this commit are enough for that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I kinda feel like this should inherit from AbstractBotHandler once we do that rename.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we inherit a protocol, all properties of the protocol now come into the class even if the class does not implement it. Since the implementation of abstract functions is not a mandate. I would rather recommend creating functions and not inheriting them so that we can come back to them later. Inheriting a Protocol also skips a lot of mypy issues like the ones we faced here which gets caught, if we keep them separate.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not looked deeply at these recent changes but if this is intended to be a Protocol (~ static duck typing), then I agree with @LoopThrough-i-j re not inheriting. It may make it clearer to add a Protocol suffix to BotHandler to indicate that.

PIG208 added 3 commits May 13, 2021 22:03
This makes the user and the bot to share the message server when
sending messages. As a result, the message id can be shared. And history
messages sent by the user will be stored as well.
@LoopThrough-i-j
Copy link
Contributor

I had a look and things look good. @neiljp would you mind reviewing?

@timabbott timabbott merged commit b04f5f9 into zulip:master May 24, 2021
@timabbott
Copy link
Member

This lgtm, merged, thanks @PIG208 and @LoopThrough-i-j!

I think we should do a round of adding docstring/comment documentation to TerminalBotHandler explaining what's going on -- e.g. the send_message function looks like it's doing something twice now, basically because the context isn't clear that it's recording the data in the SimpleMessageServer mock server.

(We might also want to rename SimpleMessageServer to MockZulipServer`, for clarity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement react for TerminalBotHandler.
5 participants