示例#1
0
文件: choose.py 项目: MWisBest/PyBot
def command( message, user, channel ):
	chooser = message.split( "," )
	if message != "" and len( chooser ) > 1:
		__main__.sendMessage( random.choice( chooser ).strip(), channel )
	else:
		__main__.sendMessage( "No comma-separated choices given.", channel )
	return True
示例#2
0
def command( message, user, recvfrom ):
	try:
		with open( os.path.dirname( os.path.realpath( __file__ ) ) + os.sep + "eightball.txt", "r" ) as eightballtxt:
			__main__.sendMessage( user + ": " + random.choice( eightballtxt.readlines() ), recvfrom )
		return True
	except:
		return False
示例#3
0
文件: calc.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	try:
		try:
			ret = str( calculate( message ) )
		except UnsafeOperatorError as unsafe_err:
			ret = "Unsafe operation: " + unsafe_err.message
		except OperatorError as op_err:
			ret = "Unsupported operator: " + op_err.node.op.__class__.__name__
		except (SyntaxError, TypeError):
			ret = "Invalid syntax."
		except ZeroDivisionError:
			ret = "Not Chuck Norris: Cannot Divide By Zero!"
		except:
			ret = "Unknown error occurred."
		
		if ret == "":
			ret = "Fix your shit."
		elif len( ret ) > 100:
			ret = "That's wayyyy too many digits bro."
		__main__.sendMessage( ret, recvfrom )
		return True
	except Exception as err:
		__main__.errorprint( "calc error!" )
		__main__.warnprint( pybotutils.getExceptionTraceback( err ) )
	return False
示例#4
0
文件: condom.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		with open( os.path.dirname( os.path.realpath( __file__ ) ) + os.sep + "condom.txt", "r" ) as condomtxt:
			__main__.sendMessage( random.choice( condomtxt.readlines() ), channel )
		return True
	except:
		return False
示例#5
0
文件: face.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		with open( os.path.dirname( os.path.realpath( __file__ ) ) + os.sep + "face.txt", "r", encoding="utf-8" ) as facetxt:
			__main__.sendMessage( random.choice( facetxt.readlines() ), channel )
		return True
	except:
		return False
示例#6
0
文件: weather.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	# .co.uk works with both UK and USA. .com does not!
	wbpostfix = ".co.uk"
	#splitmessage = message.split( ' ', maxsplit=1 )
	#if len( splitmessage ) == 2:
	#	if len( splitmessage[0] ) == 3 and len( splitmessage[1] ) == 3:
	#		wbpostfix = ".co.uk"
	txt = requests.get( "http://weather.weatherbug" + wbpostfix + "/Common/SearchResults.html?loc=" + message + "&is_search=true&nav_section=1&loc_country=WORLD&zcode=z6286&submit=GO" ).text
	try:
		location = fixHTMLCharsAdvanced( strbetween( txt, "\r\n<div class=\"boxhdr\">", "</h2>" ) ).replace( "  ", "" ).replace( "<h2>", "" ).strip() # Oh god this is ugly. so very ugly.
		farTemp = fixHTMLChars( strbetween( txt, "<div><strong><span id=\"divTemp\" class=\"entry-title\">", "&deg;F</span></strong>" ) ) #Fahrenheit
		celTemp = str( round( ( float( farTemp ) - 32 ) * 5 / 9, 1 ) ) #celsius
		humidity = fixHTMLChars( strbetween( txt, "<span id=\"divHumidity\" class=\"strong-value\">", "</span></div>" ) )
		feelsLikeLabel = fixHTMLChars( strbetween( txt, "<span id=\"spanFeelsLikeLabel\">", "</span>" ) )
		feelsLikeF = fixHTMLChars( strbetween( txt, "<span id=\"divFeelsLike\" class=\"strong-value\">", "&deg;F</span></div>" ) )
		feelsLikeC = str( round( ( float( feelsLikeF ) - 32 ) * 5 / 9, 1 ) ) #celsius
		rain = fixHTMLChars( strbetween( txt, "<span id=\"divRain\" class=\"strong-value\">", "</span></div>" ) )
		gust = fixHTMLChars( strbetween( txt, "<span id=\"divGust\" class=\"strong-value\">", "</span></div>" ) )
		if farTemp != "":
			toSend = location + " | Temperature: " + farTemp + "°F/" + celTemp + "°C"
			if humidity != "":
				toSend = toSend + " | Humidity: " + humidity
			if feelsLikeLabel != "" and feelsLikeF != "":
				toSend = toSend + " | " + feelsLikeLabel + ": " + feelsLikeF + "°F/" + feelsLikeC + "°C"
			if rain != "":
				toSend = toSend + " | Rain: " + rain
			if gust != "":
				toSend = toSend + " | Gust: " + gust
			__main__.sendMessage( toSend, recvfrom )
			return True
	except:
		pass
	__main__.sendMessage( message + " was not found.", recvfrom )
	return False
示例#7
0
文件: truth.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		message = message.strip()
		lineToSend = ""
		pathprefix = os.path.dirname( os.path.realpath( __file__ ) ) + os.sep
		if " f" in message:
			with open( pathprefix + "nick_female.txt", "r" ) as nick_femaletxt:
				lineToSend = random.choice( nick_femaletxt.readlines() )
			lineToSend = lineToSend.replace( "$2", message.partition( " " )[0] )
		elif " m" in message:
			with open( pathprefix + "nick_male.txt", "r" ) as nick_maletxt:
				lineToSend = random.choice( nick_maletxt.readlines() )
			lineToSend = lineToSend.replace( "$2", message.partition( " " )[0] )
		elif "m" in message:
			with open( pathprefix + "self_male.txt", "r" ) as self_maletxt:
				lineToSend = random.choice( self_maletxt.readlines() )
			lineToSend = lineToSend.replace( "$nick", user )
		elif "f" in message:
			with open( pathprefix + "self_female.txt", "r" ) as self_femaletxt:
				lineToSend = random.choice( self_femaletxt.readlines() )
			lineToSend = lineToSend.replace( "$nick", user )
		if lineToSend != "":
			__main__.sendMessage( lineToSend, channel )
		elif message == "":
			__main__.sendMessage( "Specify gender by using f or m. Example: truth m", channel )
		return True
	except:
		return False
示例#8
0
文件: qdb.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	txt = requests.get( "http://qdb.us/random/" ).text
	quoteNum = fixHTMLCharsAdvanced( strbetween( txt, "\">#", "</a>" ) )
	quote = fixHTMLCharsAdvanced( strbetween( txt, "<span class=qt id=qt" + quoteNum , "</span>" ) )
	quote = quote.replace( "<br />", " / " )
	__main__.sendMessage( "Quote #" + quoteNum + ": " + quote, recvfrom )
	return True
示例#9
0
文件: insult.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	insult = fixHTMLCharsAdvanced( strbetween( requests.get( "http://www.randominsults.net/" ).text, "<strong><i>", "</i></strong>" ) )
	if insult != "":
		__main__.sendMessage( message + ": " + insult, recvfrom )
	else:
		__main__.sendMessage( "There was a problem. Fix your shit.", recvfrom )
	return True
示例#10
0
文件: roman.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		result = ""
		if message.isdigit() and "." not in message: # Numeric, convert to roman numerals
			number = int( message )
			if 250000 > number > 0:
				for ( numeral, integer ) in romanNumeralMap:
					while number >= integer:
						result = result + numeral
						number = number - integer
			else:
				result = "Can't be less than 1, and I'm not going over 249,999 either!"
		elif romanNumeralPattern.search( message ):
			intsult = 0
			index = 0
			for ( numeral, integer ) in romanNumeralMap:
				while message[index:index+len(numeral)] == numeral:
					intsult = intsult + integer
					index = index + len( numeral )
			result = str( intsult )
		else:
			result = "I only accept integers and valid roman numerals from 1 to 249,999."
		__main__.sendMessage( result, channel )
		return True
	except:
		return False
示例#11
0
文件: wotd.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://dictionary.reference.com/wordoftheday/" )
		__main__.sendMessage( "Word of the Day: " + __main__.strbetween( res.text, "<title>Get the Word of the Day - ", " |" ), channel )
		return True
	except:
		return False
示例#12
0
文件: google.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://www.google.com/search?q=" + message )
		# There is a lot of shit. Cut off as much as possible before sending it to the HTML parser in an effort to speed up parsing
		datlongtext = __main__.strbetween( res.text, " id=\"resultStats\">", "</html>" )
		datlongtext = datlongtext.replace( "<b>", "" ).replace( "</b>", "" ).replace( "<em>", "" ).replace( "</em>", "" ) # Get rid of bolds, this tends to be used just to highlight the keyword searched
		resultOneUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" ) # The link and result text come between this
		datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultOneUnparsed + "</h3>", "" ) # Now that we got the first one, get rid of it to find the next one
		resultTwoUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" )
		datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultTwoUnparsed + "</h3>", "" )
		resultThreeUnparsed = __main__.strbetween( datlongtext, "<h3 class=\"r\">", "</h3>" )
		datlongtext = datlongtext.replace( "<h3 class=\"r\">" + resultThreeUnparsed + "</h3>", "" )
		# Great, now we've got the three results isolated. Let's parse them!
		resultOneLink = __main__.strbetween( resultOneUnparsed, "<a href=\"/url?q=", "&amp;sa=U" )
		resultTwoLink = __main__.strbetween( resultTwoUnparsed, "<a href=\"/url?q=", "&amp;sa=U" )
		resultThreeLink = __main__.strbetween( resultThreeUnparsed, "<a href=\"/url?q=", "&amp;sa=U" )
		resultOneText = __main__.strbetween( resultOneUnparsed, "\">", "</a>" )
		resultTwoText = __main__.strbetween( resultTwoUnparsed, "\">", "</a>" )
		resultThreeText = __main__.strbetween( resultThreeUnparsed, "\">", "</a>" )
		if resultOneLink != "" and resultOneText != "":
			__main__.sendMessage( htmlCleaner( resultOneText ) + " - " + htmlCleaner( resultOneLink ), channel )
		if resultTwoLink != "" and resultTwoText != "":
			threading.Timer( 0.5, __main__.sendMessage, args=( htmlCleaner( resultTwoText ) + " - " + htmlCleaner( resultTwoLink ), channel ) ).start()
		if resultThreeLink != "" and resultThreeText != "":
			threading.Timer( 1.0, __main__.sendMessage, args=( htmlCleaner( resultThreeText ) + " - " + htmlCleaner( resultThreeLink ), channel ) ).start()
		return True
	except:
		return False
示例#13
0
def handle( packet ):
	try:
		if packet['rest'][0] == "#": # just parsing channel messages here
			user = strbetween( packet['host'], ":", "!" )
			if __main__.getAccessLevel( user ) < 0:
				return False # Get out of here banned loser!
			msgsplit = packet['rest'].split( " :", maxsplit=1 )
			channel = msgsplit[0]
			splitmessage = msgsplit[1].split( " " )
			titleFound = False
			for totest in splitmessage:
				if urlregex.search( totest ): # great, we found a URL!
					if not totest.startswith( "http" ): # We need this at the start for some damn reason
						totest = "http://" + totest
					try: # who knows what we got sent to
						tosend = ""
						if "imgur.com" in totest:
							tosend = imgur( totest )
						elif "youtube.com" in totest or "youtu.be" in totest:
							tosend = youtube( totest )
						else:
							tosend = normalLink( totest )
						tosend = tosend.replace( "google", "Google" ).replace( "Google", "\x02\x03" + "02,00G\x03" + "04,00o\x03" + "08,00o\x03" + "02,00g\x03" + "03,00l\x03" + "04,00e\x03\x02" )
						if tosend != "":
							__main__.sendMessage( tosend, channel )
							titleFound = True
					except:
						continue
			return titleFound
		return False
	except:
		return False
示例#14
0
文件: fml.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://m.fmylife.com/random" )
		__main__.sendMessage( __main__.fixHTMLChars( __main__.strbetween( res.text, "<p class=\"text\">", "</p>" ) ), channel )
		return True
	except:
		return False
示例#15
0
文件: googl.py 项目: MWisBest/PyBot
def command(message, user, recvfrom):
    link = pybotutils.googlshort(message)
    if link != "":
        __main__.sendMessage(link, recvfrom)
    else:
        __main__.sendMessage("Fix your shit.", recvfrom)
    return True
示例#16
0
文件: high.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://www.thathigh.com/random" )
		__main__.sendMessage( __main__.fixHTMLChars( __main__.strbetween( res.text, "<p>", "</p>" ) ), channel ) 
		return True
	except:
		return False
示例#17
0
文件: synonym.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	txt = requests.get( "http://mobile-dictionary.reverso.net/english-synonyms/" + message ).text
	synonym = fixHTMLChars( strbetween( txt, "direction=\"target\">", "<span" ) )
	if synonym != "":
			__main__.sendMessage( "Synonyms for " + message + ": " + synonym, recvfrom )
	else:
		__main__.sendMessage( message + " was not found.", recvfrom )
	return True
示例#18
0
文件: dinner.py 项目: MWisBest/PyBot
def command(message, user, recvfrom):
    txt = requests.get("http://whatthefuckshouldimakefordinner.com/").text
    meal = fixHTMLChars(strbetween(txt, '" target="_blank">', "</a></dt>"))
    url = fixHTMLChars(strbetween(txt, '<dt><a href="', '" target="_blank">'))
    if meal != "" and url != "":
        __main__.sendMessage(meal + " - " + url, recvfrom)
    else:
        __main__.sendMessage("You will starve!", recvfrom)
    return True
示例#19
0
文件: fml.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	thefml = requests.get( "http://www.fmylife.com/random" ).text
	thefml = strbetween( thefml, "<p class=\"content\">", "</p>" )
	thefml = strbetween( thefml, ">", "</a>" )
	thefml = fixHTMLChars( thefml )
	if thefml == "":
		thefml = "Today, PyBot couldn't find an FML. FML"
	__main__.sendMessage( thefml, recvfrom )
	return True
示例#20
0
文件: riddle.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	txt = requests.get( "http://www.randomriddles.com/" ).text
	riddle = fixHTMLCharsAdvanced( strbetween( txt, "<strong><i>", " <a ;" ) )
	answer = fixHTMLCharsAdvanced( strbetween( txt, "alert('", "')\"" ) )
	if riddle != "" and answer != "":
		__main__.sendMessage( riddle, recvfrom )
		# Use a timer so we don't block
		threading.Timer( 15.0, __main__.sendMessage, args=( "Answer: " + answer, recvfrom ) ).start()
	return True
示例#21
0
文件: dict.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	txt = requests.get( "http://mobile-dictionary.reverso.net/english-definition/" + message ).text
	definition = fixHTMLChars( strbetween( txt, "direction=\"target\">", "<span" ) )
	type = fixHTMLChars( strbetween( txt, "style=\"color:#B50000;\" direction=\"\">", "<span" ) )
	if definition != "":
		__main__.sendMessage( message + ": " + type + " - " + definition, recvfrom )
	else:
		__main__.sendMessage( message + " was not found.", recvfrom )
	return True
示例#22
0
文件: haiku.py 项目: EliteTK/PyBot
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
示例#23
0
文件: xbox.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	txt = requests.get( "https://live.xbox.com/en-US/Profile?gamertag=" + message ).text
	gamerscore = fixHTMLChars( strbetween( txt, "<div class=\"gamerscore\">", "</div>" ) )
	lastseen = fixHTMLChars( strbetween( txt, "<div class=\"presence\">", "</div>" ) )
	gamertag = fixHTMLChars( strbetween( txt, "<title>", "&#39;s Profile" ) ) #get proper case of gamertag
	if gamerscore != "":
		__main__.sendMessage( gamertag + " :: Status: " + lastseen + " :: Gamerscore: " + gamerscore, recvfrom )
	else:
		__main__.sendMessage( message + " was not found.", recvfrom )
	return True
示例#24
0
文件: googl.py 项目: EliteTK/PyBot
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
示例#25
0
文件: isup.py 项目: MWisBest/PyBot
def command( message, user, recvfrom ):
	status = fixHTMLChars( strbetween( requests.get( "http://isup.me/" + message ).text, "<div id=\"container\">", "<p>" ) ).strip()
	href = strbetween( status, "<a href=\"", "class=\"domain\">" )
	status = status.replace( "<a href=\"" + href + "class=\"domain\">", "" )
	status = status.replace( "</a>", "" ).replace( "</span>", "" ).replace( "  ", " " )
	if status != "":
		__main__.sendMessage( status, recvfrom )
	else:
		__main__.sendMessage( "Something went wrong.", recvfrom )
	return True
示例#26
0
文件: qdb.py 项目: EliteTK/PyBot
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
示例#27
0
文件: insult.py 项目: EliteTK/PyBot
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
示例#28
0
文件: fact.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://randomfunfacts.com/" )
		fact = __main__.fixHTMLChars( __main__.strbetween( res.text, "<font face=\"Verdana\" size=\"4\"><strong><i>", "</i></strong>" ) )
		if fact != "":
			__main__.sendMessage( fact, channel )
		else:
			__main__.sendMessage( "No fact for you!", channel )
		return True
	except:
		return False
示例#29
0
文件: pun.py 项目: EliteTK/PyBot
def command(message, user, channel):
    try:
        res = requests.get("http://www.punoftheday.com/cgi-bin/randompun.pl")
        pun = __main__.fixHTMLChars(__main__.strbetween(res.text, "<p>", "</p>"))
        if pun != "":
            __main__.sendMessage(pun, channel)
        else:
            __main__.sendMessage("No pun for you!", channel)
        return True
    except:
        return False
示例#30
0
文件: dinner.py 项目: EliteTK/PyBot
def command( message, user, channel ):
	try:
		res = requests.get( "http://whatthefuckshouldimakefordinner.com/" )
		meal = __main__.fixHTMLChars( __main__.strbetween( res.text, "\" target=\"_blank\">", "</a></dt>" ) )
		url = __main__.fixHTMLChars( __main__.strbetween( res.text, "<dt><a href=\"", "\" target=\"_blank\">" ) )
		if meal != "":
			__main__.sendMessage( meal + " - " + url, channel )
		else:
			__main__.sendMessage( "You will starve!", channel )
		return True
	except:
		return False