示例#1
0
文件: irc.py 项目: MWisBest/PyBot
def handleAPIPacket( packet ):
	if packet['command'] == "PING":
		# Make a shallow copy of the packet to avoid overwriting something.
		pingpacket = dict( packet )
		pingpacket['command'] = "PONG"
		pingpacket['raw'] = pingpacket['raw'].replace( "PING", "PONG" )
		__main__.sendPacket( pingpacket )
	elif packet['command'] == "CAP":
		handleCAPs( packet )
示例#2
0
文件: irc.py 项目: MWisBest/PyBot
def join():
	# Auth should (try) to be done before join.
	# It's not realistic to expect that to happen with NickServ/PM-based auth however,
	# but let's give it a little head start at least.
	pw = ( base64.b85decode( __main__.database['api']['ircsettings']['pw'] ) ).decode( "utf-8" )
	if pw != "" and "sasl" not in CAPs['enabled']:
		__main__.sendPacket( __main__.makePacket( "PRIVMSG NickServ :IDENTIFY " + pw ), forceDebugPrint=True )
	
	__main__.sendPacket( __main__.makePacket( "JOIN " + ",".join( __main__.database['api']['ircsettings']['channels'] ) ), forceDebugPrint=True )
	return True
示例#3
0
文件: irc.py 项目: MWisBest/PyBot
def handleCAPs( packet ):
	if not CAPs['actuallyUseThisCrap']:
		return False
	if __main__.database['globals']['debug']:
		print( "Handling CAP: " + str( packet ) )
	if " LS :" in packet['rest']:
		CAPs['server'] = packet['rest'].partition( " LS :" )[2].split()
		for cap in CAPs['server']:
			if cap in CAPs['client']:
				CAPs['enabled'].append( cap )
		if CAPs['enabled']:
			__main__.sendPacket( __main__.makePacket( "CAP REQ :" + " ".join( CAPs['enabled'] ) ) )
			return True
	elif " ACK :" in packet['rest']:
		CAPs['enabled'] = packet['rest'].partition( " ACK :" )[2].split()
		if "sasl" in CAPs['enabled']:
			__main__.sendPacket( __main__.makePacket( "AUTHENTICATE PLAIN" ) )
			data = __main__.sock.recv( 512 ).decode( errors="ignore" )
			pw = ( base64.b85decode( __main__.database['api']['ircsettings']['pw'] ) ).decode( "utf-8" )
			__main__.sendPacket( __main__.makePacket( "AUTHENTICATE " + (base64.b64encode( '\0'.join( (__main__.database['api']['ircsettings']['nick'], __main__.database['api']['ircsettings']['nick'], pw) ).encode( "utf-8" ) )).decode( "utf-8" ) ) )
			data = __main__.sock.recv( 2048 ).decode( errors="ignore" )
			__main__.sendPacket( __main__.makePacket( "CAP END" ) )
			__main__.loggedIn = True
			return True
	return False
示例#4
0
文件: ctcp.py 项目: MWisBest/PyBot
def handle( packet ):
	try:
		if packet['rest'][0] != "#": # just parsing PM messages here
			message = packet['rest'].split( " :", maxsplit=1 )[1].strip()
			if message[0] != "\x01" and message[-1] != "\x01": # CTCPs tend to use this, derp
				return False
			user = strbetween( packet['host'], ":", "!" )
			if __main__.getAccessLevel( user ) < 0:
				return False # Get out of here banned loser!
			message = message[1:-1] # Just chop off the \x01s now
			toSend = ""
			if message == "VERSION":
				toSend = "NOTICE " + user + " :\x01VERSION PyBot " + __main__.pyBotVersion + ".\x01"
			elif message == "TIME":
				toSend = "NOTICE " + user + " :\x01TIME " + time.strftime( "%a %b %d %X" ) + "\x01"
			elif message.startswith( "PING " ):
				toSend = "NOTICE " + user + " :\x01" + message + "\x01"
			if toSend != "":
				__main__.sendPacket( __main__.makePacket( toSend ) )
				return True
		return False
	except:
		return False
示例#5
0
文件: irc.py 项目: MWisBest/PyBot
def login():
	if CAPs['actuallyUseThisCrap']:
		__main__.sendPacket( __main__.makePacket( "CAP LS" ), forceDebugPrint=True )
	__main__.sendPacket( __main__.makePacket( "NICK " + __main__.database['api']['ircsettings']['nick'] ), forceDebugPrint=True )
	__main__.sendPacket( __main__.makePacket( "USER " + __main__.database['api']['ircsettings']['nick'] + " " + __main__.database['api']['ircsettings']['nick'] + " " + __main__.database['api']['ircsettings']['network'] + " :" + __main__.database['api']['ircsettings']['nick'] ), forceDebugPrint=True )
	return not CAPs['actuallyUseThisCrap']