askcompu

Untitled

Jul 21st, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | None | 0 0
  1. def snarfuri(phenny, input):
  2.     if re.match(r'(?i)' + phenny.config.prefix + titlecommands, input.group()):
  3.         return
  4.     uri = input.group(1)
  5.     if input.nick in ('derpy','Chance'):
  6.         return
  7.     try:
  8.         if re.compile('http(s)?://(.*).(jpg|jpeg|png|gif|tiff|bmp)').match(uri):
  9.             return None
  10.        
  11.         title = None
  12.  
  13.         youtube = re.compile('http(s)?://(www.)?youtube.(com|co.uk|ca)?/watch.*\?.*v\=\w+')
  14.         if youtube.match(uri) or re.compile('http(s)?://youtu.be/(.*)').match(uri):
  15.             # due to changes in how Youtube gives out API access, we need a key from the config file
  16.             title = get_youtube_title(uri, phenny.config.youtube_api_key)
  17.  
  18.         fimfiction = re.compile('http(s)?://(www.)?fimfiction.net/story/')
  19.         if fimfiction.match(uri):
  20.             title = get_story_title(uri)
  21.  
  22.         if re.compile('http(s)?://(www.)?((e621)|(e926)).net/post/show/').match(uri): #e621 or e926 link
  23.             title = ouroboros('e621',uri)
  24.  
  25.         if re.compile('http(s)?://(www.)?twentypercentcooler.net/post/show/').match(uri):
  26.             title = ouroboros('twentypercentcooler',uri)
  27.  
  28.         if re.compile('http(s)?://(www.)?derpiboo((.ru)|(ru.org))(/images)?/').match(uri):
  29.             title = derpibooru(uri)
  30.  
  31.         if title:
  32.             phenny.msg(input.sender, '[ ' + title + ' ]')
  33.         else:
  34.             title = gettitle(uri)
  35.             if title: phenny.msg(input.sender, '[ ' + title + ' ]')
  36.     except http.client.HTTPException:
  37.         return
  38. snarfuri.rule = r'.*(http[s]?://[^<> "\x01]+)[,.]?'
  39. snarfuri.priority = 'low'
Advertisement
Add Comment
Please, Sign In to add comment