forked from uniborg/uniborg
Merge branch 'master' of https://github.com/udf/uniborg
This commit is contained in:
commit
9981c27415
|
@ -1,10 +1,9 @@
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import re
|
||||||
|
|
||||||
from telethon import events
|
from telethon import events
|
||||||
from telethon.tl.functions.channels import EditTitleRequest
|
from telethon.tl.functions.channels import EditTitleRequest
|
||||||
|
|
||||||
import telethon.utils
|
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
prog_tech_id = 1040270887
|
prog_tech_id = 1040270887
|
||||||
prog_tech_channel = None
|
prog_tech_channel = None
|
||||||
|
@ -12,6 +11,16 @@ default_title = "Programming & Tech"
|
||||||
lock = asyncio.Lock()
|
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):
|
async def edit_title(title):
|
||||||
global prog_tech_channel
|
global prog_tech_channel
|
||||||
if prog_tech_channel is None:
|
if prog_tech_channel is None:
|
||||||
|
@ -24,7 +33,7 @@ async def edit_title(title):
|
||||||
@borg.on(events.NewMessage(
|
@borg.on(events.NewMessage(
|
||||||
pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=prog_tech_id))
|
pattern=re.compile(r"(?i)programming (?:&|and) (.+)"), chats=prog_tech_id))
|
||||||
async def on_name(event):
|
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}"
|
new_title = f"Programming & {new_topic}"
|
||||||
if "Tech" not in new_title:
|
if "Tech" not in new_title:
|
||||||
new_title += " & Tech"
|
new_title += " & Tech"
|
||||||
|
|
Loading…
Reference in New Issue