Skip to content

Commit b42339e

Browse files
Copilotsolumath
andcommitted
Move get_content_preview to utils/general.py for reusability
Co-authored-by: solumath <56552845+solumath@users.noreply.github.com>
1 parent 54d0816 commit b42339e

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

cogs/message/cog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
from rubbergod import Rubbergod
1010
from utils import cooldowns
1111
from utils.checks import PermissionsCheck
12+
from utils.general import get_content_preview
1213

13-
from .features import create_message_log_embed, get_content_preview
14+
from .features import create_message_log_embed
1415
from .messages_cz import MessagesCZ
1516
from .modals import MessageModal
1617

cogs/message/features.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
import disnake
44

55
import utils
6-
from config.app_config import config
7-
8-
9-
def get_content_preview(content: str | None, limit: int | None = None) -> str:
10-
"""Get a preview of the message content, truncated if necessary.
11-
12-
Args:
13-
content: The full message content
14-
limit: Maximum length of the preview. If None, uses config value.
15-
16-
Returns:
17-
Truncated content with "..." if it exceeds the limit, otherwise the full content
18-
"""
19-
if limit is None:
20-
limit = config.message_log_content_preview_limit
21-
22-
if not content:
23-
return ""
24-
25-
if len(content) > limit:
26-
return content[:limit] + "..."
27-
return content
286

297

308
async def create_message_log_embed(

cogs/message/modals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import disnake
22

33
from config.app_config import config
4+
from utils.general import get_content_preview
45

5-
from .features import create_message_log_embed, get_content_preview
6+
from .features import create_message_log_embed
67
from .messages_cz import MessagesCZ
78

89

utils/general.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,24 @@ async def edit_msg(inter: disnake.ApplicationCommandInteraction, original_msg: s
234234
new_msg = f"{original_msg}\n{new_msg}"
235235
await inter.edit_original_response(new_msg)
236236
return new_msg
237+
238+
239+
def get_content_preview(content: str | None, limit: int | None = None) -> str:
240+
"""Get a preview of the message content, truncated if necessary.
241+
242+
Args:
243+
content: The full message content
244+
limit: Maximum length of the preview. If None, uses config value.
245+
246+
Returns:
247+
Truncated content with "..." if it exceeds the limit, otherwise the full content
248+
"""
249+
if limit is None:
250+
limit = config.message_log_content_preview_limit
251+
252+
if not content:
253+
return ""
254+
255+
if len(content) > limit:
256+
return content[:limit] + "..."
257+
return content

0 commit comments

Comments
 (0)