Last active
August 29, 2015 13:56
-
-
Save BlaneyXYZ/7c54f6398dbb0f2e2a09 to your computer and use it in GitHub Desktop.
Autoshorten for @TheFiZi (Now for CloudBot running on python3.4)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cloudbot import hook | |
from cloudbot.util import web | |
import re | |
link_re = re.compile(r'((https?://([-\w\.]+)+(:\d+)?(/([\S/_\.]*(\?\S+)?)?)?))', re.I) | |
@hook.regex(link_re) | |
def autoshorten(match): | |
url = match.group(1) | |
try: | |
return web.shorten(url) | |
except web.ServiceError as e: | |
return e.message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!