Ejemplo n.º 1
0
def get(moose, username, challenge_name):
	name = ""
	if challenge_name[0] == '#':
		try:
			challenge_number = int(challenge_name[1:])
		except ValueError:
			moose.send_message("%s is not a valid challenge id" % challenge_name)
			return
		if moose.redis_server.hlen("challs") <= challenge_number or challenge_number < 0:
			moose.send_message("%s is not a valid challenge id" % challenge_name)
			return
		else:
			name = [(i, s) for i, s in enumerate(moose.redis_server.hkeys("challs"))][challenge_number][1]
	else:
		if not moose.redis_server.hexists("challs", challenge_name):
			moose.send_message("%s is not a valid challenge name" % challenge_name)
			return
		else:
			name = challenge_name
	try:
		gist = create_gist(moose, name, loads(moose.redis_server.hget("challs", name)))
		moose.send_message("%s" % gist)
		update_seen(moose, username, name)
	except GistException:
		moose.send_message("Unable to create gist")
Ejemplo n.º 2
0
def add(moose, username, args):
	if len(args) < 2:
		moose.cmd("help", "add")
		return
	challenge_name, description = args[0], args[1:]
	new_info = InfoMessage(username, datetime.now().strftime("%m-%d-%Y %H:%M:%S"), " ".join(description))
	if moose.redis_server.hget("challs", challenge_name) == None:
		moose.redis_server.hset("challs", challenge_name, dumps([new_info]))
	else:
		old = loads(moose.redis_server.hget("challs", challenge_name))
		old.append(new_info)
		moose.redis_server.hset("challs", challenge_name, dumps(old))
	moose.send_message("Added!")
	update_seen(moose, username, challenge_name)