Integrate cleaner colour_emoji function into pytchat_listener.py
This commit is contained in:
@@ -9,6 +9,23 @@ from rich.style import Style
|
|||||||
|
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
|
# Define the emoji pattern and coloring function
|
||||||
|
emoji_pattern = re.compile(
|
||||||
|
r'('
|
||||||
|
r'\U0001F600-\U0001F64F' # emoticons
|
||||||
|
r'\U0001F300-\U0001F5FF' # symbols & pictographs
|
||||||
|
r'\U0001F680-\U0001F6FF' # transport & map symbols
|
||||||
|
r'\U0001F1E0-\U0001F1FF' # flags (iOS)
|
||||||
|
r'\u2702-\u27B0' # Dingbats
|
||||||
|
r'\u24C2-\u2B55' # Enclosed characters
|
||||||
|
r'\U0001F900-\U0001F9FF' # Supplemental Symbols & Pictographs
|
||||||
|
r'\u200D' # ZWJ
|
||||||
|
r'\uFE0F' # VS-16
|
||||||
|
r')+', flags=re.UNICODE)
|
||||||
|
|
||||||
|
def colour_emoji(txt):
|
||||||
|
return emoji_pattern.sub(r'[magenta]\1[/magenta]', txt)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Clear the terminal screen
|
# Clear the terminal screen
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
@@ -38,27 +55,11 @@ def main():
|
|||||||
author_display_name = c.author.name
|
author_display_name = c.author.name
|
||||||
message_text = c.message
|
message_text = c.message
|
||||||
|
|
||||||
# pytchat does not provide explicit emote data like the official API
|
|
||||||
# So we rely on regex for text-based emotes and standard emojis.
|
|
||||||
|
|
||||||
# Process text-based emotes (e.g., :face-purple-sweating:)
|
# Process text-based emotes (e.g., :face-purple-sweating:)
|
||||||
message_text = re.sub(r'(:[a-zA-Z0-9_-]+:)', r'[blue]\1[/blue]', message_text)
|
message_text = re.sub(r'(:[a-zA-Z0-9_-]+:)', r'[blue]\1[/blue]', message_text)
|
||||||
|
|
||||||
# Add coloring for standard emojis
|
# Apply emoji coloring using the new function
|
||||||
emoji_pattern = re.compile(
|
message_text = colour_emoji(message_text)
|
||||||
r"""(
|
|
||||||
\U0001F600-\U0001F64F # emoticons
|
|
||||||
\U0001F300-\U0001F5FF # symbols & pictographs
|
|
||||||
\U0001F680-\U0001F6FF # transport & map symbols
|
|
||||||
\U0001F1E0-\U0001F1FF # flags (iOS)
|
|
||||||
\U00002702-\U000027B0 # Dingbats
|
|
||||||
\U000024C2-\U0001F251 # Enclosed characters
|
|
||||||
\U0001F900-\U0001F9FF # Supplemental Symbols and Pictographs
|
|
||||||
\U0000200D # Zero Width Joiner (for emoji sequences)
|
|
||||||
\U0000FE0F # Variation Selector-16 (for emoji presentation)
|
|
||||||
)+"""
|
|
||||||
, re.UNICODE | re.VERBOSE)
|
|
||||||
message_text = emoji_pattern.sub(r'[magenta]\1[/magenta]', message_text)
|
|
||||||
|
|
||||||
# Alternate background styles
|
# Alternate background styles
|
||||||
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
background_style = Style(bgcolor="#2B2B2B") if message_count % 2 == 0 else Style(bgcolor="#3A3A3A")
|
||||||
@@ -84,4 +85,4 @@ def main():
|
|||||||
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
console.print(f"[green]Chat log saved to {log_filename}[/green]")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
Reference in New Issue
Block a user