attempt to fix title casing

kate
udf 2018-11-01 23:04:15 +02:00
parent 2ba0debfea
commit b28f2c5b35
Signed by: kate
GPG Key ID: E40724BAD73AF77B
1 changed files with 11 additions and 1 deletions

View File

@ -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"