def command( command, message, user, recvfrom ): link = "http://www.urbandictionary.com/" if command != "rurban": link += "define.php?term=" + message else: link += "random.php" txt = requests.get( link ).text definition = fixHTMLCharsAdvanced( strbetween( txt, "<div class='meaning'>\n", "\n</div>" ) ) word = fixHTMLCharsAdvanced( strbetween( txt, "<title>Urban Dictionary: ", "</title>" ) ) if definition != "" and word != "" and not definition.startswith( notDefinedPrefix ): toSend = word + ": " + definition if len( toSend ) >= 370: # This is roughly the longest message I've been able to send. shortLink = googlshort( "http://www.urbandictionary.com/define.php?term=" + word ) # 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:(366-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 += "... " + shortLink # Finally finishing it off __main__.sendMessage( toSend, recvfrom ) return True elif definition.startswith( notDefinedPrefix ): __main__.sendMessage( message + " isn't defined.", recvfrom ) return True else: __main__.sendMessage( "There was a problem. Fix your shit.", recvfrom ) return False return False
def command(message, user, recvfrom): link = pybotutils.googlshort(message) if link != "": __main__.sendMessage(link, recvfrom) else: __main__.sendMessage("Fix your shit.", recvfrom) return True
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: link = pybotutils.googlshort( message ) if link != "": __main__.sendMessage( link, channel ) else: __main__.sendMessage( "Fix your shit.", channel ) return True except: return False