From 79f014ab698728ffad0268c0bb06b4cd32e86ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 16 Oct 2019 10:22:51 +0200 Subject: [PATCH] name formatting changes (initial + last_name; truncating) --- dudlebot.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dudlebot.py b/dudlebot.py index f68450c..082a8a7 100644 --- a/dudlebot.py +++ b/dudlebot.py @@ -12,6 +12,8 @@ from telegram.ext import Updater, CommandHandler, PicklePersistence class DudleBot: + LINE_LIMIT = 9 + def __init__(self, token): self.logger = logging.getLogger("dudle") @@ -80,7 +82,7 @@ class DudleBot: responses.append(PlanResponse.UNKNOWN) user = update.message.from_user - name = user.username or f"{user.first_name} {user.last_name}" + name = user.username or ((user.first_name[0] + ". ") if user.first_name else '') + user.last_name context.chat_data['plan'].entries[user.id] = PlanEntry(name=name, responses=responses) @@ -113,8 +115,7 @@ class DudleBot: update.message.reply_text(response) - @staticmethod - def _reply_with_plan(update, context): + def _reply_with_plan(self, update, context): plan: Plan = context.chat_data['plan'] formatted_plan = f"Poll: {plan.start.strftime('%d.%m.%Y')} -> " \ @@ -138,7 +139,8 @@ class DudleBot: for response in responses: formatted_plan += f"{str(response)} " - formatted_plan += f" {entry.name}" + formatted_plan += entry.name if len(entry.name) < self.LINE_LIMIT \ + else entry[:self.LINE_LIMIT - 2] + "…" formatted_plan += "\n" formatted_plan += "```"