irc.py: duplicate some code to avoid scanning the line twice