idonethis: Remove unreachable code & simplify response generation.

Also remove unnecessary import.
This commit is contained in:
neiljp (Neil Pilgrim) 2018-05-27 17:25:14 -07:00 committed by showell
parent 4e19a7716d
commit dbe44a2774

View file

@ -1,4 +1,3 @@
import sys
import requests import requests
import logging import logging
import re import re
@ -65,40 +64,39 @@ def api_create_entry(body: str, team_id: str) -> Any:
return make_API_request("/entries", "POST", {"body": body, "team_id": team_id}) return make_API_request("/entries", "POST", {"body": body, "team_id": team_id})
def list_steams() -> str: def list_steams() -> str:
data = api_list_team() response = ["Teams:"] + [" * " + team['name'] for team in api_list_team()] + [""]
response = "Teams:\n" return "\n".join(response)
for team in data:
response += " * " + team['name'] + "\n"
return response
def get_team_hash(team_name: str) -> str: def get_team_hash(team_name: str) -> str:
data = api_list_team() for team in api_list_team():
for team in data:
if team['name'].lower() == team_name.lower() or team['hash_id'] == team_name: if team['name'].lower() == team_name.lower() or team['hash_id'] == team_name:
return team['hash_id'] return team['hash_id']
raise TeamNotFoundException(team_name) raise TeamNotFoundException(team_name)
def team_info(team_name: str) -> str: def team_info(team_name: str) -> str:
data = api_show_team(get_team_hash(team_name)) data = api_show_team(get_team_hash(team_name))
response = "Team Name: " + data['name'] + "\n" return "\n".join(["Team Name: {name}",
response += "ID: `" + data['hash_id'] + "`\n" "ID: `{hash_id}`",
response += "Created at: " + data['created_at'] + "\n" "Created at: {created_at}", ""]).format(**data)
return response
def entries_list(team_name: str) -> str: def entries_list(team_name: str) -> str:
if team_name: if team_name:
data = api_list_entries(get_team_hash(team_name)) data = api_list_entries(get_team_hash(team_name))
response = "Entries for " + team_name + ":\n" response = "Entries for {}:\n".format(team_name)
else: else:
data = api_list_entries() data = api_list_entries()
response = "Entries for all teams:\n" response = "Entries for all teams:\n"
for entry in data: for entry in data:
response += " * " + entry['body_formatted'] + "\n" response += "\n".join(
response += " * Created at: " + entry['created_at'] + "\n" [" * {body_formatted}",
response += " * Status: " + entry['status'] + "\n" " * Created at: {created_at}",
response += " * User: " + entry['user']['full_name'] + "\n" " * Status: {status}",
response += " * Team: " + entry['team']['name'] + "\n" " * User: {username}",
response += " * ID: " + entry['hash_id'] + "\n" " * Team: {teamname}",
" * ID: {hash_id}",
""]).format(username=entry['user']['full_name'],
teamname=entry['team']['name'],
**entry)
return response return response
def create_entry(message: str) -> str: def create_entry(message: str) -> str:
@ -185,8 +183,6 @@ Below are some of the commands you can use, and what they do.
def get_response(self, message: Dict[str, Any]) -> str: def get_response(self, message: Dict[str, Any]) -> str:
message_content = message['content'].strip().split() message_content = message['content'].strip().split()
if message_content == "":
return ""
reply = "" reply = ""
try: try:
command = " ".join(message_content[:2]) command = " ".join(message_content[:2])