示例#1
0
def ask(request):
	text = ""
	p = request.text.split(' ')
	###
	if p[0].lower() == "gd":
		if p[2].lower() == "json":
			text = "Try again later"
	if p[0].lower() == "time":
		text = '<time format="Teraz jest %A, %d %B %Y roku, godzina %H:%M:%S"/>'
	if p[0].lower() == "echo":
		text = " ".join(p[1:])
	###
	if text == "":
		return response(text="", quality=0, image="/static/imgs/modules/consolebot.png")
	else:
		return response(text=text, quality=1, image="/static/imgs/modules/consolebot.png")
示例#2
0
def ask(request):
	if ("play" in request.text and "num" in request.text) or ("gra" in request.text and "licz" in request.text):
		cache.set(str(request.user.id) + "guessnumber", { "Number": random.randint(1,100), "Tryies": 0 }, 3600)
		return response(image="/static/imgs/modules/guessnumber.png", text="Pomyślałem liczbę od 1 do 100. Zgaduj, a jeżeli ci się znudzi wpisz 'exit'.", quality=1)
	elif "exit" in request.text:
		cache.delete(str(request.user.id) + "guessnumber")
		return response(image="/static/imgs/modules/guessnumber.png", text="Game ended", quality=1)
	elif str(request.user.id) + "guessnumber" in cache:
		data = cache.get(str(request.user.id) + "guessnumber")
		cont = True
		try:
			data["Tryies"] += 1
			if data["Number"] < int(request.text):
				return response(image="/static/imgs/modules/guessnumber.png", quality=1, text=request.text + ": Moja liczba jest mniejsza")
			if data["Number"] > int(request.text):
				return response(image="/static/imgs/modules/guessnumber.png", quality=1, text=request.text + ": Moja liczba jest większa")
			if data["Number"] == int(request.text):
				t = data["Tryies"]
				cont = False
				return response(image="/static/imgs/modules/guessnumber.png", quality=1, text=request.text + ": Wygrałeś. To ta liczba. Ilość prób: " + str(t))
		finally:
			if cont:
				cache.set(str(request.user.id) + "guessnumber", data, 3600)
			else:
				cache.delete(str(request.user.id) + "guessnumber")
	else:
		return response(image="/static/imgs/modules/guessnumber.png", quality=0.01, text="Ej.. Zagrajmy w zgadywanie liczb wpisz 'zagrajmy w zgadywanie liczb'.")
示例#3
0
def ask(request):
    txt = request.text.lower()
    if "hangman" in txt:
        import manfred.data.models

        category = manfred.data.models.HangManCategory.objects.filter(language="1").order_by("?")[0]
        word = manfred.data.models.HangManWord.objects.filter(category=category).order_by("?")[0].word.decode("utf-8")
        category = category.name.decode("utf-8")

        rq = {"Word": word, "Know": "_" * (len(word) - 1), "Level": 0}
        cache.set(str(request.user.id) + "_hangman", rq, 3600)
        return response(
            text='Wylosowa³em s³owo z kategorii "'
            + category.encode("ISO-8859-2")
            + '". Zgaduj. Napisz "exit" aby zakoñczyæ grê<br/>'
            + rq["Know"].encode("ISO-8859-2"),
            quality=1,
        )
    elif "exit" in txt:
        # Stop
        cache.delete(str(request.user.id) + "_hangman")
        return response(text="Gra zakoñczona", quality=1)
    elif str(request.user.id) + "_hangman" in cache:
        rq = cache.get(str(request.user.id) + "_hangman")

        if len(txt) == 1 and txt in rq["Word"]:
            # Show letter
            new = ""
            for i in len(rq["Know"]):
                if rq["Know"][i] != "_":
                    new += rq["Word"][i]
                elif rq["Know"][i] == "_" and rq["Word"][i] == txt:
                    new += rq["Word"][i]
                else:
                    new += "_"
            rq["Know"] = new
        elif txt == rq["Word"]:
            # Show word
            rq["Know"] = txt
        else:
            # Fail
            rq["Level"] += 1

        if rq["Know"] == rq["Word"]:
            cache.delete(str(request.user.id) + "_hangman")
            return response(text="Wygra³e¶. To ten wyraz. Gra zakoñczona", quality=1)
        elif rq["Level"] > 3:
            cache.delete(str(request.user.id) + "_hangman")
            return response(text='Przegra³e¶. Ten wyraz to "' + rq["Word"] + '". Gra zakoñczona', quality=1)
        else:
            cache.set(str(request.user.id) + "_hangman", rq, 3600)
            return response(text="Grasz dalej<br>" + rq["Know"], quality=1)
    else:
        return response(text='Zagrajmy w wisielca. Wpisz "hangman" aby rozpocz±æ', quality=0.01)