Example #1
0
def checkPigs(s, nick, channel, text):
	words = stemPhrase(text)
	#print("Words:", words)
	
	##:: Pig Format ::
	##
	## [0]   [1]      [2]   [3]
	## nick, channel, says, words
	## |     |        |     ^ (find all theses items; if that item is a list,
	## |     |        |     ^  then we only need to find one of the items in
	## |     |        |     ^  that list)
	## |     |        ^ (who needs to say all those words)
	## |     ^ (must act only on phrases in the channel it was created)
	## ^ (this is who we unmute when we find the phrase)
	
	
	# for each user muted that is in the channel in question
	for pig in flyingPigs:
		if pig[1] != channel: continue
		if pig[2] and nick != pig[2]: continue
		
		Unmute = True
		
		# check to see if all the keywords are in the sentance
		for word in pig[3]:
			
			if type(word) == list:
				win = False
				for w in word:
					if w in words:
						win = True
						break
				if not win:
					Unmute = False
				
			elif word not in words:
				Unmute = False
				#print(word, "not in words")
				break
			
		
		if Unmute:
			#print("unmute")
			#print(meta.users[channel])
			channel, nick = meta.isUser(channel, pig[0])
			if channel and nick:
				#print("Unmuting:", nick, "on", channel)
				meta.users[channel][nick].unmute(s)
				removePig(nick, channel)
Example #2
0
def handle(s, nick, ident, host, cmd, data):


	if cmd == "PING":
		meta.send(s, "PONG %s\r\n" % data)
		return True
	
	
	
	elif cmd == "001":
		if meta.conf['pass']:
			print("Sending NickServ Password\n")
			meta.sendMsg(s, "NickServ", "IDENTIFY %s" % meta.conf['pass'])
		
		print("Joining Channel %s\n" % meta.conf['channel'])
		meta.send(s, "MODE %s +B\r\nJOIN %s\r\nUSERHOST %s\r\n" % (meta.conf['nick'], meta.conf['channel'], meta.conf['ident']))
		
		return True
		
		
		
		
	elif cmd == "353":
		# Create our user list on channel join (353: user list)
		#print(data)
		
		listStart = data.find(':')
		
		cfind = data.find('=')
		if cfind == -1:
			#secret
			cfind = data.find('*')
			if cfind == -1:
				#private
				cfind = data.find('@')
		
		channel = data[cfind+2 : listStart-1]
		userlist = data[listStart+1 :].split()
		
		
		#print("userlist:",userlist)
		
		for u in userlist:
			#print(u)
			if u[0] == '&':
				user = u[1 :]
				meta.users[channel][user] = meta.User(user, channel, ident, host)
				meta.users[channel][user].protected = True
				
			elif u[0] == '~':
				user = u[1 :]
				meta.users[channel][user] = meta.User(user, channel, ident, host)
				meta.users[channel][user].owner = True
				
			elif u[0] == '@':
				user = u[1 :]
				meta.users[channel][user] = meta.User(user, channel, ident, host)
				meta.users[channel][user].op = True
				
			elif u[0] == '%':
				user = u[1 :]
				meta.users[channel][user] = meta.User(user, channel, ident, host)
				meta.users[channel][user].halfOp = True
				
			elif u[0] == '+':
				user = u[1 :]
				meta.users[channel][user] = meta.User(user, channel, ident, host)
				meta.users[channel][user].voice = True
				
			else:
				#print("channel:", channel)
				#print("U:", u)
				meta.users[channel][u] = meta.User(u, channel, ident, host)
				
			
		meta.parseMuteTimers(s, channel)
		
	
	
	elif cmd == "MODE":
		#return True
		mode = data.split()
		
		if len(mode) < 3:
			return True
		
		print(nick, ident, mode)
		channel = mode[0]
		user = mode[2]
		mode = mode[1]
		
		if not meta.isUser(channel, user):
			return True
		
		add = True
		for char in mode:
			if char == "+": add = True
			elif char == "-": add = False
			elif char == "v":
				if add: 
					meta.users[channel][user].voice = True
					#clears mute timers
					meta.users[channel][user].unmute(s)
					#take them off the pig watch list (mute until list)
					removePig(user, channel)
				else:
					meta.users[channel][user].voice = False
			elif char == "o":
				if add: meta.users[channel][user].op = True
				else: meta.users[channel][user].op = False
			elif char == "a":
				if add: meta.users[channel][user].protected = True
				else: meta.users[channel][user].protected = False
			elif char == "h":
				if add: meta.users[channel][user].halfOp = True
				else: meta.users[channel][user].halfOp = False
			elif char == "q":
				if add: meta.users[channel][user].owner = True
				else: meta.users[channel][user].owner = False
		
		
		
		
		return True
	
	
	elif cmd == "KICK":
		# remove the user from our list when they are kicked
		kick = data.split()
		
		if meta.isUser(kick[0], kick[1]):
			del meta.users[kick[0]][kick[1]]
		
		removePig(kick[1], kick[0])
		return True
	
	
	
	elif cmd == "JOIN":
		channel = data[1 :]
		if nick == meta.conf['nick']:
			#:[email protected] JOIN :#joey
			#when jobot joins a channel, add that channel to its list
			meta.users[ channel ] = dict()
			meta.send(s, "WHO {0}\r\n".format(channel))
		else:
			#:[email protected] JOIN :#xkcd
			meta.users[channel][nick] = meta.User(nick, channel, ident, host)
			
			# mute the person if wally has a timer ready and waiting for them
			muted = meta.parseMuteTimers(s, channel, nick)
			
			# dont autovoice if they are on a mute timer
			if not muted and meta.conf['autovoice']:# and meta.canMute(channel, meta.conf['nick']) and meta.conf['autovoice']:
				meta.users[channel][nick].unmute(s)
			
			
			if nick not in meta.userInfo:
				meta.userInfo[nick] = {}
			meta.userInfo[nick]["ident"] = ident
			meta.userInfo[nick]["host"] = host
		return True
	
	
	elif cmd == "PART":
		
		meta.delUser(data, nick)
		
		removePig(nick, data)
		return True
	
	
	# WHO #channel reply
	#:colobus.foonetic.net 352 Joey #xkcd-robotics ~Jobot hide-54ECEB19.tampabay.res.rr.com colobus.foonetic.net wally HrB% :0 Joey
	#:colobus.foonetic.net 352 Joey #xkcd-robotics ~Joey hide-54ECEB19.tampabay.res.rr.com colobus.foonetic.net Joey Hr& :0 Joey
	elif cmd == "352":
		x = data.split()
		if x[5] not in meta.userInfo:
			meta.userInfo[x[5]] = {}
		meta.userInfo[x[5]]["ident"] = x[2]
		meta.userInfo[x[5]]["host"] = x[3]
		meta.userInfo[x[5]]["server"] = x[4]
		meta.userInfo[x[5]]["realname"] = x[8]
		return True
	
	
	# Handle nick changes. No channel is given because nicks are unique for that server.
	elif cmd == "NICK":
		for channel in meta.users.keys():
			if nick in meta.users[channel]:
				meta.users[channel][data[1:]] = meta.users[channel][nick]
				del meta.users[channel][nick]
				
				piggy = findPig(nick, channel)
				if piggy:
					removePig(nick, channel)
					groundPig(data[1:], channel, piggy[2], piggy[3])
				
				m = meta.delMuteTimer(nick, channel)
				if m:
					meta.saveMuteTimers(*m)
		return True
	
	
	elif cmd == "QUIT":
		#:[email protected] QUIT :Ping timeout
		for channel in meta.users.keys():
			if nick in meta.users[channel]:
				del meta.users[channel][nick]
		
		removePig(nick, channel)
		
		return True
Example #3
0
def msg(s, nick, ident, host, channel, text):
	
	
	
	#print(channel)
	#no channel specific commands in private chat
	if channel == meta.conf['nick']:
		inChannel = False
		channel = nick
	else:
		inChannel = True
		
	
	if nick in meta.conf['ignore'] or host in meta.conf['ignorehost']:
		return False
	
	
	checkPigs(s, nick, channel, text)
	
	
	print(channel+":", nick,"|",text)
	
	
	
	if not re.match(r"wally[,:] ", text, re.I):
		return True
	
	if channel in meta.LOUD and not re.match(r"bitch[,:] ", text, re.I):
		return True
	
	
	text = text[7 :]
	textLower = text.lower()
	
	#print("In !1_main msg func", meta.canMute(channel, nick), inChannel)
	
	if textLower == "you there?":
		meta.sendMsg(s, channel, "yes")
		return True
	
	elif textLower[: 5] == "mute " and meta.canMute(channel, nick) and inChannel:
		#mute Joey until pigs fly
		#mute Joey until hell freezes over
		#mute Joey until ...your mom
		
		
		
		userEnd = text.find(' ', 5)
		
		#print("In mute", userEnd)
		
		if userEnd > 0:
			user = text[5 : userEnd]
			params = textLower[userEnd+1 :]
			
			# mute me 1m
			# mute me until pigs fly
			if user.lower() == 'me':
				user = nick
			
			if params[:6] == 'until ' or params[:4] == 'til ':
				if params[:4] == 'til ':
					params = params[4:]
				else:
					params = params[6:]
				
				# improper syntax
				if not params:
					meta.sendMsg(s, channel, "Until when? Finish your statements...")
					return False
				
				try:
					# add the user to the 'muted until' list
					stemmed = groundPigs(user, channel, params, nick)
				except:
					traceback.print_exc()
					input()
				
				print("Muting", user, "until", stemmed)
				
				c, u = meta.isUser(channel, user)
				if c and u:
					meta.users[c][u].mute( s )
				else:
					print(user, 'is not a user')
					meta.sendMsg(s, channel, "Mute who?")
					
				return False
			
			if not re.match(r"\d+[smhdwyc]?", params):
				return True
			
			if params[-1:] == 's':#seconds
				muteTime = float(params[ :-1])
			elif params[-1:] == 'm':#minutes
				muteTime = float(params[ :-1]) * 60
			elif params[-1:] == 'h':#hours
				muteTime = float(params[ :-1]) * 3600
			elif params[-1:] == 'd':#days
				muteTime = float(params[ :-1]) * 86400
			elif params[-1:] == 'w':#weeks
				muteTime = float(params[ :-1]) * 604800
			elif params[-1:] == 'y':#years
				muteTime = float(params[ :-1]) * 31556926
			elif params[-1:] == 'c':#Centuries
				muteTime = float(params[ :-1]) * 3155692600
			else:
				muteTime = float(params) #seconds
			
		else:
			user = text[5 :]
			
			if user.lower() == 'me':
				user = nick
			
			muteTime = 0
			
		c, u = meta.isUser(channel, user)
		if c and u:
			print("Muting", u, muteTime)
			meta.users[c][u].mute( s, muteTime )
		else:
			print(user, 'is not a user')
			meta.sendMsg(s, channel, "Mute who?")
			
		return False
		
		
	elif textLower.find('unmute ') == 0 and meta.canMute(channel, nick) and inChannel:
		user = text[7 :]
		
		if user.lower() == 'me':
			user = nick
			
		c, u = meta.isUser(channel, user)
		if c and u:
			meta.users[c][u].unmute(s)
			removePig(u, channel)
			#print("Unmuting", u)
		else:
			meta.sendMsg(s, channel, "Unmute who?")
		return False
		
	elif textLower.find('ban ') == 0:
		if not inChannel: return False
		
		if not meta.canBan(channel, nick):
			meta.sendMsg(s, channel, "%s: You do not have the power!" % nick)
			return False
			
		if not meta.canBan(channel, meta.conf['nick']):
			#meta.sendMsg(s, channel, "%s: I do not have the power!" % nick)
			return True
			
		
		r = re.match(r"ban\s+([^\s]+)\s*(?:(?:for\s+)?(.*?))?[!.?]*$", textLower)
		
		if not r:
			meta.sendMsg(s, channel, "%s: Invalid syntax." % nick)
			return False
		
		user, timeStr = r.groups()
		
		c, user = meta.isUser(channel, user)
		
		if not user:
			meta.sendMsg(s, channel, "%s: ban who?" % nick)
			return False
		
		x = meta.userInfo[user]
		
		length = timeOffset(timeStr)
		
		if not timeStr or (length and length < 0):
			meta.ban(s, channel, host=x['host'])
			return False
		
		elif not length:
			meta.sendMsg(s, channel, "%s: Invalid time." % nick)
			return False
		
		
		meta.timedBan(s, channel, length, host=x['host'])
		
		#meta.sendMsg(s, channel, "%s, You are awarded one tricky-dick-fun-bill for finding an undocumented unfinished feature!"%nick)
		return False
	
	elif textLower.find('unban ') == 0:
		if not inChannel: return False
		
		if not meta.canBan(channel, nick):
			meta.sendMsg(s, channel, "%s: You do not have the power!" % nick)
			return False
			
		if not meta.canBan(channel, meta.conf['nick']):
			#meta.sendMsg(s, channel, "%s: I do not have the power!" % nick)
			return True
		
		r = re.match(r"unban\s+([^\s]+?)[!.?\s]*$", textLower)
		
		if not r:
			meta.sendMsg(s, channel, "%s: Invalid syntax." % nick)
			return False
		
		(user,) = r.groups()
		
		c, user = meta.isUser(channel, user)
		
		if not user:
			meta.sendMsg(s, channel, "%s: unban who?" % nick)
			return False
		
		x = meta.userInfo[user]
		
		banmask = meta.unban(s, channel, host=x['host'])
		
		return False
	elif False and textLower == 'be loud' and ((inChannel and meta.canMute(channel, nick)) or not inChannel):
		while channel in meta.LOUD:
			meta.LOUD.remove(channel)
		meta.LOUD.append(channel)
		
		meta.sendMsg(s, channel, "%s: Ok."%nick)
		return False
		
	elif False and (textLower == 'not so loud' or textLower == 'be cool') and \
		((inChannel and meta.canMute(channel, nick)) or not inChannel):
		if channel in meta.LOUD:
			meta.LOUD.remove(channel)
			meta.sendMsg(s, channel, "%s: Ok."%nick)
			return False
			
		
	elif (textLower == 'restart' or textLower == 'reboot') and meta.isAuthor(nick, ident, host):
		meta.quit = True
		meta.restart = True
		return False
		
	elif (textLower == 'quit' or textLower == 'exit') and meta.isAuthor(nick, ident, host):
		meta.quit = True
		return False