Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Oliver <excid3@gmail.com>2012-02-09 22:32:52 -0600
committerChris Oliver <excid3@gmail.com>2012-02-09 22:32:52 -0600
commit0be9eac469c7eb7699042288060d9b65eea48a53 (patch)
treea734ed8bfcb3a05b935bcb816f4c41385df6896f
parentccbdcd6d3507e6bdcd2952a7c1f19873028f2fad (diff)
Added regex to parse urls. Closes #14
-rw-r--r--logbot.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/logbot.py b/logbot.py
index ecdcaaa..8691d9d 100644
--- a/logbot.py
+++ b/logbot.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python
+# coding: utf-8
+
"""
LogBot
@@ -45,6 +47,15 @@ except:
from ircbot import SingleServerIRCBot
from irclib import nm_to_n
+import re
+
+pat1 = re.compile(r"(^|[\n ])(([\w]+?://[\w\#$%&~.\-;:=,?@\[\]+]*)(/[\w\#$%&~/.\-;:=,?@\[\]+]*)?)", re.IGNORECASE | re.DOTALL)
+
+#urlfinder = re.compile("(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))")
+
+def urlify2(value):
+ return pat1.sub(r'\1<a href="\2" target="_blank">\3</a>', value)
+ #return urlfinder.sub(r'<a href="\1">\1</a>', value)
### Configuration options
DEBUG = False
@@ -190,6 +201,7 @@ class Logbot(SingleServerIRCBot):
# Format the event properly
chans = event.target()
msg = self.format_event(name, event, params)
+ msg = urlify2(msg)
# Quit goes across all channels
if not chans or not chans.startswith("#"):