From 2ba0debfeab37f17825b25861ecd9c24b72c45c9 Mon Sep 17 00:00:00 2001 From: udf Date: Thu, 1 Nov 2018 23:02:34 +0200 Subject: [PATCH 1/2] clean up imports --- stdplugins/sp_prog_rename.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stdplugins/sp_prog_rename.py b/stdplugins/sp_prog_rename.py index 7cffcb6..801ffad 100644 --- a/stdplugins/sp_prog_rename.py +++ b/stdplugins/sp_prog_rename.py @@ -1,10 +1,9 @@ import asyncio +import re + from telethon import events from telethon.tl.functions.channels import EditTitleRequest -import telethon.utils - -import re prog_tech_id = 1040270887 prog_tech_channel = None From b28f2c5b357a5dc88b065e243386470204ea30e6 Mon Sep 17 00:00:00 2001 From: udf Date: Thu, 1 Nov 2018 23:04:15 +0200 Subject: [PATCH 2/2] attempt to fix title casing --- stdplugins/sp_prog_rename.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/stdplugins/sp_prog_rename.py b/stdplugins/sp_prog_rename.py index 801ffad..1c4c0d8 100644 --- a/stdplugins/sp_prog_rename.py +++ b/stdplugins/sp_prog_rename.py @@ -11,6 +11,16 @@ default_title = "Programming & Tech" lock = asyncio.Lock() +def fix_title(s): + # Ideally this would be a state machine, but ¯\_(ツ)_/¯ + def replace(m): + token = m.group(1) + if token.lower() == 'and': + token = '&' + return token.capitalize() + (' ' if m.group(2) else '') + return re.sub(r'(\S+)(\s+)?', replace, s) + + async def edit_title(title): global prog_tech_channel if prog_tech_channel is None: @@ -23,7 +33,7 @@ async def edit_title(title): @borg.on(events.NewMessage( pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=prog_tech_id)) async def on_name(event): - new_topic = event.pattern_match.group(1).title() + new_topic = fix_title(event.pattern_match.group(1)) new_title = f"Programming & {new_topic}" if "Tech" not in new_title: new_title += " & Tech"