xkcd bot: Update bot & tests to use bot identity functionality.
This commit is contained in:
parent
f15356c4c8
commit
2b86b9f488
|
@ -44,10 +44,11 @@ class TestXkcdBot(BotTestCase):
|
|||
help_txt = "xkcd bot supports these commands:"
|
||||
err_txt = "xkcd bot only supports these commands, not `{}`:"
|
||||
commands = '''
|
||||
* `@xkcd help` to show this help message.
|
||||
* `@xkcd latest` to fetch the latest comic strip from xkcd.
|
||||
* `@xkcd random` to fetch a random comic strip from xkcd.
|
||||
* `@xkcd <comic id>` to fetch a comic strip based on `<comic id>` e.g `@xkcd 1234`.'''
|
||||
* `{0} help` to show this help message.
|
||||
* `{0} latest` to fetch the latest comic strip from xkcd.
|
||||
* `{0} random` to fetch a random comic strip from xkcd.
|
||||
* `{0} <comic id>` to fetch a comic strip based on `<comic id>` e.g `{0} 1234`.'''.format(
|
||||
"@**test-bot**")
|
||||
self.verify_reply('', err_txt.format('') + commands)
|
||||
self.verify_reply('help', help_txt + commands)
|
||||
# Example invalid command
|
||||
|
|
|
@ -35,7 +35,8 @@ class XkcdHandler(object):
|
|||
'''
|
||||
|
||||
def handle_message(self, message: Dict[str, str], bot_handler: Any) -> None:
|
||||
xkcd_bot_response = get_xkcd_bot_response(message)
|
||||
quoted_name = bot_handler.identity().mention
|
||||
xkcd_bot_response = get_xkcd_bot_response(message, quoted_name)
|
||||
bot_handler.send_reply(message, xkcd_bot_response)
|
||||
|
||||
class XkcdBotCommand(object):
|
||||
|
@ -49,16 +50,16 @@ class XkcdNotFoundError(Exception):
|
|||
class XkcdServerError(Exception):
|
||||
pass
|
||||
|
||||
def get_xkcd_bot_response(message: Dict[str, str]) -> str:
|
||||
def get_xkcd_bot_response(message: Dict[str, str], quoted_name: str) -> str:
|
||||
original_content = message['content'].strip()
|
||||
command = original_content.strip()
|
||||
|
||||
commands_help = ("%s"
|
||||
"\n* `@xkcd help` to show this help message."
|
||||
"\n* `@xkcd latest` to fetch the latest comic strip from xkcd."
|
||||
"\n* `@xkcd random` to fetch a random comic strip from xkcd."
|
||||
"\n* `@xkcd <comic id>` to fetch a comic strip based on `<comic id>` "
|
||||
"e.g `@xkcd 1234`.")
|
||||
"\n* `{0} help` to show this help message."
|
||||
"\n* `{0} latest` to fetch the latest comic strip from xkcd."
|
||||
"\n* `{0} random` to fetch a random comic strip from xkcd."
|
||||
"\n* `{0} <comic id>` to fetch a comic strip based on `<comic id>` "
|
||||
"e.g `{0} 1234`.".format(quoted_name))
|
||||
|
||||
try:
|
||||
if command == 'help':
|
||||
|
|
Loading…
Reference in a new issue