def command( command, message, user, channel ): try: if command != "rurban": link = "http://urbandictionary.com/define.php?term=" + message else: link = "http://www.urbandictionary.com/random.php" res = requests.get( link ) definition = __main__.fixHTMLCharsAdvanced( pybotutils.strbetween( res.text, "<div class='meaning'>\n", "\n</div>" ) ) word = __main__.fixHTMLCharsAdvanced( pybotutils.strbetween( res.text, "<title>Urban Dictionary: ", "</title>" ) ) if definition != "" and word != "": toSend = word + ": " + definition if len( toSend ) >= 440: # This is roughly the longest message I've been able to send. shortLink = pybotutils.googlshort( "http://www.urbandictionary.com/define.php?term=" + message ) # Get a short link here in order to send as much as possible toCutOff = len( shortLink ) # Get the length of said link to make room for it toSend = toSend[0:(436-toCutOff)] # Using 436 here to allow room for "... " of course toSend = toSend.rpartition( " " )[0] # In order to make sure it doesn't cut off in the middle of a word toSend = toSend + "... " + shortLink # Finally finishing it off __main__.sendMessage( toSend, channel ) return True else: if "<i>" + message + "</i> isn't defined.<br/>Can you define it?" in res.text: __main__.sendMessage( message + " isn't defined.", channel ) return True else: __main__.sendMessage( "There was a problem. Fix your shit.", channel ) return False return False except: return False
def command( message, user, channel ): try: res = requests.get( "http://qdb.us/random/" ) quoteNum = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "\">#", "</a>" ) ) quote = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<span class=qt id=qt" + quoteNum , "</span>" ) ) quote = quote.replace( "<br />", " / " ) __main__.sendMessage( "Quote #" + quoteNum + ": " + quote, channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://www.randomriddles.com/" ) riddle = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<strong><i>", " <a ;" ) ) answer = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "alert('", "')\"" ) ) if riddle != "": __main__.sendMessage( riddle, channel ) if answer != "": # Use a timer so we don't block threading.Timer( 15.0, __main__.sendMessage, args=( "Answer: " + answer, channel ) ).start() return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://prestopnik.com/emo_haiku/" ) haiku = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div align=center><BR><BR>", "<BR><BR><BR><BR></div>" ) ) haiku = haiku.replace( "<BR>", " " ) __main__.sendMessage( haiku, channel ) return True except: return False
def command( message, user, channel ): try: res = requests.get( "http://www.randominsults.net/" ) insult = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<strong><i>", "</i></strong>" ) ) if insult != "": __main__.sendMessage( message + ": " + insult, channel ) else: __main__.sendMessage( "There was a problem. Fix your shit.", channel ) return True except: return False
def command( message, user, channel ): try: message = message.strip().lower() if message in signs: res = requests.get( "http://my.horoscope.com/astrology/free-daily-horoscope-" + message + ".html" ) horoscope = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div class=\"fontdef1\" style=\"padding-right:10px;\" id=\"textline\">", "</div>" ) ) luckynum = __main__.fixHTMLCharsAdvanced( __main__.strbetween( res.text, "<div class=\"fontultrasma5\"><b>", "</b>" ) ) luckynum = luckynum.replace( "\t", "" ) if horoscope != "": __main__.sendMessage( message + ": " + horoscope, channel ) __main__.sendMessage( "[Lucky Numbers]:" + luckynum, channel ) else: __main__.sendMessage( message + "'s sign not found today. :(", channel ) elif message == "": __main__.sendMessage( "Usage: horoscope [sign]", channel ) else: __main__.sendMessage( "Invalid sign. Valid signs: " + (", ".join( signs )), channel ) return True except: return False
def htmlCleaner( link ): # Remove or replace any special characters link = __main__.fixHTMLCharsAdvanced( link ) # Start with the usual stuff link = link.replace( "%3F", "?" ) link = link.replace( "%3D", "=" ) return link