mypy: Add annotations for define.
This commit is contained in:
parent
d33e9b9d92
commit
b382eacd18
|
@ -5,6 +5,8 @@ import requests
|
|||
import html2text
|
||||
import string
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
class DefineHandler(object):
|
||||
'''
|
||||
This plugin define a word that the user inputs. It
|
||||
|
@ -17,19 +19,19 @@ class DefineHandler(object):
|
|||
PHRASE_ERROR_MESSAGE = 'Definitions for phrases are not available.'
|
||||
SYMBOLS_PRESENT_ERROR_MESSAGE = 'Definitions of words with symbols are not possible.'
|
||||
|
||||
def usage(self):
|
||||
def usage(self) -> str:
|
||||
return '''
|
||||
This plugin will allow users to define a word. Users should preface
|
||||
messages with @mention-bot.
|
||||
'''
|
||||
|
||||
def handle_message(self, message, bot_handler):
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
original_content = message['content'].strip()
|
||||
bot_response = self.get_bot_define_response(original_content)
|
||||
|
||||
bot_handler.send_reply(message, bot_response)
|
||||
|
||||
def get_bot_define_response(self, original_content):
|
||||
def get_bot_define_response(self, original_content: str) -> str:
|
||||
split_content = original_content.split(' ')
|
||||
# If there are more than one word (a phrase)
|
||||
if len(split_content) > 1:
|
||||
|
@ -66,7 +68,7 @@ class DefineHandler(object):
|
|||
|
||||
except Exception as e:
|
||||
response += self.REQUEST_ERROR_MESSAGE
|
||||
logging.exception(e)
|
||||
logging.exception("")
|
||||
|
||||
return response
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from zulip_bots.test_lib import StubBotTestCase
|
|||
class TestDefineBot(StubBotTestCase):
|
||||
bot_name = "define"
|
||||
|
||||
def test_bot(self):
|
||||
def test_bot(self) -> None:
|
||||
|
||||
# Only one type(noun) of word.
|
||||
bot_response = ("**cat**:\n\n* (**noun**) a small domesticated carnivorous mammal "
|
||||
|
|
Loading…
Reference in a new issue