Skip to content

Commit

Permalink
Compose new user info message
Browse files Browse the repository at this point in the history
  • Loading branch information
TimJentzsch committed Apr 21, 2022
1 parent a234526 commit 2a8d73a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
32 changes: 23 additions & 9 deletions api/slack/commands/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.utils import timezone

from api.models import TranscriptionCheck
from api.serializers import VolunteerSerializer
from api.slack import client
from api.slack.utils import dict_to_table, parse_user
from api.views.misc import Summary
Expand All @@ -29,10 +28,7 @@ def info_cmd(channel: str, message: str) -> None:
elif len(parsed_message) == 2:
user, username = parse_user(parsed_message[1])
if user:
v_data = VolunteerSerializer(user).data
msg = i18n["slack"]["user_info"].format(
username, "\n".join(dict_to_table(v_data))
)
msg = user_info_text(user)
else:
msg = i18n["slack"]["errors"]["unknown_username"].format(username=username)
else:
Expand All @@ -43,11 +39,29 @@ def info_cmd(channel: str, message: str) -> None:

def user_info_text(user: BlossomUser) -> str:
"""Get the info message for the given user."""
general = user_general_info(user)
transcription_quality = user_transcription_quality_info(user)
debug = user_debug_info(user)
name_link = f"<https://reddit.com/u/{user.username}|{user.username}>"
title = f"Info about *{name_link}*:"

return f"TODO\n{general}\n{transcription_quality}\n{debug}"
general = _format_info_section("General", user_general_info(user))
transcription_quality = _format_info_section(
"Transcription Quality", user_transcription_quality_info(user)
)
debug = _format_info_section("Debug Info", user_debug_info(user))

return f"{title}\n\n{general}\n\n{transcription_quality}\n\n{debug}"


def _format_info_section(name: str, section: Dict) -> str:
"""Format a given info section to a readable string.
Example:
*Section name*:
- Key 1: Value 1
- Key 2: Value 2
"""
section_items = "\n".join([f"- {key}: {value}" for key, value in section.items()])

return f"*{name}*:\n{section_items}"


def user_general_info(user: BlossomUser) -> Dict:
Expand Down
8 changes: 0 additions & 8 deletions blossom/strings/en_US.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ Here's a status update on everything!
```
"""

user_info="""
User info for {0}:
```
{1}
```
"""

github_sponsor_update="{0} GitHub Sponsors: [{1}] - {2} | {3} {0}"

[slack.errors]
Expand Down

0 comments on commit 2a8d73a

Please sign in to comment.