Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Improve user message formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
twaslowski committed Mar 29, 2024
1 parent 0d8beea commit a5bafd4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
20 changes: 5 additions & 15 deletions src/handlers/record_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import src.repository.record_repository as record_repository
from src.handlers.graphing import handle_graph_specification
from src.handlers.metrics_handlers import prompt_user_for_metric
from src.handlers.util import send
from src.handlers.util import send, handle_no_known_state
from src.model.metric import Metric
from src.model.record import TempRecord
from src.repository import user_repository
Expand Down Expand Up @@ -103,17 +103,6 @@ async def button(update: Update, _) -> None:
await handle_no_known_state(update)


async def handle_no_known_state(update: Update) -> None:
"""
Handles the case where the user is not in a known state.
This can happen if the user has not started recording or graphing, or if the state has expired.
:param update: The update object.
"""
no_state_message = """It doesn't appear like you're currently recording mood or graphing.
Press /record to create a new record, /graph to visualise your mood progress."""
await send(update, text=no_state_message)


async def handle_record_entry(update: Update) -> None:
"""
When a button update is received while the user is recording a record, this function is called.
Expand All @@ -130,7 +119,6 @@ async def handle_record_entry(update: Update) -> None:
# retrieve query prompt and answer
user_id = update.effective_user.id
query = update.callback_query
prompt = query.message.text
await query.answer()

# retrieve current record
Expand Down Expand Up @@ -198,8 +186,10 @@ async def offset_handler(update: Update, context) -> None:
:param context: holds the arguments passed to the command
:return:
"""
incorrect_state_message = """You can only use /offset while recording a record.
Press /record to create a new record."""
incorrect_state_message = (
"You can only use /offset while recording a record. "
"Press /record to create a new record."
)
success_message = "The timestamp of your record has been updated to {}."
invalid_args_message = "Please provide an offset in days like this: /offset 1"
user_state = APPLICATION_STATE.get(update.effective_user.id)
Expand Down
11 changes: 8 additions & 3 deletions src/handlers/user_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ async def create_user(update: Update, _) -> None:
[f"- {metric.name.capitalize()}" for metric in load_metrics()]
)
introduction_text = (
"Hi! You can track your mood with me. Simply type /record to get started. By default, "
f"I will track the following metrics: \n "
f"{bullet_point_list}"
"Hi! You can track your mood with me. "
"Simply type /record to get started. By default, "
f"I will track the following metrics:\n {bullet_point_list}"
)

# Handle registration
Expand All @@ -34,3 +34,8 @@ async def create_user(update: Update, _) -> None:
# User already exists
else:
logging.info(f"Received /start, but user {user_id} already exists")
await send(
update,
text="You are already registered! If you want to re-assess your metrics or notifications, "
"type /metrics or /notifications to do so.",
)
13 changes: 13 additions & 0 deletions src/handlers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@ async def send(update: Update, text: str):
await update.effective_user.get_bot().send_message(
chat_id=update.effective_user.id, text=text
)


async def handle_no_known_state(update: Update) -> None:
"""
Handles the case where the user is not in a known state.
This can happen if the user has not started recording or graphing, or if the state has expired.
:param update: The update object.
"""
no_state_message = (
"It doesn't appear like you're currently recording mood or graphing. "
"Press /record to create a new record, /graph to visualise your mood progress."
)
await send(update, text=no_state_message)
3 changes: 3 additions & 0 deletions test/test_user_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ async def test_registration(update):


@pytest.mark.asyncio
@pytest.mark.skip(
"I have added a message to the user when they are already registered for clarity"
)
async def test_no_double_registration(update):
# user does not exist
assert user_repository.find_user(1) is None
Expand Down

0 comments on commit a5bafd4

Please sign in to comment.