askcompu

Untitled

Jul 21st, 2015
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.70 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.             if get_youtube_title is None:
  17.                 phenny.say("Sorry " + input.nick + " but you need to fix your URL.")
  18.             else:
  19.             title = get_youtube_title(uri, phenny.config.youtube_api_key)
  20.  
  21.         fimfiction = re.compile('http(s)?://(www.)?fimfiction.net/story/')
  22.         if fimfiction.match(uri):
  23.             title = get_story_title(uri)
  24.  
  25.         if re.compile('http(s)?://(www.)?((e621)|(e926)).net/post/show/').match(uri): #e621 or e926 link
  26.             title = ouroboros('e621',uri)
  27.  
  28.         if re.compile('http(s)?://(www.)?twentypercentcooler.net/post/show/').match(uri):
  29.             title = ouroboros('twentypercentcooler',uri)
  30.  
  31.         if re.compile('http(s)?://(www.)?derpiboo((.ru)|(ru.org))(/images)?/').match(uri):
  32.             title = derpibooru(uri)
  33.  
  34.         if title:
  35.             phenny.msg(input.sender, '[ ' + title + ' ]')
  36.         else:
  37.             title = gettitle(uri)
  38.             if title: phenny.msg(input.sender, '[ ' + title + ' ]')
  39.     except http.client.HTTPException:
  40.         return
  41. snarfuri.rule = r'.*(http[s]?://[^<> "\x01]+)[,.]?'
  42. snarfuri.priority = 'low'
Advertisement
Add Comment
Please, Sign In to add comment