Skip to content

Commit 1d37ed2

Browse files
Niloth-ptimabbott
authored andcommitted
bots: Rename BotHandler to AbstractBotHandler.
Fixes #690.
1 parent fb73220 commit 1d37ed2

File tree

42 files changed

+155
-143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+155
-143
lines changed

packaged_helloworld/packaged_helloworld/packaged_helloworld.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Any, Dict
33

44
import packaged_helloworld
5-
from zulip_bots.lib import BotHandler
5+
from zulip_bots.lib import AbstractBotHandler
66

77
__version__ = packaged_helloworld.__version__
88

@@ -17,7 +17,7 @@ def usage(self) -> str:
1717
sophisticated, bots that can be installed separately.
1818
"""
1919

20-
def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None:
20+
def handle_message(self, message: Dict[str, Any], bot_handler: AbstractBotHandler) -> None:
2121
content = "beep boop"
2222
bot_handler.send_reply(message, content)
2323

zulip_bots/zulip_bots/bots/baremetrics/baremetrics.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
import requests
66

7-
from zulip_bots.lib import BotHandler
7+
from zulip_bots.lib import AbstractBotHandler
88

99

1010
class BaremetricsHandler:
11-
def initialize(self, bot_handler: BotHandler) -> None:
11+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
1212
self.config_info = bot_handler.get_config_info("baremetrics")
1313
self.api_key = self.config_info["api_key"]
1414

@@ -38,7 +38,7 @@ def initialize(self, bot_handler: BotHandler) -> None:
3838

3939
self.check_api_key(bot_handler)
4040

41-
def check_api_key(self, bot_handler: BotHandler) -> None:
41+
def check_api_key(self, bot_handler: AbstractBotHandler) -> None:
4242
url = "https://api.baremetrics.com/v1/account"
4343
test_query_response = requests.get(url, headers=self.auth_header)
4444
test_query_data = test_query_response.json()
@@ -57,7 +57,7 @@ def usage(self) -> str:
5757
Version 1.0
5858
"""
5959

60-
def handle_message(self, message: Dict[str, Any], bot_handler: BotHandler) -> None:
60+
def handle_message(self, message: Dict[str, Any], bot_handler: AbstractBotHandler) -> None:
6161
content = message["content"].strip().split()
6262

6363
if content == []:

zulip_bots/zulip_bots/bots/beeminder/beeminder.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import requests
55
from requests.exceptions import ConnectionError
66

7-
from zulip_bots.lib import BotHandler
7+
from zulip_bots.lib import AbstractBotHandler
88

99
help_message = """
1010
You can add datapoints towards your beeminder goals \
@@ -80,7 +80,7 @@ class BeeminderHandler:
8080
towards their beeminder goals via zulip
8181
"""
8282

83-
def initialize(self, bot_handler: BotHandler) -> None:
83+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
8484
self.config_info = bot_handler.get_config_info("beeminder")
8585
# Check for valid auth_token
8686
auth_token = self.config_info["auth_token"]
@@ -96,7 +96,7 @@ def initialize(self, bot_handler: BotHandler) -> None:
9696
def usage(self) -> str:
9797
return "This plugin allows users to add datapoints towards their Beeminder goals"
9898

99-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
99+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
100100
response = get_beeminder_response(message["content"], self.config_info)
101101
bot_handler.send_reply(message, response)
102102

zulip_bots/zulip_bots/bots/chessbot/chessbot.py

+14-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import chess
66
import chess.engine
77

8-
from zulip_bots.lib import BotHandler
8+
from zulip_bots.lib import AbstractBotHandler
99

1010
START_REGEX = re.compile("start with other user$")
1111
START_COMPUTER_REGEX = re.compile("start as (?P<user_color>white|black) with computer")
@@ -24,7 +24,7 @@ def usage(self) -> str:
2424
"Stockfish program on this computer."
2525
)
2626

27-
def initialize(self, bot_handler: BotHandler) -> None:
27+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
2828
self.config_info = bot_handler.get_config_info("chess")
2929

3030
try:
@@ -36,7 +36,7 @@ def initialize(self, bot_handler: BotHandler) -> None:
3636
# runner is testing or knows they won't be using an engine.
3737
print("That Stockfish doesn't exist. Continuing.")
3838

39-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
39+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
4040
content = message["content"]
4141

4242
if content == "":
@@ -76,7 +76,7 @@ def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> No
7676
elif resign_regex_match:
7777
self.resign(message, bot_handler, last_fen)
7878

79-
def start(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
79+
def start(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
8080
"""Starts a game with another user, with the current user as white.
8181
Replies to the bot handler.
8282
@@ -93,7 +93,7 @@ def start(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
9393
bot_handler.storage.put("last_fen", new_board.fen())
9494

9595
def start_computer(
96-
self, message: Dict[str, str], bot_handler: BotHandler, is_white_user: bool
96+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, is_white_user: bool
9797
) -> None:
9898
"""Starts a game with the computer. Replies to the bot handler.
9999
@@ -123,7 +123,7 @@ def start_computer(
123123
)
124124

125125
def validate_board(
126-
self, message: Dict[str, str], bot_handler: BotHandler, fen: str
126+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, fen: str
127127
) -> Optional[chess.Board]:
128128
"""Validates a board based on its FEN string. Replies to the bot
129129
handler if there is an error with the board.
@@ -147,7 +147,7 @@ def validate_board(
147147
def validate_move(
148148
self,
149149
message: Dict[str, str],
150-
bot_handler: BotHandler,
150+
bot_handler: AbstractBotHandler,
151151
last_board: chess.Board,
152152
move_san: str,
153153
is_computer: object,
@@ -180,7 +180,7 @@ def validate_move(
180180
return move
181181

182182
def check_game_over(
183-
self, message: Dict[str, str], bot_handler: BotHandler, new_board: chess.Board
183+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, new_board: chess.Board
184184
) -> bool:
185185
"""Checks if a game is over due to
186186
- checkmate,
@@ -224,7 +224,7 @@ def check_game_over(
224224
return False
225225

226226
def move(
227-
self, message: Dict[str, str], bot_handler: BotHandler, last_fen: str, move_san: str
227+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, last_fen: str, move_san: str
228228
) -> None:
229229
"""Makes a move for a user in a game with another user. Replies to
230230
the bot handler.
@@ -256,7 +256,7 @@ def move(
256256
bot_handler.storage.put("last_fen", new_board.fen())
257257

258258
def move_computer(
259-
self, message: Dict[str, str], bot_handler: BotHandler, last_fen: str, move_san: str
259+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, last_fen: str, move_san: str
260260
) -> None:
261261
"""Preforms a move for a user in a game with the computer and then
262262
makes the computer's move. Replies to the bot handler. Unlike `move`,
@@ -306,7 +306,7 @@ def move_computer(
306306
bot_handler.storage.put("last_fen", new_board_after_computer_move.fen())
307307

308308
def move_computer_first(
309-
self, message: Dict[str, str], bot_handler: BotHandler, last_fen: str
309+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, last_fen: str
310310
) -> None:
311311
"""Preforms a move for the computer without having the user go first in
312312
a game with the computer. Replies to the bot handler. Like
@@ -345,7 +345,9 @@ def move_computer_first(
345345
# `bot_handler`'s `storage` only accepts `str` values.
346346
bot_handler.storage.put("is_with_computer", str(True))
347347

348-
def resign(self, message: Dict[str, str], bot_handler: BotHandler, last_fen: str) -> None:
348+
def resign(
349+
self, message: Dict[str, str], bot_handler: AbstractBotHandler, last_fen: str
350+
) -> None:
349351
"""Resigns the game for the current player.
350352
351353
Parameters:

zulip_bots/zulip_bots/bots/converter/converter.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import Any, Dict, List
66

77
from zulip_bots.bots.converter import utils
8-
from zulip_bots.lib import BotHandler
8+
from zulip_bots.lib import AbstractBotHandler
99

1010

1111
def is_float(value: Any) -> bool:
@@ -49,12 +49,12 @@ def usage(self) -> str:
4949
all supported units.
5050
"""
5151

52-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
52+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
5353
bot_response = get_bot_converter_response(message, bot_handler)
5454
bot_handler.send_reply(message, bot_response)
5555

5656

57-
def get_bot_converter_response(message: Dict[str, str], bot_handler: BotHandler) -> str:
57+
def get_bot_converter_response(message: Dict[str, str], bot_handler: AbstractBotHandler) -> str:
5858
content = message["content"]
5959

6060
words = content.lower().split()

zulip_bots/zulip_bots/bots/define/define.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import html2text
77
import requests
88

9-
from zulip_bots.lib import BotHandler
9+
from zulip_bots.lib import AbstractBotHandler
1010

1111

1212
class DefineHandler:
@@ -27,7 +27,7 @@ def usage(self) -> str:
2727
messages with @mention-bot.
2828
"""
2929

30-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
30+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
3131
original_content = message["content"].strip()
3232
bot_response = self.get_bot_define_response(original_content)
3333

zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import apiai
77

8-
from zulip_bots.lib import BotHandler
8+
from zulip_bots.lib import AbstractBotHandler
99

1010
help_message = """DialogFlow bot
1111
This bot will interact with dialogflow bots.
@@ -47,7 +47,7 @@ class DialogFlowHandler:
4747
DialogFlow bots to zulip
4848
"""
4949

50-
def initialize(self, bot_handler: BotHandler) -> None:
50+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
5151
self.config_info = bot_handler.get_config_info("dialogflow")
5252

5353
def usage(self) -> str:
@@ -56,7 +56,7 @@ def usage(self) -> str:
5656
DialogFlow bots to zulip
5757
"""
5858

59-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
59+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
6060
result = get_bot_result(message["content"], self.config_info, message["sender_id"])
6161
bot_handler.send_reply(message, result)
6262

zulip_bots/zulip_bots/bots/dropbox_share/dropbox_share.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from dropbox import Dropbox
55

6-
from zulip_bots.lib import BotHandler
6+
from zulip_bots.lib import AbstractBotHandler
77

88
URL = "[{name}](https://www.dropbox.com/home{path})"
99

@@ -14,15 +14,15 @@ class DropboxHandler:
1414
between zulip and your dropbox account.
1515
"""
1616

17-
def initialize(self, bot_handler: BotHandler) -> None:
17+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
1818
self.config_info = bot_handler.get_config_info("dropbox_share")
1919
self.ACCESS_TOKEN = self.config_info.get("access_token")
2020
self.client = Dropbox(self.ACCESS_TOKEN)
2121

2222
def usage(self) -> str:
2323
return get_help()
2424

25-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
25+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
2626
command = message["content"]
2727
if command == "":
2828
command = "help"

zulip_bots/zulip_bots/bots/encrypt/encrypt.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict
22

3-
from zulip_bots.lib import BotHandler
3+
from zulip_bots.lib import AbstractBotHandler
44

55

66
def encrypt(text: str) -> str:
@@ -34,7 +34,7 @@ def usage(self) -> str:
3434
Feeding encrypted messages into the bot decrypts them.
3535
"""
3636

37-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
37+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
3838
bot_response = self.get_bot_encrypt_response(message)
3939
bot_handler.send_reply(message, bot_response)
4040

zulip_bots/zulip_bots/bots/file_uploader/file_uploader.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import Dict
44

5-
from zulip_bots.lib import BotHandler
5+
from zulip_bots.lib import AbstractBotHandler
66

77

88
class FileUploaderHandler:
@@ -13,7 +13,7 @@ def usage(self) -> str:
1313
"\n- @uploader help : Display help message"
1414
)
1515

16-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
16+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
1717
help_str = (
1818
"Use this bot with any of the following commands:"
1919
"\n* `@uploader <local_file_path>` : Upload a file, where `<local_file_path>` is the path to the file"

zulip_bots/zulip_bots/bots/flock/flock.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import requests
55
from requests.exceptions import ConnectionError
66

7-
from zulip_bots.lib import BotHandler
7+
from zulip_bots.lib import AbstractBotHandler
88

99
USERS_LIST_URL = "https://api.flock.co/v1/roster.listContacts"
1010
SEND_MESSAGE_URL = "https://api.flock.co/v1/chat.sendMessage"
@@ -97,14 +97,14 @@ class FlockHandler:
9797
flock user without having to leave Zulip.
9898
"""
9999

100-
def initialize(self, bot_handler: BotHandler) -> None:
100+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
101101
self.config_info = bot_handler.get_config_info("flock")
102102

103103
def usage(self) -> str:
104104
return """Hello from Flock Bot. You can send messages to any Flock user
105105
right from Zulip."""
106106

107-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
107+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
108108
response = get_flock_bot_response(message["content"], self.config_info)
109109
bot_handler.send_reply(message, response)
110110

zulip_bots/zulip_bots/bots/followup/followup.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# See readme.md for instructions on running this code.
22
from typing import Dict
33

4-
from zulip_bots.lib import BotHandler
4+
from zulip_bots.lib import AbstractBotHandler
55

66

77
class FollowupHandler:
@@ -26,11 +26,11 @@ def usage(self) -> str:
2626
called "followup" that your API user can send to.
2727
"""
2828

29-
def initialize(self, bot_handler: BotHandler) -> None:
29+
def initialize(self, bot_handler: AbstractBotHandler) -> None:
3030
self.config_info = bot_handler.get_config_info("followup", optional=False)
3131
self.stream = self.config_info.get("stream", "followup")
3232

33-
def handle_message(self, message: Dict[str, str], bot_handler: BotHandler) -> None:
33+
def handle_message(self, message: Dict[str, str], bot_handler: AbstractBotHandler) -> None:
3434
if message["content"] == "":
3535
bot_response = (
3636
"Please specify the message you want to send to followup stream after @mention-bot"

0 commit comments

Comments
 (0)