def iknew(self, args, prefix, trailing):
		# Channel only
		if not args[0][0]=="#":
			return
		
		# Check banned names
		fromWho = self.bot.extract_nick_from_prefix(prefix)
		if fromWho in self.banlist:
			return;
		
		# Checked banned IPs
		fromIp = self.bot.extract_ip_from_prefix(prefix)
		if fromIp in self.baniplist:
			return
		
		# !dyk add
		cmd = Tools.messageHasCommand("!dyk add", trailing, True)
		if cmd:
			if time.time() - self.lastDykAdd < self.config["addLimitSeconds"]:
				# too soon!
				return;
			self.lastDykAdd = int(time.time())
			allowed = True
			# Bad word check
			for word in self.config["badwords"]:
				if word.lower() in cmd[2].lower():
					allowed = False
			# Dupe check
			if self.factAlreadyExists(cmd[2]):
				allowed = False
			if allowed:
				self.addFactoid(fromWho, fromIp, cmd[2].strip(), args[0])
			return
		
		# !dyk
		cmd = Tools.messageHasCommand("!dyk", trailing, False)
		if cmd and cmd[2]=='':
			
			if time.time() - self.lastDyk < self.config["infoLimitSeconds"]:
				remaining = self.config["infoLimitSeconds"] - (float(time.time() - self.lastDyk))
				minutes = int(math.floor(remaining/60))
				seconds = int(remaining - (minutes*60))
				self.bot.do_privmsg(fromWho, "Please wait %s minute(s) and %s second(s)." % (minutes, seconds))
				return;
			factoid = self.loadRandomFactoid()
			if not factoid:
				return
			msg = "<Did you know?> %s" % factoid["text"]
			if not factoid["user"]=="(Imported)":
				msg+=" <Added by %s>" % factoid["user"]
			self.bot.do_privmsg(args[0], msg)
			
			self.lastDyk = int(time.time())
				
			return
Example #2
0
	def scramble(self, args, prefix, trailing):
		sender = self.bot.extract_nick_from_prefix(prefix)
		if self.currentWord and trailing.strip().lower() == self.currentWord:
			playerScore = self.getScore(sender, 1)
			self.bot.do_privmsg(args[0], "%s guessed the word - %s! %s now has %s points." % (sender, self.currentWord, sender, playerScore))
			self.currentWord = None
			return
		
		cmd = Tools.messageHasCommand(".scramble", trailing)
		if cmd:
			if self.currentWord:
				self.bot.do_privmsg(args[0], "Current word is - %s (%s letters)" % (self.scrambled, len(self.scrambled)))
			else:
				f = open(self.wordsFile, "r")
				skip = random.randint(0, self.wordsCount)
				while skip>=0:
					f.readline()
					skip-=1
				self.currentWord = f.readline().strip().lower()
				self.log("Word is: %s"%self.currentWord)
				f.close()
				
				self.scrambled = ""
				
				for subword in self.currentWord.split(" "):
					self.scrambled+=self.scrambleWord(subword)+ " "
				self.scrambled = self.scrambled.strip()
				
				self.bot.do_privmsg(args[0], "New scrambled word - %s " % (self.scrambled))
Example #3
0
	def checkem(self, args, prefix, trailing):
		fromWho = self.bot.extract_nick_from_prefix(prefix)
		
		cmd = Tools.messageHasCommand("!mcstatus", trailing, False)
		if cmd and cmd[2]=='':
			
			status = "Minecraft Status " 
			if self.last_checked_at:
				status += "(%i seconds ago)" % (time.time() - self.last_checked_at) 
			status += ": "
			
			color = self.choosePrefixFor(self.results["login"])
			status+=color+"Login"+color[0:-1]+" "
			
			color = self.choosePrefixFor(self.results["session"])
			status+=color+"Session"+color[0:-1]+" "
			
			color = self.choosePrefixFor(self.results["web"])
			status+=color+"Website"+color[0:-1]+" "
			
			color = self.choosePrefixFor(self.results["skin"])
			status+=color+"Skins"+color[0:-1]+" "
			
			color = self.choosePrefixFor(self.results["account"])
			status+=color+"Accounts"+color[0:-1]+" "
			
			color = self.choosePrefixFor(self.results["mcbouncer"])
			status+=color+"MCBouncer"+color[0:-1]
			
			self.bot.do_privmsg(args[0], status)
Example #4
0
	def scramble(self, args, prefix, trailing):
		sender = self.master.bot.extract_nick_from_prefix(prefix)
		cmd = Tools.messageHasCommand(".scrambleon", trailing)
		if cmd and not self.running:
			self.running = True
			self.startScramble()
			return
		cmd = Tools.messageHasCommand(".scrambleoff", trailing)
		if cmd and self.running:
			self.gameover()
			self.running = False
			return
		cmd = Tools.messageHasCommand(".scramble top", trailing)
		if cmd:
			sortedscores = []
			for player in self.master.scores:
				sortedscores.append({'name':player, 'score':self.master.scores[player]})
			sortedscores = sorted(sortedscores, key=itemgetter('score'))
			sortedscores.reverse()
			numScores = len(sortedscores)
			if numScores>3:
				numScores=3
			resp = "Top %s: " % str(numScores)
			which = 1
			while which<=numScores:
				resp+="%s: %s, " % (sortedscores[which-1]["name"], sortedscores[which-1]["score"])
				which+=1
			self.master.bot.do_privmsg(self.channel, resp[:-2])
		cmd = Tools.messageHasCommand(".scramble score", trailing)
		if cmd:
			someone = cmd[2].strip()
			if len(someone) > 0:
				self.master.bot.do_privmsg(self.channel, "%s: %s has a score of %s" % (sender, someone, self.master.getScoreNoWrite(someone)))
			else: 
				self.master.bot.do_privmsg(self.channel, "%s: %s" % (sender, self.master.getScore(sender)))
		if self.currentWord and trailing.strip().lower() == self.currentWord:
			playerScore = self.master.getScore(sender, 1)
			self.master.bot.do_privmsg(self.channel, "%s guessed the word - %s! %s now has %s points. Next word in %s seconds." % (sender, self.currentWord, sender, playerScore, self.delayNext))
			self.currentWord = None
			self.clearTimers()
			self.hintsGiven = 0
			self.nextTimer = Timer(self.delayNext, self.startNewWord)
			self.nextTimer.start()
			self.guesses=0
		else:
			self.guesses+=1
Example #5
0
	def images(self, args, prefix, trailing):
		cmd = Tools.messageHasCommand(".images", trailing)
		if cmd:
			sender = self.bot.extract_nick_from_prefix(prefix)
			query = cmd[2]
			results = self.googleImagesSearch(query)
			if len(results) == 0:
				self.bot.do_privmsg(args[0], "%s: No Results " % sender)
			else:
				chosenOne = results[random.randint(0, len(results)-1)];
				self.bot.do_privmsg(args[0], "%s: Google Image for '%s': %s " % (sender, query, chosenOne["imageUrl"]));
Example #6
0
	def roulette(self, args, prefix, trailing):
		cmd = Tools.messageHasCommand(".roulette", trailing)
		if cmd:
			sender = self.bot.extract_nick_from_prefix(prefix)
			if self.chambers == None:
				self.reload(args[0])
				return
			
			if self.chambers.pop(0):
				self.bot.do_kick(args[0], sender, "BANG! You died.")
				self.chambers = None
			else: 
				self.bot.do_privmsg(args[0], "Click!")
Example #7
0
	def hcsmp(self, args, prefix, trailing):
		cmd = Tools.messageHasCommand("!hcsmp", trailing, False)
		if cmd and cmd[2]=='':
			try:
				s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
				s.settimeout(5)
				start=time.time()
				s.connect(("hardcore.hcsmp.com", 25565))
				s.send('\xFE\x01')
				d = s.recv(512)
				end=time.time()
				s.close()
				d = d[5:].decode('utf-16be').split('\x00')
				
				self.bot.do_privmsg(args[0], "Online, %sms ping, MC v%s, %s/%s players: %s" % ( str(int((end-start)*1000)), d[2], d[4], d[5], d[3] ) )
			except Exception,e:
				print e
				self.bot.do_privmsg(args[0], "HCSMP seems to be down!")
Example #8
0
	def hunt(self, args, prefix, trailing):
		fromWho = self.bot.extract_nick_from_prefix(prefix)
		
		cmd = Tools.messageHasCommand("!huntscore", trailing, False)
		if cmd:
			scores = self.loadScores()
			if not fromWho in scores:
				self.bot.do_privmsg(fromWho, "You have no points :(")
			else:
				scores = scores[fromWho]
				kills = 0
				runts = 0
				prime = 0
				weight = 0.0
				shots = 0
				misses = 0
				for kill in scores:
					if kill["prime"]:
						prime+=1
					if kill["runt"]:
						runts+=1
					kills+=1
					weight+=kill["weight"]
					shots+=1
					shots+=kill["misses"]
					misses+=kill["misses"]
					
				self.bot.do_privmsg(fromWho, "You've shot %s %s for a total weight of %s lbs." % (kills, self.config["animalSpeciesPlural"], weight))
				self.bot.do_privmsg(fromWho, "%s prime catches, %s runts, %s bullets used and %s misses." % (prime, runts, shots, misses))
				print "DuckHunt: %s used !huntscore" % fromWho
			return
		
		# Channel only
		if not args[0][0]=="#":
			return
		
		cmd = Tools.messageHasCommand("!shoot", trailing, False)
		if cmd and cmd[2]=='':
			if self.isDuckOut:
				
				if not fromWho in self.misses:
					self.misses[fromWho]=0
					
				shotIn = round(time.time() - self.outStart, 2)
				
				if random.randint(0, 100) <= self.config["missChance"]:
					self.bot.do_privmsg(self.config["activeChannel"], "%s fires after %s seconds and misses!" % (fromWho, shotIn))
					self.misses[fromWho]+=1
					return
				
				self.isDuckOut = False
				
				bagged = {
					"species":self.config["animalSpecies"],
					"gender":"M" if random.randint(0,1)==1 else "F",
					"time":shotIn,
					"prime":False,
					"runt":False,
					"weight":0.0,
					"date":time.time(),
					"misses":self.misses[fromWho]
				}
				
				message = "%s bags " % fromWho
				
				if random.randint(0, 100) <= self.config["primeChance"]:
					bagged["prime"]=True
					bagged["weight"]=self.getRandWeight(self.config["weightMax"], self.config["weightFat"])
					message += "a prime catch, a "
				elif random.randint(0, 100) <= self.config["runtChance"]:
					bagged["runt"]=True
					bagged["weight"]=self.getRandWeight(self.config["weightRunt"], self.config["weightMin"])
					message += "a runt of a catch, a "
				else:
					bagged["weight"]=self.getRandWeight(self.config["weightMin"], self.config["weightMax"])
					message += "a "
				
				message += "%s lb " % (bagged["weight"])
				if bagged["gender"]=="M":
					message += self.config["animalNameMale"]+" "
				else:
					message += self.config["animalNameFemale"]+" "
				
				message += "in %s seconds!" % shotIn
				
				self.bot.do_privmsg(self.config["activeChannel"], message)
				
				self.addKillFor(fromWho, bagged)
				
				self.misses = {}
				
				self.startHunt();
Example #9
0
	def mkimage(self, args, prefix, trailing):
		prefixIp = prefix.split("@")[1]
		if prefixIp in self.banIps:
			return
		
		cmd = Tools.messageHasCommand(".remove", trailing)
		if cmd and args[0][0] != "#":
			sender = self.bot.extract_nick_from_prefix(prefix)
			removeSplit = cmd[2].split(" ")
			if len(removeSplit)!=2:
				return
			password, toRemove = removeSplit
			if password!="adminPassword45678":
				self.bot.do_privmsg(sender, "Wrong password.")
				return
			removes = []
			for meme in self.existingMemes["memes"]:
				if meme["memeFile"]==toRemove:
					removes.append(meme)
			for item in removes:
				if os.path.exists( self.getFilePath("images/%s"%item["memeFile"]) ):
					os.remove( self.getFilePath("images/%s"%item["memeFile"]) )
				self.existingMemes["memes"].remove(item)
				self.bot.do_privmsg(sender, "Meme removed.")
			yaml.dump(self.existingMemes, file(self.memeLibPath, 'w'))
		
		cmd = Tools.messageHasCommand(".help", trailing)
		if cmd:
			sender = self.bot.extract_nick_from_prefix(prefix)
			
			self.bot.do_privmsg(sender, "I Am Memebot and I create meme images.")
			self.bot.do_privmsg(sender, "Commands: .help .faqs .memes .meme")
			self.bot.do_privmsg(sender, "Examples: .meme Bush Sucks   <- Create a meme with a random image")
			self.bot.do_privmsg(sender, "Examples: .memes             <- Get a list of available memes")
			self.bot.do_privmsg(sender, "Examples: .icp I eat dicks   <- Create a meme of the icp with your given text")
			return
		
		cmd = Tools.messageHasCommand(".faqs", trailing)
		if cmd:
			sender = self.bot.extract_nick_from_prefix(prefix)
			self.bot.do_privmsg(sender, "PM me .faq <number> for answers.")
			self.bot.do_privmsg(sender, "FAQ 1: You're broken! Who do I contact?")
			self.bot.do_privmsg(sender, "FAQ 2: How can I submit a new background image to the bot?")
			self.bot.do_privmsg(sender, "FAQ 3: I'm offended! How can I get an image taken down?")
			self.bot.do_privmsg(sender, "FAQ 4: Is your source code available?")
			return
		
		cmd = Tools.messageHasCommand(".faq", trailing)
		if cmd:
			sender = self.bot.extract_nick_from_prefix(prefix)
			faqnum = -1
			try:
				faqnum = int(cmd[2])
			except:
				return
				# invalid faq number
			if faqnum==1:
				self.bot.do_privmsg(sender, "Answer 1: This bot can be fixed by YourNameHere.")
			elif faqnum==2:
				self.bot.do_privmsg(sender, "Answer 2: New images should have the URL PM'd to YourNameHere.")
				self.bot.do_privmsg(sender, "Answer 2: If the demand is enough, a .suggest command may be added in the future.")
			elif faqnum==3:
				self.bot.do_privmsg(sender, "Answer 3: No images will be taken down with the exception of extreme cases and ")
				self.bot.do_privmsg(sender, "Answer 3: valueless images (such as images full of invalid characters)")
			elif faqnum==4:
				self.bot.do_privmsg(sender, "Answer 4: Memebot is a module for PyIRC bot. The bot including this module")
				self.bot.do_privmsg(sender, "Answer 4: can be found on github: https://github.com/xMopx/pyircbot-github")
		# past here is channel-only commands.
		if not args[0][0] == "#":
			return
		
		# look for an appropriate command
		for memecmd in self.memes:
			cmd = Tools.messageHasCommand(memecmd, trailing)
			if cmd:
				
				sender = self.bot.extract_nick_from_prefix(prefix)
				text = cmd[2].upper().strip()
				
				self.bot.do_privmsg(args[0], "%s: Meme created: http://yourmemehost/memes/%s" % (sender, self.getMeme(memecmd, text, prefix)))
				return
		
		cmd = Tools.messageHasCommand(".memes", trailing)
		if cmd:
			available = []
			for meme in self.memes:
				available.append(meme)
			available = ', '.join(available)
			sender = self.bot.extract_nick_from_prefix(prefix)
			self.bot.do_privmsg(sender, "Available memes: %s" % available)
			return
		
		cmd = Tools.messageHasCommand(".meme", trailing)
		if cmd:
			memecommands = self.memes.keys()
			chosen = memecommands[random.randint(0, len(memecommands)-1)]
			
			sender = self.bot.extract_nick_from_prefix(prefix)
			text = cmd[2].upper().strip()
			
			self.bot.do_privmsg(args[0], "%s: Meme created: http://yourmemehost/memes/%s" % (sender, self.getMeme(chosen, text, prefix)))
			return