From d1fc72ed12235ab5b991662b7160ef3704728682 Mon Sep 17 00:00:00 2001 From: Matthew Iverson Date: Fri, 29 Nov 2024 01:03:47 -0500 Subject: [PATCH] Upload files to "Modules" --- Modules/tips.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Modules/tips.py b/Modules/tips.py index 4bbbe3a..b6ec358 100644 --- a/Modules/tips.py +++ b/Modules/tips.py @@ -385,14 +385,21 @@ TCODES = [ ] ANSI_ESCAPE_REGEX = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') +TCODE_PATTERN = re.compile(r'(T\d{4}(\.\d{3})?)') # Matches T#### or T####.### def get_random_tip_or_joke(clean=False): - # Pick a random tip or joke and assign a color + # Pick a random tip or joke item = random.choice(TIPS + JOKES + TCODES) - formatted_item = f"{item}" + + # Replace T-Codes with clickable links + def replace_tcode_with_link(match): + tcode = match.group(1) + return f'{tcode}' + + formatted_item = TCODE_PATTERN.sub(replace_tcode_with_link, item) if clean: - # Remove ANSI escape codes if clean output is requested - return ANSI_ESCAPE_REGEX.sub('', formatted_item) - + # Remove HTML tags for clean output + formatted_item = re.sub(r'<[^>]+>', '', formatted_item) + return formatted_item \ No newline at end of file