diff --git a/utils.py b/utils.py new file mode 100644 index 0000000..583f968 --- /dev/null +++ b/utils.py @@ -0,0 +1,12 @@ +import re + +# Strip bbcode coming into ircBridge from site chatbox +def strip_bbcode(text): + # Matches BBCode tags like [tag], [tag=value], [/tag] + return re.sub(r'\[(\/?)?(color|size|pre|img|url|b|i|u|style)(=[^\]]+)?\]', '', text, flags=re.IGNORECASE) + +# Extract username from an IRC line +def parse_username(line): + if line.startswith(":"): + return line[1:].split("!")[0] + return "UnknownUser"