コード例 #1
0
ファイル: signbot.py プロジェクト: Cairnarvon/SignBot
 def __send_kmail(self, pname, pid, message, item=None):
     msg = {'userId': pid, 'text': message}
     if item:
         msg['items'] = [{'id': item, 'quantity': 1}]
     r = SendMessageRequest(self.__session, msg)
     r.doRequest()
     self.log('I sent a kmail to {} (#{}): "{}"'.format(pname, pid, message))
     if item:
         self.log('I sent them an item: {}'.format(
             {4939: "time's arrow",
              7698: "rubber spider",
              4811: "Holiday Fun!"}.get(item, "item #{}".format(item))))
コード例 #2
0
ファイル: clanapps.py プロジェクト: KevZho/redditbot
	def get(self):
		s = Session()
		login(s)
		g = GetPendingApplicationsRequest(s)
		pending = g.doRequest()
		for userId in pending["players"]:
			logging.debug("adding %s" % userId)
			if userId not in Data.clanBlacklist:
				a = AddPlayerToClanRequest(s, userId)
				logging.debug("adding %s is a %s" % (userId, a.doRequest()))
				msg = SendMessageRequest(s, {'userId': userId, 'text': "You have been accepted into Reddit United.\n\nPlease read clan rules in the clan forums, under the subforum \"Clan Rules.\" We're telling you this because as a Normal Member (your current rank), you have 0 (ZERO) privileges (Yes, NO stash, NO dungeon), and the only way to be promoted is reading the rules C-A-R-E-F-U-L-L-Y! If you don't read them, we'll know. Oh, yes we'll know, all right.\n\nMake sure to join us in clan chat as well! Type in \"/listen clan\" (or) \"/chat clan\" into the chat box.\n\nPlease do not reply to this message. This is an automated response."})
				msg.doRequest()
			else:
				logging.debug("player %s is on blacklist" % userId)
コード例 #3
0
ファイル: web.py プロジェクト: KevZho/buffbot
	def post(self):
		s = Session()
		try:
			c1 = cookielib.Cookie(None, "PHPSESSID", memcache.get("PHPSESSID"), None, False, memcache.get("domain0"), True, False, memcache.get("path0"), True, False, None, False, None, False, None, False)
			jar = cookielib.CookieJar()
			jar.set_cookie(c1)
			c2 = cookielib.Cookie(None, "appserver", memcache.get("appserver"), None, False, memcache.get("domain1"), True, False, memcache.get("path1"), True, False, None, False, None, False, None, False)
			jar.set_cookie(c2)
			s.cj = jar

			s.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(s.cj))
			s.isConnected = memcache.get("isConnected")
			s.userId = memcache.get("userId")
			s.userName = memcache.get("userName")
			s.userPasswordHash = memcache.get("userPasswordHash")
			s.serverURL = memcache.get("serverURL")
			s.pwd = memcache.get("pwd")
			s.rollover = memcache.get("rollover")
		except:
			logging.error("some memcache keys were deleted, logging in manually and setting memcache keys")
			s.login(Data.USERNAME, Data.PASSWORD)

			memcache.add(key="isConnected", value=bool(s.isConnected))
			memcache.add(key="userId", value=int(s.userId))
			memcache.add(key="userName", value=str(s.userName))
			memcache.add(key="userPasswordHash", value=str(s.userPasswordHash))
			memcache.add(key="serverURL", value=str(s.serverURL))
			memcache.add(key="pwd", value=str(s.pwd))
			memcache.add(key="rollover", value=int(s.rollover))

			i = 0
			for cookie in s.cj:
				logging.info("%s=%s" % (cookie.name, cookie.value))
				memcache.add(key=cookie.name,value=str(cookie.value))
				memcache.add(key="domain%d" % i, value=str(cookie.domain))
				memcache.add(key="path%d" % i, value=str(cookie.path))
				i += 1

		# START DOING CRAP
		username = self.request.get("username")
		search = SearchPlayerRequest(s, username)
		uid = None
		try:
			uid = search.doRequest()['players'][0]["userId"]
		except:
			logging.error("dc'ed from server")
			s.login(Data.USERNAME, Data.PASSWORD)

			memcache.add(key="isConnected", value=bool(s.isConnected))
			memcache.add(key="userId", value=int(s.userId))
			memcache.add(key="userName", value=str(s.userName))
			memcache.add(key="userPasswordHash", value=str(s.userPasswordHash))
			memcache.add(key="serverURL", value=str(s.serverURL))
			memcache.add(key="pwd", value=str(s.pwd))
			memcache.add(key="rollover", value=int(s.rollover))

			i = 0
			for cookie in s.cj:
				logging.info("%s=%s" % (cookie.name, cookie.value))
				memcache.add(key=cookie.name,value=str(cookie.value))
				memcache.add(key="domain%d" % i, value=str(cookie.domain))
				memcache.add(key="path%d" % i, value=str(cookie.path))
				i += 1

			uid = search.doRequest()['players'][0]["userId"]

		logging.info("Player: {0}, Buffs: {1}".format(username, self.request.get("buffs")))
		splitBuffs = self.request.get("buffs").split("\n")

		msg = {
			"userId": s.userId,
			"text": ""
		}
		for buff in splitBuffs:
			msg["text"] += "%s %s %s\n" % (Data.secretKey, uid, buff)

		send = SendMessageRequest(s, msg)
		send.doRequest()

		self.response.out.write("Buff request received. Your buffs will arrive shortly. Redirecting to web buff page in 5 seconds.")
		self.response.out.write('''<script type="text/javascript">setTimeout("window.location='/web/'", 5000)</script>''')
コード例 #4
0
ファイル: main.py プロジェクト: KevZho/buffbot
def doStuff():
	logging.debug("doStuff()")
	s = Session()
	try:
		c1 = cookielib.Cookie(None, "PHPSESSID", memcache.get("PHPSESSID"), None, False, memcache.get("domain0"), True, False, memcache.get("path0"), True, False, None, False, None, False, None, False)
		jar = cookielib.CookieJar()
		jar.set_cookie(c1)
		c2 = cookielib.Cookie(None, "appserver", memcache.get("appserver"), None, False, memcache.get("domain1"), True, False, memcache.get("path1"), True, False, None, False, None, False, None, False)
		jar.set_cookie(c2)
		s.cj = jar

		s.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(s.cj))
		s.isConnected = memcache.get("isConnected")
		s.userId = memcache.get("userId")
		s.userName = memcache.get("userName")
		s.userPasswordHash = memcache.get("userPasswordHash")
		s.serverURL = memcache.get("serverURL")
		s.pwd = memcache.get("pwd")
		s.rollover = memcache.get("rollover")
	except:
		logging.error("some memcache keys were deleted")

	m = None
	messages = None

	try:
		m = GetMessagesRequest(s)
		messages = m.doRequest()
	except:
		logging.warn("Not logged in, logging in")
		memcache.flush_all()
		s = Session()
		s.login(Data.USERNAME, Data.PASSWORD)

		memcache.add(key="isConnected", value=bool(s.isConnected))
		memcache.add(key="userId", value=int(s.userId))
		memcache.add(key="userName", value=str(s.userName))
		memcache.add(key="userPasswordHash", value=str(s.userPasswordHash))
		memcache.add(key="serverURL", value=str(s.serverURL))
		memcache.add(key="pwd", value=str(s.pwd))
		memcache.add(key="rollover", value=int(s.rollover))

		i = 0
		for cookie in s.cj:
			logging.info("%s=%s" % (cookie.name, cookie.value))
			memcache.add(key=cookie.name,value=str(cookie.value))
			memcache.add(key="domain%d" % i, value=str(cookie.domain))
			memcache.add(key="path%d" % i, value=str(cookie.path))
			i += 1

		m = GetMessagesRequest(s)
		messages = m.doRequest()

	for kmail in messages["kmails"]:
		logging.info("%s sent kmail with text %s" % (kmail["userName"], kmail["text"]))

		msg = kmail["text"].split("\n")
		totalMP = 0
		totalCost = 0
		buffsCast = []

		for randomBuff in msg:
			specialCase = False
			specialUID = None
			info = randomBuff.split(" ")
			buff = ""
			duration = 0

			if not info[0].isdigit():
				if info[0] == Data.secretKey:
					specialCase = True
					specialUID = int(info[1])
				else:
					logging.info("No duration set")
					buff = " ".join(info)
					logging.info("Need to interpret %s" % buff)
					duration = 50
			else:
				logging.info("Duration set for %d" % int(info[0]))
				buff = " ".join(info)[len(info[0]) + 1:]
				logging.info("Need to interpret %s" % buff)

				duration = int(info[0]) if int(info[0]) < Data.MAXLENGTH else Data.MAXLENGTH

			if specialCase:
				if len(info) >= 3:
					if not info[2].isdigit():
						logging.info("No duration set")
						buff = " ".join(info)[len(info[0]) + len(info[1]) + 2:]
						logging.info("Need to interpret %s" % buff)
						duration = 50
					else:
						logging.info("Duration set for %d" % int(info[2]))
						buff = " ".join(info)[len(info[0]) + len(info[1]) + len(info[2]) + 3:]
						logging.info("Need to interpret %s" % buff)

						duration = int(info[2]) if int(info[2]) < Data.MAXLENGTH else Data.MAXLENGTH

			theBuff = None
			for key in Data.buffs.keys():
				if buff.lower() in key.lower():
					theBuff = Data.buffs[key]
					logging.info("keyword '{0}' matched for {1}".format(buff, key))

			if theBuff is not None and buff != "":
				shouldBuff = True
				c = CharpaneRequest(s)
				charData = c.doRequest()

				currentMP = charData["currentMP"]
				timesNeeded = int(math.ceil(float(duration)/float(Data.ACCORDION_DURATION)))

				logging.info("Current: MP: {0}, meat: {1}".format(currentMP, charData["meat"]))
				logging.info("Current MP: {0}, Need: {1}".format(currentMP, (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded))

				if "once" not in theBuff:
					while currentMP < (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded < charData["maxMP"]:
						if currentMP > (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded:
							logging.error("Should not be here!")
							break
						if charData["meat"] > 94:
							logging.warn("Out of MP. Buying mystery juice")
							store = StoreRequest(s, 2, 518)
							try:
								store.doRequest()
							except:
								logging.error("dc'ed from server")
								s = Session()
								memcache.flush_all()
								s.login(Data.USERNAME, Data.PASSWORD)
								store.doRequest()
								memcache.add(key="isConnected", value=bool(s.isConnected))
								memcache.add(key="userId", value=int(s.userId))
								memcache.add(key="userName", value=str(s.userName))
								memcache.add(key="userPasswordHash", value=str(s.userPasswordHash))
								memcache.add(key="serverURL", value=str(s.serverURL))
								memcache.add(key="pwd", value=str(s.pwd))
								memcache.add(key="rollover", value=int(s.rollover))
								i = 0
								for cookie in s.cj:
									logging.info("%s=%s" % (cookie.name, cookie.value))
									memcache.add(key=cookie.name,value=str(cookie.value))
									memcache.add(key="domain%d" % i, value=str(cookie.domain))
									memcache.add(key="path%d" % i, value=str(cookie.path))
									i += 1

							u = UseItemRequest(s, 518)
							u.doRequest()
							totalCost += 95
							currentMP = c.doRequest()["currentMP"]
						else:
							logging.error("No meat or MP, stopping")
							shouldBuff = False
							break
				else:
					while currentMP < (theBuff["mp"] - Data.MPCOSTREDUCTION) < charData["maxMP"]:
						if currentMP > (theBuff["mp"] - Data.MPCOSTREDUCTION):
							logging.error("Should not be here!")
							break
						if charData["meat"] > 94:
							logging.warn("Out of MP. Buying mystery juice")
							store = StoreRequest(s, 2, 518)
							try:
								store.doRequest()
							except:
								logging.error("dc'ed from server")
								s = Session()
								memcache.flush_all()
								s.login(Data.USERNAME, Data.PASSWORD)
								store.doRequest()
								memcache.add(key="isConnected", value=bool(s.isConnected))
								memcache.add(key="userId", value=int(s.userId))
								memcache.add(key="userName", value=str(s.userName))
								memcache.add(key="userPasswordHash", value=str(s.userPasswordHash))
								memcache.add(key="serverURL", value=str(s.serverURL))
								memcache.add(key="pwd", value=str(s.pwd))
								memcache.add(key="rollover", value=int(s.rollover))
								i = 0
								for cookie in s.cj:
									logging.info("%s=%s" % (cookie.name, cookie.value))
									memcache.add(key=cookie.name,value=str(cookie.value))
									memcache.add(key="domain%d" % i, value=str(cookie.domain))
									memcache.add(key="path%d" % i, value=str(cookie.path))
									i += 1

							u = UseItemRequest(s, 518)
							u.doRequest()
							totalCost += 95
							currentMP = c.doRequest()["currentMP"]
						else:
							logging.error("No meat or MP, stopping")
							shouldBuff = False
							break

				if shouldBuff and theBuff["available"] and (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded < charData["maxMP"]:
					if not specialCase:
						skill = UseSkillRequest(s, theBuff["id"], 1, kmail["userId"]) if "once" in theBuff else UseSkillRequest(s, theBuff["id"], timesNeeded, kmail["userId"])

						logging.info("Buffing %s with %s" % (kmail["userName"], getSkillFromId(theBuff["id"])["name"]))

						try:
							skill.doRequest()
							totalMP += (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded
							buffsCast.append(theBuff["id"])
						except:
							logging.fatal("Casting error for KMail request.")
					else:
						skill = UseSkillRequest(s, theBuff["id"], 1, specialUID) if "once" in theBuff else UseSkillRequest(s, theBuff["id"], timesNeeded, specialUID)

						logging.info("Buffing %s with %s" % (specialUID, getSkillFromId(theBuff["id"])["name"]))

						try:
							skill.doRequest()
							totalMP += (theBuff["mp"] - Data.MPCOSTREDUCTION) * timesNeeded
							buffsCast.append(theBuff["id"])
						except:
							logging.fatal("Casting error for web interface request.")
			else:
				logging.warn("No buff found matching %s" % buff)

		msg = None
		if not specialCase:
			msg = {
				"userId": kmail["userId"],
				"text": "Thanks for using BuffBot!\nTotal MP used: {0}\nTotal meat spent on magical mystery juice: {1}".format(totalMP, totalCost)
			}
		else:
			msg = {
				"userId": specialUID,
				"text": "Thanks for using BuffBot!\nTotal MP used: {0}\nTotal meat spent on magical mystery juice: {1}".format(totalMP, totalCost)
			}

		for someBuff in buffsCast:
			msg["text"] += "\nGave buff: %s" % getSkillFromId(someBuff)["name"]

		if len(buffsCast) > 0:
			send = SendMessageRequest(s, msg)
			send.doRequest()
			logging.info("KMail sent")
		else:
			if not specialCase:
				msg = {
					"userId": kmail["userId"],
					"text": "Thanks for using BuffBot!\nEither one of two things happened:\n1. BuffBot ran out of meat and MP, so it couldn't complete your request. Please send some meat next time for some magical mystery juice if this is the case.\n2. BuffBot did not know how to interpret your input. If this is the case, please refer to http://rubuffbot.appspot.com/faq/ for information on how to use BuffBot."
				}
			else:
				msg = {
					"userId": specialUID,
					"text": "Thanks for using BuffBot!\nEither one of two things happened:\n1. BuffBot ran out of meat and MP, so it couldn't complete your request. Please send some meat next time for some magical mystery juice if this is the case.\n2. BuffBot did not know how to interpret your input. If this is the case, please refer to http://rubuffbot.appspot.com/faq/ for information on how to use BuffBot."
				}
			send = SendMessageRequest(s, msg)
			send.doRequest()

		d = DeleteMessagesRequest(s, [kmail["id"]])
		d.doRequest()
		logging.info("KMail deleted")

		c = CharpaneRequest(s)
		charData = c.doRequest()
		logging.info("Final MP and Meat: {0}, {1}".format(charData["currentMP"], charData["meat"]))
コード例 #5
0
ファイル: main.py プロジェクト: KevZho/redditbot
def process(s, c, counter):
	chats = None
	try:
		chats = c.getNewChatMessages()
	except:
		chats = c.getNewChatMessages()
	for chat in chats:
		# handle PMs
		if chat["type"] == "private" and chat['userId'] not in Data.playerBlacklist:
			incrementCounter(chat, counter)
			u = UserProfileRequest(s, chat["userId"])
			# allow use in RU only
			if u.doRequest()["clanName"] == "Reddit United":
				if re.match(Data.wang, chat['text']):
					player = db.GqlQuery("SELECT * FROM Player WHERE userName='******'" % chat['userName'].lower()).get()
					if player is None:
						player = Player(userName=chat['userName'].lower(), gotPackage=False, wangsUsed=0, arrowUsed=False)
					if player.wangsUsed < Data.WANG_LIMIT:
						logging.debug("hitting %s with a wang" % chat['userName'])
						wang = CursePlayerRequest(s, chat["userId"], 625)
						try:
							wang.doRequest()
							player.wangsUsed += 1
							player.put()
							c.sendChatMessage("/msg %s You have been slapped with a wang." % chat["userId"])
						except:
							c.sendChatMessage("/msg %s An error occurred. Please try again later." % chat["userId"])
					else:
						logging.warn("%s has hit limit for wang" % chat['userName'])
						c.sendChatMessage("/msg %s You have used all 5 wangs for the day." % chat['userId'])
				elif re.match(Data.rigRoll, chat['text']):
					if chat['userId'] == 2434890:
						if re.match(Data.rigRoll, chat['text']).group(5) != "k" and re.match(Data.rigRoll, chat['text']).group(5) != "m":
							logging.debug("Rolling normally RIGGED")
							c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % (str(re.match(Data.rigRoll, chat['text']).group(1)), chat["userName"], re.match(Data.rigRoll, chat['text']).group(8)))
						elif re.match(Data.rigRoll, chat['text']).group(5) == "k" or re.match(Data.rigRoll, chat['text']).group(5) == "K":
							logging.debug("Rolling x1000 RIGGED")
							c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % ((str(re.match(Data.rigRoll, chat['text']).group(1)) + str(re.match(Data.rigRoll, chat['text']).group(5))), chat["userName"], re.match(Data.rigRoll, chat['text']).group(8)))
						elif re.match(Data.rigRoll, chat['text']).group(5) == "m" or re.match(Data.rigRoll, chat['text']).group(5) == "M":
							logging.debug("Rolling x1m RIGGED")
							c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % ((str(re.match(Data.rigRoll, chat['text']).group(1)) + str(re.match(Data.rigRoll, chat['text']).group(5))), chat["userName"],  re.match(Data.rigRoll, chat['text']).group(8)))
				elif re.match(Data.diceRoll, chat['text']):
					logging.debug(re.match(Data.diceRoll, chat['text']).group(5))
					# TODO: take out this part after raffles.
					if chat['userId'] in [2413861, 1481327] and re.match(Data.diceRoll, chat['text']).group(1) == 10:
						if db.GqlQuery("SELECT * FROM Player WHERE userName='******'").get().baleeted is False:
							c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % (str(re.match(Data.diceRoll, chat['text']).group(1)), chat["userName"], 4))
							player = db.GqlQuery("SELECT * FROM Player WHERE userName='******'").get()
							player.baleeted = True
							player.put()
						else:
							c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % (str(re.match(Data.diceRoll, chat['text']).group(1)), chat["userName"], random.randint(1, int(re.match(Data.diceRoll, chat['text']).group(1)))))
					# roll! group 2 = #, group 5 = k or m, group 7 = channel
					elif re.match(Data.diceRoll, chat['text']).group(5) != "k" and re.match(Data.diceRoll, chat['text']).group(5) != "m":
						logging.debug("Rolling normally")
						c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % (str(re.match(Data.diceRoll, chat['text']).group(1)), chat["userName"], random.randint(1, int(re.match(Data.diceRoll, chat['text']).group(1)))))
					elif re.match(Data.diceRoll, chat['text']).group(5) == "k" or re.match(Data.diceRoll, chat['text']).group(5) == "K":
						logging.debug("Rolling x1000")
						c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % ((str(re.match(Data.diceRoll, chat['text']).group(1)) + str(re.match(Data.diceRoll, chat['text']).group(5))), chat["userName"], random.randint(1, int(re.match(Data.diceRoll, chat['text']).group(1)) * 1000)))
					elif re.match(Data.diceRoll, chat['text']).group(5) == "m" or re.match(Data.diceRoll, chat['text']).group(5) == "M":
						logging.debug("Rolling x1m")
						c.sendChatMessage("/clan Rolling 1D%s for %s gives %s" % ((str(re.match(Data.diceRoll, chat['text']).group(1)) + str(re.match(Data.diceRoll, chat['text']).group(5))), chat["userName"], random.randint(1, int(re.match(Data.diceRoll, chat['text']).group(1)) * 1000000)))
				elif re.match(Data.wangOther, chat['text']):
					logging.debug("slapping %s with a wang. request by %s" % (re.match(Data.wangOther, chat['text']).group(2), chat['userName']))
					player = db.GqlQuery("SELECT * FROM Player WHERE userName='******'" % chat['userName'].lower()).get()
					if player is None:
						player = Player(userName=chat['userName'].lower(), gotPackage=False, wangsUsed=0, arrowUsed=False)
					if player.wangsUsed < Data.WANG_LIMIT:
						wang = CursePlayerRequest(s, re.match(Data.wangOther, chat['text']).group(2), 625)
						try:
							wang.doRequest()
							player.wangsUsed += 1
							player.put()
							c.sendChatMessage("/msg %s %s has been slapped with a wang." % (chat["userId"], re.match(Data.wangOther, chat['text']).group(2)))
						except:
							c.sendChatMessage("/msg %s An error occurred. Please try again later." % chat["userId"])
					else:
						logging.warn("%s has hit limit for wang" % chat['userName'])
						c.sendChatMessage("/msg %s You have used all 5 wangs for the day." % chat['userId'])
				# elif re.match(Data.loveMe, chat['text']):
				# 	logging.debug("sending love back at %s" % chat['userName'])
				# 	c.sendChatMessage("/msg %s Awww... I love you back!" % chat["userId"])
				elif re.match(Data.arrow, chat['text']):
					if chat['userId'] not in [1589628]:
						logging.debug("hitting %s with a time's arrow" % chat['userId'])
						player = db.GqlQuery("SELECT * FROM Player WHERE userName = '******'" % chat['userName'].lower()).get()
						if player is None:
							player = Player(userName=chat['userName'].lower(), gotPackage=False, wangsUsed=0, arrowsUsed=False)
						if not player.arrowsUsed:
							arrow = CursePlayerRequest(s, chat["userId"], 4939)
							try:
								arrow.doRequest()
								player.arrowsUsed = True
								player.put()
								c.sendChatMessage("/msg %s Hitting you with a time's arrow, straight to the knee." % chat["userId"])
							except:
								logging.error("Out of arrows/error!")
								c.sendChatMessage("/msg %s Oops, looks like I'm out of arrows :'( (Or you're in Ronin/HC, or you've been hit already by someone else)" % chat["userId"])
						else:
							logging.warn("%s hit limit for time's arrow" % chat['userName'])
							c.sendChatMessage("/msg %s You have used your arrow for the day." % chat['userId'])
					else:
						logging.warn("%s is blacklisted from arrows" % chat['userName'])
						c.sendChatMessage("/msg %s You have been blacklisted from using time's arrows." % chat['userId'])
				elif re.match(Data.arrowOther, chat['text']):
					if chat['userId'] not in [1589628]:
						player = db.GqlQuery("SELECT * FROM Player WHERE userName = '******'" % chat['userName'].lower()).get()
						if player is None:
							player = Player(userName=chat['userName'].lower(), gotPackage=False, wangsUsed=0, arrowsUsed=False)
						if not player.arrowsUsed:
							logging.debug("hitting %s with a time's arrow. request by %s" % (re.match(Data.arrowOther, chat['text']).group(2), chat['userName']))
							arrow = CursePlayerRequest(s, re.match(Data.arrowOther, chat['text']).group(2), 4939)
							try:
								arrow.doRequest()
								player.arrowsUsed = True
								player.put()
								c.sendChatMessage("/msg %s %s has been hit with an arrow." % (chat["userId"], re.match(Data.arrowOther, chat['text']).group(2)))
							except:
								c.sendChatMessage("/msg %s An error occurred. Please try again later." % chat["userId"])
						else:
							logging.warn("%s hit limit for time's arrow" % chat['userName'])
							c.sendChatMessage("/msg %s You have used your arrow for the day." % chat['userId'])
					else:
						logging.warn("%s is blacklisted from arrows" % chat['userName'])
						c.sendChatMessage("/msg %s You have been blacklisted from using time's arrows." % chat['userId'])
				elif re.match(Data.upgradeStatus, chat['text']):
					c.sendChatMessage("/msg %s Rank upgrades have been moved to RedditRankBot. Please PM him instead." % chat['userId'])
					# # TODO: rewrite to use FindWhitelistRequest in order to not accidentally demote a player
					# e = EditPlayerRankRequest(s, chat['userId'], 6)
					# if e.doRequest()["success"]:
					# 	logging.debug("Promoted %s to a Lurker" % chat['userName'])
					# 	AddClannieToClanWhitelistRequest(s, chat['userId']).doRequest()
					# 	c.sendChatMessage("/msg %s You have been promoted to Lurker." % chat["userId"])
					# 	c.sendChatMessage("/clan %s (#%s) has been promoted to a Lurker." % (chat["userName"], chat["userId"]))
					# else:
					# 	c.sendChatMessage("/msg %s Sorry, I've failed to automatically promote you. Please see a mod." % chat['userId'])
				elif re.match(Data.sendCarePackage, chat['text']):
					if chat['userId'] in Data.karmanautPlus:
						logging.info("Attempting to send care package to %s request by %s" % (re.match(Data.sendCarePackage, chat['text']).group(1), chat['userName']))
						newbieName = re.match(Data.sendCarePackage, chat['text']).group(1)
						if newbieName.isdigit():
							newbieName = UserProfileRequest(s, re.match(Data.sendCarePackage, chat['text']).group(1)).doRequest()["userName"]
						playerSearch = db.GqlQuery("SELECT * FROM Player WHERE userName = '******'" % newbieName.lower()).get()
						msgBody = {
							"userId": re.match(Data.sendCarePackage, chat['text']).group(1),
							"text": "Welcome to KoL and Reddit United! Here's some stuff to help you out.\n\nThis newbie package was requested by %s for you" % chat["userName"],
							"items": [{"id": 143, "quantity": 1}, {"id": 591,	"quantity": 1},	{"id": 1450, "quantity": 1}, {"id": 196, "quantity": 3}, {"id": 2402, "quantity": 10}, {"id": 7071, "quantity": 10}, {"id": 7072, "quantity": 10}],	"meat": 1000
						}
						if playerSearch is None:
							# send a package, update the datastore
							c.sendChatMessage("/w %s Sending a care package..." % chat["userId"])
							try:
								SendMessageRequest(s, msgBody).doRequest()
								Player(userName=newbieName.lower(), gotPackage=True, wangsUsed=0, arrowsUsed=False).put()
								c.sendChatMessage("/w %s %s has been sent a care package." % (chat['userId'], newbieName))
							except:
								c.sendChatMessage("/w %s Failed to send. Username may be too long and KoL chat made a space between it. Please send one manually. (This is a general fail message, this could also mean one ingredient of the package is missing)" % chat['userName'])
						else:
							if playerSearch.gotPackage is False:
								c.sendChatMessage("/w %s Sending a care package..." % chat["userId"])
								try:
									SendMessageRequest(s, msgBody).doRequest()
									playerSearch.gotPackage = True
									playerSearch.put()
									c.sendChatMessage("/w %s %s has been sent a care package." % (chat['userId'], newbieName))
									logging.info("%s has been sent a care package" % newbieName)
								except:
									c.sendChatMessage("/w %s Failed to send. Username may be too long and KoL chat made a space between it. Please send one manually" % chat['userName'])
									logging.error("Failed to send package to %s" % newbieName)
							else:
								logging.warn("Failed to send package to %s, player has been sent one already" % newbieName)
								c.sendChatMessage("/w %s %s has already been sent a care package" % (chat['userId'], newbieName))
					else:
						logging.warn("Unauthorized attempt to send care package by %s" % chat["userName"])
						c.sendChatMessage("/w %s You are not authorized to send care packages. This incident will be reported." % chat['userId'])
				else:
					# No matching command was found, inform the player
					incrementCounter(chat, counter)
					c.sendChatMessage("/msg %s Oops, I didn't recognize what you wanted. Try again, or type !help in clan chat to receive a list of commands to use." % chat["userId"])
			else:
				# If FaxBot, then acknowledge the fax completion.
				if chat["userId"] == 2194132:
					if " has copied a" in chat['text']:
						logging.debug("A %s has been copied in." % re.match(Data.parseFax, chat['text']).group(1))
						c.sendChatMessage("Your fax request has been completed. A %s has been copied in." % re.match(Data.parseFax, chat['text']).group(1))
					elif "I do not understand your request." in chat['text'] or "just delivered a fax to your clan" in chat['text']:
						c.sendChatMessage("/clan There was a problem in faxing. Please try again.")
				else:
					# handle of other players
					c.sendChatMessage("/msg %s Sorry, you must be in the clan \"Reddit United\" to use this bot." % chat['userId'])
		else:
			if "channel" in chat and chat["channel"] == "clan" and chat["userId"] not in Data.playerBlacklist:
				if re.match(Data.fax, chat['text']):
					incrementCounter(chat, counter)
					c.sendChatMessage("/clan Faxing a %s..." % re.match(Data.fax, chat['text']).group(1))
					logging.debug("faxing a %s. requested by %s" % (re.match(Data.fax, chat['text']).group(1), chat['userName']))
					c.sendChatMessage("/w FaxBot %s" % re.match(Data.fax, chat['text']).group(1))
				# elif re.match(Data.clanMemberBack, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	logging.debug("w/b to %s" % chat['userName'])
				# 	c.sendChatMessage("/clan Welcome back, %s!" % chat["userName"])
				# elif re.match(Data.clanMemberHi, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	logging.debug("hello to %s" % chat['userName'])
				# 	c.sendChatMessage("/clan Hello, %s!" % chat["userName"])
				# elif re.match(Data.clanMemberLeave, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	logging.debug("goodbye to %s" % chat['userName'])
				# 	c.sendChatMessage("/clan Goodbye, %s!" % chat["userName"])
				elif re.match(Data.snack, chat['text']):
					incrementCounter(chat, counter)
					logging.debug("munching on a snack from %s" % chat['userName'])
					c.sendChatMessage("/clan /me munches on the snack happily")
				elif re.match(Data.smack, chat['text']):
					incrementCounter(chat, counter)
					logging.debug("smacked by %s" % chat['userName'])
					c.sendChatMessage("/clan /me smacks %s back twice as hard" % chat['userName'])
				elif re.match(Data.ignoreMe, chat['text']):
					logging.debug("ignoring %s by own request" % chat['userName'])
					c.sendChatMessage("/clan You have been ignored by RedditBot. Note that this has permanently locked you out of all of RedditBot's features.")
					c.sendChatMessage("/baleet %s" % chat['userId'])
					player = db.GqlQuery("SELECT * FROM Player WHERE userName='******'" % chat['userName']).get()
					if player is None:
						Player(userName=chat['userName'].lower(), gotPackage=False, baleeted=True, wangsUsed=0, arrowsUsed=False).put()
					else:
						player.baleeted = True
						player.put()
				elif re.match(Data.executeCommand, chat['text']):
					# perm type: SU only
					if chat['userId'] in Data.superUser:
						logging.info("execute %s" % re.match(Data.executeCommand, chat['text']).group(1))
						c.sendChatMessage(re.match(Data.executeCommand, chat['text']).group(1))
					else:
						logging.warn("unauthorized executeCommand by %s" % chat['userName'])
						c.sendChatMessage("/clan You are not authorized to use that command.")
				elif re.match(Data.setRank, chat['text']):
					# perm type: mod+
					if chat['userId'] in Data.modPlus:
						logging.info("setting rank for %s to %s" % (re.match(Data.setRank, chat['text']).group(1), re.match(Data.setRank, chat['text']).group(2)))
						resp = {}
						if re.match(Data.setRank, chat['text']).group(2).isdigit():
							resp = EditPlayerRankRequest(s, re.match(Data.setRank, chat['text']).group(1), re.match(Data.setRank, chat['text']).group(2)).doRequest()
						else:
							resp = EditPlayerRankRequest(s, re.match(Data.setRank, chat['text']).group(1), EditPlayerRankRequest.ranks[re.match(Data.setRank, chat['text']).group(2).lower()]).doRequest()
						if resp['success']:
							c.sendChatMessage("/clan Rank has been set.")
						else:
							c.sendChatMessage("/clan Failed to set rank.")
					else:
						logging.warn("unauthorized setRank by %s" % chat['userName'])
						c.sendChatMessage("/clan You are not authorized to use that command.")
				elif re.match(Data.optimal, chat['text']):
					incrementCounter(chat, counter)
					logging.debug("acknowledge optimal by %s" % chat['userName'])
					if chat['userName'].lower() not in ["kevzho", "basbryan", "sweeepss", "hikaru yami"]:
						c.sendChatMessage("/clan No, %s, you are not optimal enough for Kev" % chat['userName'])
					else:
						c.sendChatMessage("/clan Yes, %s, you are optimal." % chat["userName"])
				# elif re.match(Data.sharknado, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	c.sendChatMessage("/clan Sharknado was a horrible movie. Just... no.")
				elif re.match(Data.helpMe, chat['text']):
					incrementCounter(chat, counter)
					msg = SendMessageRequest(s, {"userId": chat["userId"], "text": Data.helpText})
					msg.doRequest()
				# elif re.match(Data.kill, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	if re.match(Data.kill, chat['text']).group(1).lower() not in ["kevzho", "redditbot", "jick"]:
				# 		c.sendChatMessage("/clan Commencing the killing of %s" % re.match(Data.kill, chat['text']).group(1))
				# 	else:
				# 		c.sendChatMessage("/clan I cannot kill that player.")
				# elif re.match(Data.iq, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	if chat['username'].lower() != "kevzho":
				# 		c.sendChatMessage("/clan My IQ is higher than yours, %s" % chat['userName'])
				# 	else:
				# 		c.sendChatMessage("/clan How can I be smarter than my creator? Don't be silly, %s" % chat["userName"])
				elif re.match(Data.setFlag, chat['text']):
					# perm type: SU only
					if chat['userId'] in Data.superUser:
						c.sendChatMessage("/clan Setting '%s' flag for %s to %s" % (re.match(Data.setFlag, chat['text']).group(1), re.match(Data.setFlag, chat['text']).group(2), re.match(Data.setFlag, chat['text']).group(3)))
						logging.info("Setting '%s' flag for %s to %s" % (re.match(Data.setFlag, chat['text']).group(1), re.match(Data.setFlag, chat['text']).group(2), re.match(Data.setFlag, chat['text']).group(3)))
						playerFlag = db.GqlQuery("SELECT * FROM Player WHERE userName='******'" % re.match(Data.setFlag, chat['text']).group(1)).get()
						if re.match(Data.setFlag, chat['text']).group(3) in ["False", "True"]:
							if re.match(Data.setFlag, chat['text']).group(3) == "False":
								setattr(playerFlag, re.match(Data.setFlag, chat['text']).group(2), False)
								playerFlag.put()
								c.sendChatMessage("/clan Flag set.")
							else:
								setattr(playerFlag, re.match(Data.setFlag, chat['text']).group(2), True)
								playerFlag.put()
								c.sendChatMessage("/clan Flag set.")
						elif re.match(Data.setFlag, chat['text']).group(3).isdigit():
							setattr(playerFlag, re.match(Data.setFlag, chat['text']).group(2), int(re.match(Data.setFlag, chat['text']).group(3)))
							playerFlag.put()
							c.sendChatMessage("/clan Flag set.")
						else:
							setattr(playerFlag, re.match(Data.setFlag, chat['text']).group(2), re.match(Data.setFlag, chat['text']).group(3))
							playerFlag.put()
							c.sendChatMessage("/clan Flag set.")
					else:
						c.sendChatMessage("/clan Unauthorized attempt to setFlag")
						logging.warn("%s attempted to setFlag" % chat["userName"])
				elif re.match(Data.getFlag, chat['text']):
					# perm type: SU only/admin?
					if chat['userId'] in Data.adminPlus:
						logging.info("Getting %s flag of %s" % (re.match(Data.getFlag, chat['text']).group(1), re.match(Data.getFlag, chat['text']).group(2)))
						playerGql = db.GqlQuery("SELECT * FROM Player WHERE userName='******'" % re.match(Data.getFlag, chat['text']).group(1)).get()
						if playerGql:
							c.sendChatMessage("/clan Flag %s for %s gives: %s" % (re.match(Data.getFlag, chat['text']).group(2), re.match(Data.getFlag, chat['text']).group(1), getattr(playerGql, re.match(Data.getFlag, chat['text']).group(2))))
						else:
							c.sendChatMessage("/clan Player not found!")
					else:
						c.sendChatMessage("/clan Unauthorized attempt to getFlag")
						logging.warn("%s attempted to getFlag" % chat["userName"])
				elif re.match(Data.whitelist, chat['text']):
					if chat['userId'] in Data.karmanautPlus:
						logging.info("adding %s to whitelist requested by %s" % (re.match(Data.whitelist, chat['text']).group(1), chat['userName']))
						AddClannieToClanWhitelistRequest(s, re.match(Data.whitelist, chat['text']).group(1)).doRequest()
						c.sendChatMessage("/clan Player added to whitelist.")
					else:
						c.sendChatMessage("/clan Unauthorized attempt to whitelist.")
						logging.warn("%s attempted to whitelist" % chat['userName'])
				elif re.match(Data.points, chat['text']):
					# logging.info("Clan points by %s" % chat['userName'])
					# c.sendChatMessage("/clan %s has %s clan points" % (re.match(Data.points, chat['text']).group(1), random.randint(0, 9000)))
					c.sendChatMessage("/clan Clan points are currently unavailable.")
				# elif re.match(Data.trigger, chat['text']):
				# 	incrementCounter(chat, counter)
				# 	c.sendChatMessage("/clan Do you really expect that to be a trigger?")
				elif re.match("^!version", chat['text']):
					incrementCounter(chat, counter)
					c.sendChatMessage("Version %s" % Data.version)
				elif re.match("^!([^ ]+)(.*)?$", chat['text']):
					incrementCounter(chat, counter)
					if re.match("^!([^ ]+)(.*)?$", chat['text']).group(1).lower() in Data.customTriggers:
						c.sendChatMessage(Data.customTriggers[re.match("^!([^ ]+)(.*)?$", chat['text']).group(1).lower()])
					else:
						c.sendChatMessage("/clan %s" % random.choice(Data.noTriggers).format(chat['userName'], re.match("^!([^ ]+)(.*)?$", chat['text']).group(1), ordinal(random.randint(1, 100))))
				if len(chat['text']) < (200 - len(chat['userName']) - 2):
					c.sendChatMessage("/talkie %s: %s" % (chat['userName'], chat["text"]))
				else:
					# break it up here, stopped the bug for now by just not sending messages if they are longer than 200 chars. a more long term solution would require changes to the pykol api itself.
					pass
			if "channel" in chat and chat["channel"] == "talkie" and chat["userId"] not in Data.playerBlacklist:
				c.sendChatMessage("/clan %s: %s" % (chat['userName'], chat["text"]))