From fd0cbfc1b9c4fa2fd9f1b691b330af9c108eba4b Mon Sep 17 00:00:00 2001 From: Daniel O'Connell Date: Fri, 29 Sep 2023 14:03:50 +0200 Subject: [PATCH] const for max log message length --- api/src/stampy_chat/logging.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/src/stampy_chat/logging.py b/api/src/stampy_chat/logging.py index 67254af..c58c827 100644 --- a/api/src/stampy_chat/logging.py +++ b/api/src/stampy_chat/logging.py @@ -6,6 +6,8 @@ from stampy_chat.db.session import ItemAdder from stampy_chat.db.models import Interaction +MAX_MESSAGE_LEN = 2000 - 8 + class DiscordHandler(StreamHandler): def emit(self, record): # Ignore messages that come from non chat modules @@ -22,8 +24,8 @@ class DiscordHandler(StreamHandler): if not DISCORD_LOGGING_URL: return - while len(message) > 2000 - 8: - m_section, message = message[:2000 - 8], message[2000 - 8:] + while len(message) > MAX_MESSAGE_LEN: + m_section, message = message[:MAX_MESSAGE_LEN], message[MAX_MESSAGE_LEN:] m_section = "```\n" + m_section + "\n```" DiscordWebhook(url=DISCORD_LOGGING_URL, content=m_section).execute() DiscordWebhook(url=DISCORD_LOGGING_URL, content="```\n" + message + "\n```").execute()